Root Password recovery
In this tutorial I will demonstrate you how to recover you lost password.
This tutorial is for RHEL 7 Password recovery.
Before we go further I would like to brief Linux boot process,
- When pushed power button your PC/Server it will powered on and the system firmware will runs POST (Power On Self Test) which will check and initiate attached hardware. You can do modifications to these process by BIOS/UFFI configuration
- After POST, system firmware will look for bootable device in other words it look for Master Boor Record (MBR)
- Then the System will reads the boot loader from the disk and let boot loader to take control of the system
- Now the boot loader loads its configuration from disk, at that point you may display the boot options
- Depends on your selection boot loader will load the kernel and initramfs from disk to you memory(RAM). Initramfs is some gziped archive contains kernel modules for hardware all hardware which requires on boot.
- Now boot loader hand over control to kernel with the optional commands to the kernel and memory location for initramfs.
- Then kernel will initialize all the hardware according to the driver which found in initramfs. This process will execute as PID 1. Further initramfs contains copy of systemd and also an udev (for hardware initialization)
- Now at this point root file system will mount on /sysroot
- Afterwards initramfs root file system which mounted on /sysroot will switched to system root file system. and re-executed the copy of systemd which is installed on the system
- And finally system will look for the default target and start it by resolving dependencies
Now Lets get back to our issue,
To resolve this issue, we can pause initramfs at some point and provide a shell and do the changes that we requires and continue when our shell exists.
Following Steps will do the trick,
- Reboot the System
- Interrupt the boot loader
- Select the entry which need to be booted
- Edit the entry
- And boot the system with changes
- remount the /sysroot with read write permission
- Switch to chroot jail
- Change your password
- Make system to relabel its file system (This is for SELinux purposes)
Now after rebooting the system interrupt the boot loader by pressing a arrow key, and it may look like this.
Select your desired entry to boot and press e to edit
Now find the the line that starts with "linux16" line and jump to the end of the line press ("END" button on key board) remove it till ro and add the entry
rd.break
And it will look like this
Press CTRL+X to boot with changes
At the completion system will be mounted on /sysroot and but it will be read only mount
In order to the changes it is required re-mount /sysroot with read-write permission
#mount -oremount,rw /sysroot
At this point we want system to treat /sysroot as our root file system. In order to that you may switch in to a chroot jail
#chroot /sysroot
Now you may change the root password
#passwd root
And in order to make sure all the unlabeled files relabel during the boot you may create a file call ".autorelabel" on the root directory
#touch /.autorelabel
Now you may exit from chroot jail and also from iniframs debugging shell by using exit command.
Now it will continue the boot process but it may take some time since relabeling takes some time.
Afterwards your may use newly configured password to log in to the system.
Comments
Post a Comment