Linux: Recovery root access

Published by

Posted on October 07, 2015

chroot via a livecd

Boot the LiveCD and mount the root partition of your main system.
Enter the chroot session.
Use the passwd command to set the new password (you won’t be prompted for an old one).
Exit chroot session.
Unmount the root partition.
reboot

Edit Grub

Select the appropriate boot entry in the GRUB menu and press e to edit the line.
Select the kernel line and press e again to edit it.
Append init=/bin/bash at the end of line.
Press b to boot (this change is only temporary and will not be saved to your menu.lst). After booting you will be at the bash prompt.
Your root file system is mounted as readonly now, so remount it as read/write mount -n -o remount,rw /.
Use the passwd command to create a new root password.
reboot

Edit Grub w/ selinux enabled

Select the appropriate boot entry in the GRUB menu and press e to edit the line.
Select the kernel line and press e again to edit it.
Append init=/bin/bash at the end of line.
Press b to boot (this change is only temporary and will not be saved to your menu.lst). After booting you will be at the bash prompt.
Your root file system is mounted as readonly now, so remount it as read/write mount -n -o remount,rw /.
Use the passwd command to create a new root password.
touch / .autorelabel
/sbin/reboot -f