How to Boot Ubuntu Into Recovery Mode?


While using Ubuntu, you might have encountered temporary failures in routine operations. It could be for several reasons, i.e., a corrupted file system, networking/internet not working, or overloaded disk space. In such a case, Ubuntu offers a recovery mode to boot into the system. The recovery mode allows you to reconfigure the filesystem and networking, clean up the disk space, update the grub, etc. The recovery mode offers various common fixes on screen, and you can just select the one you are looking for.

This post addresses the possible ways to boot your Ubuntu into a recovery mode.

How to Boot Ubuntu Into Recovery Mode?

Ubuntu offers two ways to boot into a recovery mode, i.e., one from the grub menu at the startup and the other using the commands inside Ubuntu. It depends on the scenario to choose the method. For instance, if the system does not boot and you are unable to get into it then choose Method 1. However, if you need to launch the recovery mode for routine maintenance then use Method 2 (you can also use Method 1 as well). Let’s discuss both:

Boot Ubuntu Into Recovery Mode Using GRUB Menu

Let’s say you are unable to boot. In such a case, you can invoke the GRUB menu at the startup and boot into recovery mode. Let’s see how it works:

Reboot your system and press the Shift or Esc key to boot into the GRUB menu and select “Advanced options for Ubuntu”:

Choose the Kernel through which you want to boot into the Recovery mode (select the one that you are currently using):

Here’s the Recovery Mode:

You have multiple troubleshooting options. Let’s discuss all these one by one:

  • clean: Cleans up the disk space.
  • dpkg: Fixes the broken packages.
  • fsck: Checks/analyzes the file systems.
  • grub: Updates the GRUB (sudo update-grub)
  • network: Enable the networking service(s).
  • root: Enter the root shell (also referred to as the Gateway to the Rescue/Emergency Mode).
  • system-summary: Provides the details of the system.

Which Option to Choose?

If you know the reason why you are in recovery mode? Choose the option as per your requirements. If you do not know what to fix or what has invoked the problem, then do all these operations one by one, i.e., clean, dpkg, fsck grub, network, or the root login. The root login permits you to access the system as a root user and perform the key operations (cleaning disk space, checking file system, configuring network, etc) manually.

Once all is done, you need to select the “resume” option to get into the system.

Important: When you boot/resume in normal mode (through the GRUB menu), some GUI operations might not function properly. Reboot your Ubuntu again to fix all these.

Boot Ubuntu Into Recovery Mode Using the GRUB Configuration File

The operations (clean, dpkg, fsck, grub) in the recovery mode need not be used only when the system malfunctions. All these refer to the routine maintenance of your Ubuntu as well. In such a case, you can invoke the recovery mode from the Ubuntu terminal as well (without rebooting). Let’s see how:

Step 1: Edit the GRUB Configuration

The purpose is to boot into recovery from the Ubuntu’s GRUB. For this, we have to make changes to the GRUB configuration file. Let’s open it in any editor:

$ sudo nano /etc/default/grub

Upon opening, here you will find the “GRUB_DEFAULT” which is used to boot Ubuntu in a normal mode.

You need to change “GRUB_DEFAULT” to Boot into recovery mode. To do so, you must know the index values of the Boot Menu/Sub Menu, i.e., 1st value has the index “0” and so on.

  • Inside the GRUB menu, the “Advanced options for Ubuntu” is placed in 2nd position (index value is 1).
  • In the Advanced options, you will see the bootable kernels (normal and recovery). Get the index number of the recovery Kernel that you want to boot with.

As per the details, you need to set the “GRUB_DEFAULT” value based on two parameters, i.e., 1st to select the “Advanced options” (Menu) and the other for the “Recovery Kernel” (Sub Menu). The “GRUB_DEFAULT” accepts the directive values in the following format:

GRUB_DEFAULT=“x>y”

Where x and y represent the index values of the menu and sub-menu. Let’s use index 1 for both and make changes in the “/etc/default/grub”:

What if you do not know the index of the GRUB entries?

You can use the “grep” command to filter the content of the “/boot/grub/grub.cfg” and check the index numbers. Open the terminal and run the below command:

grep -E "submenu|menuentry" /boot/grub/grub.cfg | grep -B 1 -E "recovery|submenu"
  • grep -E “submenu|menuentry” /boot/grub/grub.cfg: Searches the submenu and menuentry fields in the grub.cfg file. Here, the submenu represents “Advanced options for Ubuntu” menu.
  • grep -E “recovery|submenu”: Filters the results of the first part that contains the recovery keyword in the menu/submenu. The “-B 1” fetches one line before each match (to get the index number correctly).

Here’s the output:

Step 2: Update the GRUB

Use the below command to update the GRUB so that it acknowledges the newly made changes:

sudo update-grub

Step 3: Reboot the System

Reboot the system. On the next boot, you will directly fall into the “Recovery Mode”:

You can choose and perform any debugging/troubleshooting task.

Important: Once your issue is resolved, make sure to revert the value of “DEFAULT_GRUB” to “0” in the “/etc/default/grub”.

Bonus Tip: How to Boot Ubuntu Into a Rescue/Emergency Mode?

Other than Ubuntu/Debian derivatives, the rescue or the emergency modes are considered the recovery modes. Although these functionalities are available in Ubuntu but are used rarely because of the presence of the Recovery mode.
We will demonstrate here how you can boot Ubuntu into a rescue or emergency mode.

Through GRUB Configuration

GRUB configurations can be changed to boot into the rescue or the emergency mode. Let’s understand how it works:

Step 1: Enter the GRUB Menu

At the startup time, press the Shift (or the Esc) key to get into the GRUB menu. Then, press the “e” key to edit the GRUB boot commands:

Step 2: Add the systemd unit

Here, we have to direct our systemd to use the rescue or the emergency mode during the boot. To do so, trace the line starting with the keyword “linux” and add the “systemd.unit=rescue.target”.

Note: To boot into the emergency mode, you need to set “systemd.unit=emergency.target” in the same line.

Lastly, use the F10 or CTRL+X to save changes and boot into the respective mode:

Now, you are in the rescue mode. Enter the root password:

Step 3: Remount the Root File System

Remount the root filesystem:

mount -n -o remount, rw /

Note: The rescue mode activates the primary services but not the network interfaces. However, the emergency mode allows you to fix the system issues when you are unable to access the rescue mode.

Through Recovery Mode

The rescue or the emergency mode can be invoked while you are in recovery mode. Let’s see how:

Step 1: Log in as a Root

First, you have to boot into the Recovery Mode that we described earlier. You will see the “root” option, select it and provide the root password to log in as a root:

Step 2: Remount the Root File System

Initially, when you start the root shell, Ubuntu’s root filesystem is accessible only with read-only permissions. We are about to perform some operations which have an impact on the filesystem. Thus, use the below command to remount the filesystem with read/write permissions:

mount -n -o remount, rw /

Now, you are in rescue mode and can use various Linux Commands to fix the encountered issues. To come out of the rescue mode, use the “exit” keyword.

Bottom Line

Recovery refers to getting your system out of the temporary failure. Mostly, recovery mode is triggered at the boot time. For this, you have to access the GRUB menu (using the SHIFT/ESC key) and select the recovery Kernel. However, if you try to run the recovery mode for routine maintenance, you can change the “DEFAULT_GRUB” in the “/etc/default/grub”.

Apart from recovery, users can use the “rescure” or “emergency” mode as well to fix temporary errors. This post has addressed the possible ways to boot Ubuntu into a recovery mode.

Print Friendly, PDF & Email
Categories