For Linux system admins, booting RHEL 7 / CentOS 7 servers in single user mode is the most common day to day activities. Single user mode is considered as maintenance or emergency mode where we can perform our troubleshooting steps. Following are the scenarios where we need to boot our RHEL / CentOS Servers in Single user mode:
- Reset Root password – There can be some scenarios where someone from the team has reset the root password and he/she didn’t share it with team and left the organization
- Repairing file system – There are some situations where OS(operating system) file systems got corrupted and while rebooting server didn’t come up, so in that case we have to repair file system by entering into single user mode.
- Fix Wrong entry of fstab file – Let’s suppose I have created one file system on RHEL / CentOS Server and update the /etc/fstab file, but there was some typo while updating the file system entries. I got the request to reboot the server, so while booting up it got stuck while mounting that file system. So to resolve and fix such issue, we need to boot Linux servers in Single User mode.
- Disabling / enabling Service – There can some service which is taking lot of time or delaying the boot. So in that case we can disable that service from single user mode. On the contrary we can also enable specific service from single user mode.
There are two methods through which we can boot CentOS 7 / RHEL 7 servers in Single User Mode.
Step1: Reboot your Server and go to Grub boot loader menu and choose the appropriate kernel, example is shown below:
Step 2: Press ‘e’ and go to the end of line which starts with ‘linux16’ word.
Type “rd.break” at end of line which begins with linux16 and then press “ctrl+x”
In the next window we will get single user mode or emergency mode, something like below:
Step 3: Now remount the /sysroot in ‘rw’ mode
switch_root:/# mount -o remount,rw /sysroot switch_root:/# chroot /sysroot
Let’s assume we want to reset root password. Run the beneath commands
sh-4.2# echo “New-root-password” | passwd --stdin root sh-4.2# touch /.autorelabel
Now you can edit the files and scan corrupted file system with fsck command. Once you are done with troubleshooting Type ‘exit‘ command two times or ‘reboot -f‘ to reboot your server.
Step 1: Reboot the server and go to the grub menu and select the appropriate kernel
Step 2: Press ‘e’ and go the line with starts with ‘linux16’
Replace “ro” with “rw init=/sysroot/bin/sh”
Once done with the changes press ‘Ctrl+x’
Step 3: Mount the root file system with chroot command
:/# chroot /sysroot
Let’s assume I want to disable network manager service and rest root password, run the following commands:
:/# systemctl disable NetworkManager :/# echo “Enter-New-Root-password” | passwd --stdin root :/# touch /.autorelabel
Once you are done with the changes, type “reboot -f” command to reboot your server
Note: In production environment, Single user mode is also password protected. By default root password is the single user mode password on CentOS 7 / RHEL 7 Servers.
That’s all from this tutorial. In case these steps help to resolve any technical issue then please do share your comments in the comments section below.