Software >> OS >> Unix >> Linux >> RHEL >> All >> Recovery >> How to troubleshoot and recover root password or unbootable system

 

 RHEL 6

Method 1 - using bootable installation media (DVD or ISO)

## For physical servers, insert the bootable installation DVD, for VMs, select the bootable installation ISO as optical drive
## in our case, we are using the RHEL 6.2 installation boot DVD




Once booted from the optical drive, select Rescue Installed system




Select the keyboard and click OK




Select Local CD/DVD and then click OK




Select network option accordingly, in our case, we did not require netowrk, so selected No




Select Continue




Click OK




Take note the system being recovered is not mounted under /mnt/sysimage, click OK




Select shell  Start shell



## run df command to see the filesystem mounted under /mnt/sysimage


## run the following to change system root to /mnt/sysimage

bash-4.1# chroot /mnt/sysimage


## perform the recovery accordingly e.g. to change root password

bash-4.1# passwd root


Method 2 - boot current system into single user mode


## If we don't have bootable installation media, try to boot to single user mode



At this screen, press any key to enter Grub menu




Press a to append to the kernel arguments for this menu entry




Add a space and then single selinux=0 to the end of the line, then press Enter to accept the changes




The system will boot into single user mode and shell prompt presented without need to login.

## proceed to perform the recovery or troubleshooting




 

 RHEL 7

Method 1 - using bootable installation media (DVD or ISO)


## For physical servers, insert the bootable installation DVD, for VMs, select the bootable installation ISO as optical drive




Once booted from optical drive, select Troubleshooting



Select Rescue a Red Hat Enterprise Linux system



Select Continue




## The system's root filesystem is not mounted as /mnt/sysimage and you will be presented with the following prompt

sh-4.2#



## make that the root environment by

sh-4.2# chroot /mnt/sysimage


## You can now proceed with the recovery or troubleshooting, e.g. to change root password


sh-4.2# passwd root

Method 2 - edit grub menu

Boot the system

At the GRUB menu, press e

At the grub editor, use the arrow keys to look for the line that starts with linux16

Move the cursor to the end of that line

Add to the end of the line: rd.break enforcing=0

Press Ctrl-x to save

## You will be presented with the following prompt

switch_root:/#


## type the following to mount rhe root filesystem of the system being recovered

switch_root:/# mount -o remount,rw /sysroot

switch_root:/# chroot /sysroot


## the prompt will change to

sh-4.2#


## you can perform the troubleshooting or recovery accordingly


## e.g. to change the root password

sh-4.2# passwd root

sh-4.2# exit

switch_root#: exit
•    system will then boot to normal multi user mode
 
login as root with the new password
•    at this point /etc/shadow file will have lost it's SELinux label, need to put it back
 
# ls -ldZ /etc/shadow
----------. root root system_u:object_r:unlabeled_t:s0 /etc/shadow
 
# restorecon /etc/shadow
 
# ls -ldZ /etc/shadow
----------. root root system_u:object_r:shadow_t:s0    /etc/shadow