For day to day operations tasks, sometimes Linux geeks have to boot Linux server in single user mode for recovering the root password, repairing file system errors, fixing incorrect entry of fstab and disabling or enabling systemctl services.
Single user mode is the maintenance or emergency mode where Linux geeks perform all troubleshooting steps. In Single user mode all the system services are stopped and only root user is allowed to execute commands. In this article we will demonstrate on how to boot CentOS 8 / RHEL 8 server into a single user mode and perform troubleshooting steps.
There are two ways to boot CentOS 8 and RHEL 8 server in Single User Mode
Method 1) Using “rd.break” keyword
Step:1) Reboot Your CentOS 8 or RHEL 8 Server and go to grub boot loader screen by interrupting auto boot and choose first line which includes the kernel (In case you have multiple kernel lines choose the appropriate one which suits to your environment). Below is the CentOS 8 boot loader screen,
Step:2) Press ‘e’ to enter in the edit mode and then go to the end of line which starts with ‘linux‘ word, type the keyword “rd.break”
now press Ctrl-x to boot system in single user mode then we will get below screen,
Step:3) Remount the /sysroot in read-write (rw) mode
Run the following commands to mount sysroot file system in rw,
switch_root:/# mount -o remount,rw /sysroot switch_root:/# chroot /sysroot sh-4.4#
As we can see above that we got ‘sh’ shell prompt, now root user can execute the commands.
Let’s assume we want to recover root password by resetting it, so execute following commands one after the another
sh-4.4# echo “[email protected]@123#” | passwd --stdin root sh-4.4# touch /.autorelabel
Once you are done with password reset, run below command to reboot your system
sh-4.4# reboot -f
Method 2) Replacing the ‘ro’ word with “rw init=/sysroot/bin/sh”
Step 1) Reboot your CentOS 8 / RHEL 8 System and interrupt the auto boot by entering up and down arrow key then we will get following grub screen.
Choose the first line which includes the kernel,
Step 2) Press ‘e’ to enter in edit mode and look for the line which starts with ‘linux’ word, replace the “ro” with “rw init=/sysroot/bin/sh”
press “Ctrl-x” to boot the system in single user mode,
Step 3) Mount the root file system using chroot command,
:/# chroot /sysroot
Let’s assume you want to correct some invalid entries in fstab file,
:/# vi /etc/fstab
Make the required changes in fstab file then save and exit
In case you want to disable some systemctl service like sendmail, run the following command,
:/# systemctl disable sendmail
Once you are done with changes and troubleshooting steps then reboot your system using following command,
:/# reboot -f
Note: Alternate way to reboot the system from single user mode is to run exit command twice.
That’s all from this tutorial, In case these steps help you to recover your system and root password then please don’t hesitate to share valuable feedback and comments.