GRUB Recovery Modes in Linux: Resetting a Password and Repairing the System

Sunucun 5 min read

GRUB (GRand Unified Bootloader) is the boot loader that loads the operating system on most Linux systems. When a system won’t boot, a password has been forgotten or an update has left the machine in a bad state, GRUB’s recovery options let you repair it without reinstalling. In this article we explain how to open the GRUB menu, use Ubuntu recovery mode, reset a password and fix the grub rescue> prompt step by step.

Illustration: Linux

How to Open the GRUB Menu

On single-OS installations the GRUB menu is often hidden and the system boots straight through. According to the Ubuntu documentation, to show the menu:

  • On BIOS systems: Hold down Shift while the computer starts, before the Ubuntu logo appears.
  • On UEFI systems: Press Esc (several times if needed) while the firmware loads. Fast boot can leave very little time, so try again if it doesn’t work the first time.

You can’t reach the GRUB menu over SSH on a server, because it appears before the operating system and the SSH service start. If you use a VPS server, restart it from the VNC/console screen in your provider’s control panel and open the menu there.

Recovery Environments in GRUB

“GRUB recovery mode” usually refers to one of three different environments:

EnvironmentHow to open itWhat it is for
Recovery modeThe “(recovery mode)” entry under “Advanced options” in the menuBoots the system with minimal services; offers a root shell, file system check, package repair and more
GRUB command line (grub>)Press c in the menu; Esc returns to the menuRuns GRUB commands such as listing disks or loading a kernel manually
Rescue shell (grub rescue>)Opens by itself when GRUB fails to load its normal moduleLets you locate GRUB’s files with very limited commands and switch to the normal menu

Booting Ubuntu Recovery Mode

  1. Restart the computer or server and open the GRUB menu.
  2. Select Advanced options for Ubuntu.
  3. Select the kernel entry ending in (recovery mode) and press Enter.
  4. Choose the option you need in the recovery menu. It includes options such as checking the file system (fsck), repairing broken packages (dpkg), updating GRUB and dropping to a root shell.

In the root shell the root partition is mounted read-only. Make it writable first; if you also need other partitions such as /home or /boot, mount them all afterwards:

mount -o remount,rw /
mount --all

Resetting a Linux Password via GRUB

If you have forgotten your user password, you can set a new one from the root shell in recovery mode:

mount -o remount,rw /
passwd username
sync
reboot

Replace username with your own user name; if you don’t remember it, ls /home shows it. passwd asks for the new password twice. After the reboot you can log in with the new password.

Distributions without a recovery mode entry use a different method. On RHEL, AlmaLinux and Rocky Linux, for example, the root password is reset from a special environment opened by editing the boot entry; in that case follow the steps in your distribution’s official documentation.

Temporarily Editing a Boot Entry

Press e while an entry is highlighted in the GRUB menu to edit its commands. For example, if a faulty graphics driver stops the system from booting, you can add a kernel parameter to the end of the line that starts with linux. According to the GRUB manual, press Ctrl+X to boot the edited entry, or Esc to discard the changes and return to the menu.

These edits are not permanent; they apply only to that boot. For a permanent change on Ubuntu/Debian, edit /etc/default/grub and run sudo update-grub.

How to Fix the “grub rescue>” Prompt

If you only see a grub rescue> prompt, GRUB has failed to load the normal module it needs to show the menu. This usually happens after the disk or partition layout changes, the /boot partition is moved or another operating system is installed. For a temporary fix, first check the current settings and disks:

set
ls
ls (hd0,gpt2)/

The ls command lists disks and partitions. Once you find the partition that contains the /boot/grub folder ((hd0,gpt2) in the example below), point GRUB to it and switch to normal mode:

set prefix=(hd0,gpt2)/boot/grub
set root=(hd0,gpt2)
insmod normal
normal

Once the system has booted, reinstall GRUB and update its configuration so the problem doesn’t come back (Ubuntu/Debian example; change the disk name to match your system):

sudo grub-install /dev/sda
sudo update-grub

The GRUB manual notes that on BIOS systems installing GRUB to the whole disk is more robust than installing it to a partition, and that you shouldn’t assume the first disk in the operating system is the one the firmware boots from.

A Note on Security

The steps above also show that anyone with physical or console access can reset a password. To limit this, you can add password protection to GRUB (in a password-protected menu you press p and enter the password before editing an entry) and encrypt the disks. On servers, protect the control panel account that gives console access with a strong password and two-factor authentication.

Conclusion

GRUB’s recovery mode, command line and grub rescue> shell let you repair a system that won’t boot, reset a forgotten password and fix boot problems without reinstalling. Before any repair, make sure you have an up-to-date backup of your important data.

Categories

Latest guides