- How to PROPERLY boot into single user mode in RHEL/CentOS 7/8
- 1. Boot into single user mode or rescue mode (rescue.target)
- 1.1 Boot into maintenance mode using ISO
- 1.2 Change runlevel to rescue.target from a valid shell
- 1.3 Boot into single user mode using GRUB2
- 2. Boot into emergency mode (emergency.target)
- 2.1 Change runlevel to emergency.target with a valid shell
- 2.2 Boot into emergency mode using GRUB2
- 3 thoughts on “How to PROPERLY boot into single user mode in RHEL/CentOS 7/8”
- Как загрузить CentOS 7 в single mode?
- How to Boot into Single User Mode in CentOS/RHEL 7
- How to Boot into Single User Mode
- CentOS / RHEL 6 : How to Boot into single user mode
- Steps
How to PROPERLY boot into single user mode in RHEL/CentOS 7/8
How to boot in single user mode in linux. Boot into rescue mode or emergency mode in Red Hat 7/8 Linux. Difference between rescue.target and emergency.target in Linux. How to boot into the emergency target with and without ISO CD-ROM. How to boot into maintenance mode in Linux.
Single user mode term was used with CentOS/RHEL 6 and earlier but now with CentOS/RHEL 7 and 8 we have rescue and emergency mode. Now in this article I will share the steps to boot into maintenance mode using systemd.unit
1. Boot into single user mode or rescue mode (rescue.target)
- Rescue mode provides a convenient single-user environment and allows you to repair your system in situations when it is unable to complete a regular booting process.
- In rescue mode, the system attempts to mount all local file systems and start some important system services
- Although it does not activate network interfaces or allow more users to be logged into the system at the same time.
- In Red Hat/CentOS 7/8, this operation requires the root password.
1.1 Boot into maintenance mode using ISO
1.2 Change runlevel to rescue.target from a valid shell
If you already have a valid shell then you can change runlevel and boot into rescue mode using systemctl from the command line.
# systemctl isolate rescue.target
Here,
isolate means start the unit specified on the command line and its dependencies and stop all others
or alternatively you can also use
Next check the graphical console of your CentOS/RHEL 7/8 Linux host, it will prompt for root user password. Once you provide the root user password you will get a working shell.
1.3 Boot into single user mode using GRUB2
Now assuming you don’t have a valid shell then you can boot into single user mode or rescue mode then you can use GRUB2. Boot your CentOS/RHEL 7/8 host till the GRUB2 menu appears.
On the GRUB2 menu press any button to halt the boot up. Next select the kernel using which you wish to boot into single user mode or rescue mode and press «e» to edit the GRUB2 menu.
In CentOS/Red Hat 7 look out for the line starting with linux16 as shown below
linux16 /vmlinuz-3.10.0-693.el7.x86_64 root=/dev/mapper/system-root ro rd.lvm.lv=system/root rd.lvm.lv=system/swap rhgb quiet
In CentOS/Red Hat 8 look out for the line starting with linux
linux ($root)/vmlinuz-4.18.0-80.el8.x86_64 root=/dev/mapper/system-root ro crashkernel=auto resume=/dev/mapper/system-swap rd.lvm.lv=system/root rd.lvm.lv=system/swap rhgb quiet
Based on your environment append systemd.unit=rescue.target , at the end of line starting with linux or linux16, for example below is a snippet from CentOS/Red Hat 8 node, Press Ctrl+x to continue with the booting with the new changes:
Next you will get the same prompt to put root user’s password:
2. Boot into emergency mode (emergency.target)
- Emergency mode provides the most minimal environment possible and allows you to repair your system even in situations when the system is unable to enter rescue mode.
- In emergency mode, the system mounts the root file system only for reading, does not attempt to mount any other local file systems, does not activate network interfaces, and only starts a few essential services.
2.1 Change runlevel to emergency.target with a valid shell
If you already have a valid shell and you wish to change runlevel to emergency mode then you can use systemctl :
# systemctl isolate emergency.target
Next check the console of your Linux host and provide the root user password to complete the runlevel change.
2.2 Boot into emergency mode using GRUB2
Similar to the steps explained under boot into single user mode , for Red Hat/CentOS 7 you will have a line starting with linux16 and for CentOS/Red Hat 8 you will have a line starting with linux in the GRUB2 menu respectively.
So based on your environment append systemd.unit=emergency.target at the end of linux or linux16 line. For example below screenshot is from CentOS/Red Hat 8 Linux node to boot into emergency mode
Press ctrl+x to continue with the booting and at the end the screen will again prompt for root user password as I had shown earlier. provide the root user password to get a shell where you can further troubleshoot your environment.
Lastly I hope the steps from the article to boot into single user mode or maintenance mode (rescue mode and emergency mode) in RHEL/CentOS 7/8 Linux was helpful. So, let me know your suggestions and feedback using the comment section.
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
3 thoughts on “How to PROPERLY boot into single user mode in RHEL/CentOS 7/8”
hello,
there is any possibility to switch off providing password during switching into rescue mode ?
cheers,
Piotr Reply
Not in any of the “rescue modes” provided by systemd.
But yes, you possible still may avoid it completely: put ‘init=/sysroot/bin/sh’ w/o quotes instead of “systemd…blah-blah”.
Your system will be booted without pivot-root, so chroot /sysroot before anything else.
And do ‘touch /.autorelabel’ if you change anything, or you will not be able to login again (no selinux in this mode) You may also try ‘rd.break=cleanup’ instead – usually the only way to recover systems with thin-lvm or other complex dm config. Again, your system will be in /sysroot, chroot manually Reply
Как загрузить CentOS 7 в single mode?
Иногда, для целей отладки или решения возникающих при загрузке проблем необходимо загрузить операционную систему в Single Mode — в однопользовательском режиме. Поскольку с выходом CenOS 7 загрузчик сменился с grub на grub2, изменился и способ загрузки в single mode. Вот как это можно сделать в CentOS 7.
При появлении меню загрузчика, нажмите «e» на том ядре, которое будем грузить. Откроется редактор конфигурации grub2. Нажмите стрелку вниз и найдите строку имеющуую вид:
linux16 /vmlinuz-3.10.0-229.14.1.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm=centos/swap vconsole.font=.
Понятно, что номер ядра и прочие параметры могут быть другими для файловой системы. Нас интересует выделенное красным. Надо заменить значение «ro» на «rw init=/sysroot/bin/bash» после чего нажмите Ctrl+x для загрузки отредактированной кофнигурации. Загрузка должна закончится выводом приглашения root’а:
Далее нужно учитывать, что файловая система загружаемой системы будет находится в /sysroot и если вам нужно просто войти туда и посмотреть, что к чему, вы можете использовать команду
Либо, если вам необходимо что-либо исправить, перед выполнением chroot, перемонтрируйте файловую систему в режим для записи (по умолчанию она монтируется в режим «только для чтения»)
How to Boot into Single User Mode in CentOS/RHEL 7
Single User Mode (sometimes known as Maintenance Mode) is a mode in Unix-like operating systems such as Linux operate, where a handful of services are started at system boot for basic functionality to enable a single superuser perform certain critical tasks.
It is runlevel 1 under system SysV init, and runlevel1.target or rescue.target in systemd. Importantly, the services, if any, started at this runlevel/target varies by distribution. It’s generally useful for maintenance or emergency repairs (since it doesn’t offer any network services at all), when a computer is not capable of normal operations.
Some of the low-level repairs include running such as fsck of damaged disk partitions, reset root password if you have lost it, fix “failed to mount /etc/fstab” error – just to mention the most critical of them. And also when the system fails to boot normally.
In this tutorial, we will describe how to boot into single user mode on CentOS 7. Note that practically this will help you enter the emergency mode and access an emergency shell.
How to Boot into Single User Mode
1. First restart your CentOS 7 machine, once boot process starts, wait for the GRUB boot menu to appear as shown in the screen shot below.
2. Next, select your Kernel version from the grub menu item and press e key to edit the first boot option. Now use the Down arrow key to find the kernel line (starts with “linux16“), then change the argument ro to rw init=/sysroot/bin/sh as shown in the screen shot below.
3. Once you have finished the task in the previous step, press Ctrl-X or F10 to boot into single user mode (access an emergency shell).
4. Now mount root (/) filesystem using the following command.
At this point, you can perform all the necessary low-level system maintenance tasks. Once you are done, reboot the system using this command.
You may also liked to read following articles.
Lastly, the single user mode or maintenance mode is not password-protected by default, so any one with malicious intend and physical access to your computer can enter the emergency mode and “destroy” your system.
Next, we will show you how to password-protect single user mode on CentOS 7. Until then, stay connected to Tecmint.com.
CentOS / RHEL 6 : How to Boot into single user mode
Booting into single user mode using GRUB is accomplished by editing the kernel line. single user mode can be accessed by appending an “S“, “s“, or “single” to the kernel command line in GRUB. This assumes that either the GRUB boot menu is not password protected or that you have access to the password if it is.
Steps
1. When the system boots up, you will see the GRUB countdown, which is set to 5 seconds by default.
2. Press “Esc” to intercept this countdown and go enter a GRUB menu as show below :
3. Select/highlight the desired kernel using the up/down arrow keys. Press ‘e’ to start editing the desired kernel. In my case, I have only one kernel.
4. Scroll down to the “kernel…” line. This line tells GRUB which kernel to boot. Press ‘e’ again to edit this line. Move to the end of the line (instead, you can also press a to directly go to the end of the kernel line). You can add number “1” or word “single” to the end (to signify single user mode).
5. Once you have finished the change, press Enter to accept the editing. Then press ‘b’ to boot using that kernel and boot into runlevel 1 (single user mode). This will boot the system into single-user mode, i.e. the boot process will stop immediately after execution of rc.sysinit and present a root BASH shell.