As you might already know, Runlevels are replaced with Systemd targets in many recent Linux distributions like RHEL 7 / RHEL 8 and Ubuntu 16.04 LTS and newer versions. For more details about runlevels and systemd target, refer this guide. In this brief tutorial, we are going to see how to boot into rescue mode or emergency mode in Ubuntu 20.04 and Ubuntu 18.04 LTS editions. This guide is specifically written for Ubuntu, however the steps given below should work on most Linux distributions that uses Systemd as default service manager. Before getting into the topic, let me clarify what is rescue mode and emergency mode and what is the purpose of the both modes.
What is Rescue mode?
The rescue mode is equivalent to single user mode in Linux distributions that uses SysV as the default service manager. In rescue mode, all local filesystems will be mounted, only some important services will be started. However, no normal services (E.g network services) won't be started. The rescue mode is helpful in situations where the system can't boot normally. Also, we can perform some important rescue operations, such as reset root password, in rescue mode.
What is Emergency mode?
In contrast to the rescue mode, nothing is started in the emergency mode. No services are started, no mount points are mounted, no sockets are established, nothing. All you will have is just a raw shell. Emergency mode is suitable for debugging purposes.
First, we will see how to boot into rescue mode and emergency mode in Ubuntu 20.04 LTS distributions.
Boot Into Rescue Mode In Ubuntu 20.04 LTS
We can boot into rescue mode in two ways.
Method 1:
Power on your Ubuntu system. Hit ESC key right after the BIOS logo disappears to display Grub menu.
In the GRUB menu, choose the first entry and press "e" to edit it.
Hit DOWN arrow and find the line that starts with the word "linux" and add the following line at the end of it. To reach the end, just press CTRL+e or use END key or LEFT/RIGHT arrows in your keyboard.
systemd.unit=rescue.target
After adding the above line, hit Ctrl+x or F10 to boot into rescue mode.
After a few seconds, you will be landed in the rescue mode (single user mode) as root user. You will be prompted to press ENTER to enter the maintenance mode.
Here is how rescue mode looks like in Ubuntu 20.04 LTS server:
Now do whatever you want to do in the rescue mode. You may need to mount the root (/) file system in read/write mode before doing any operations in rescue mode.
mount -n -o remount,rw /
Once done, press "Ctrl+d" to boot into normal mode. Alternatively, you can type any one of the following commands to boot into normal mode.
systemctl default
Or,
exit
If you want to reboot the system instead of booting into normal mode, enter:
systemctl reboot
Method 2:
In this method, you don't need to edit grub boot menu entries.
Power on the system and choose "Advanced options for Ubuntu" from Grub boot menu.
Next, you will see the list of available Ubuntu versions with Kernel versions. Choose the "Recovery mode" in grub boot menu in Ubuntu.
After a few seconds, you will see the Ubuntu recovery menu. From the recovery menu, choose "Drop to root shell prompt" option and hit ENTER key.
Now you will be landed in the rescue mode.
Mount the root (/) file system in read/write mode by entering the following command:
mount -n -o remount,rw /
Do whatever you want to do in the rescue mode.
Once done, type exit to return back to the recovery menu.
exit
Finally, choose "Resume normal boot" option and hit ENTER.
If you don't want to boot into normal mode, type "reboot" from the maintenance mode to restart your system.
Boot Into Emergency Mode In Ubuntu 20.04 LTS
When the GRUB boot menu appears, press "e" to edit it.
Find the line that starts with the word "linux" and add the following line at the end of it.
systemd.unit=emergency.target
After adding the above line, hit Ctrl+x or F10 to boot into emergency mode.
After a few seconds, you will be landed in the emergency mode as root user. You will be prompted to press ENTER to enter the maintenance mode.
Here is how emergency mode looks like in Ubuntu 20.04 LTS server:
Now do whatever you want to do in the emergency mode. You may need to mount the root (/) file system in read/write mode before doing any operations in this mode.
mount -n -o remount,rw /
Once done, press "Ctrl+d" to boot into normal mode. Alternatively, you can type any one of the following commands to boot into normal mode.
systemctl default
Or,
exit
If you want to reboot the system instead of booting into normal mode, enter:
systemctl reboot
Related read:
Boot Into Rescue Mode In Ubuntu 18.04 LTS
Boot your Ubuntu system. When Grub menu appears, choose the first entry and press e to edit. (To reach the end, just press CTRL+e or use END key or LEFT/RIGHT arrows in your keyboard):
If you don't see the Grub menu, just hit ESC key right after the BIOS logo disappears.
Find the line that starts with word "linux" and add the following line at the end of that line (To reach the end, just press CTRL+e or use END key or LEFT/RIGHT arrows in your keyboard):
systemd.unit=rescue.target
Once you added the above line, just press CTRL+x or F10 to continue to boot into rescue mode. After a few seconds, you will be landed in the rescue mode (single user mode) as root user.
Here is how rescue mode looks like in Ubuntu 18.04 LTS server:
Next, type the following command to mount root (/) file system into read/write mode.
mount -n -o remount,rw /
Boot Into Emergency Mode
Booting your Ubuntu into emergency is as same as above method. All you have to do is replace "systemd.unit=rescue.target" with "systemd.unit=emergency.target" when editing grub menu.
Once you added "systemd.unit=emergency.target", press Ctrl+x or F10 to continue booting into emergency mode.
Finally, you can mount root filesystem into read/write mode with command:
mount -n -o remount,rw /
Switch between Rescue to Emergency mode and vice versa
If you are in rescue mode, you don't have to edit the grub boot entry as I mentioned above. Instead, just type the following command to switch to emergency mode instantly:
systemctl emergency
Similarly, to switch from emergency to rescue mode, type:
systemctl rescue
You know now what is rescue and emergency modes and how to boot into those modes in Ubuntu 20.04 and Ubuntu 18.04 LTS systems. Like I already mentioned, the steps provided here will work on many recent Linux versions that uses Systemd.
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!