How To Exit Emergency Mode Without Root Password On Linux
I recently had the pleasure of having my laptop reboot into emergency mode after I hard powered it off. The passwords I tried did not work nor could not remember my root password. Hopefully this guide will be helpful for me in the future or for any poor soul who is locked out of emergency mode.
How To Change The Root Password, When Root Password Is Unknown
How To Change Kernel Parameters
Instructions from Milosz Galazka
In case the Recovery mode menu entry is not available, you need to perform five simple steps in order to modify kernel parameters list.
- Turn on computer.
- Access GRUB menu.
- Edit existing menu entry (use
e
key).- Add
single
keyword (alternatively you can use-s
orS
) to the Linux kernel parameters list.- Press
CTRL-X
orF10
while still in edit mode to continue boot process.
How To Reset The Root Password
Instructions from TecMint
Now check the status of root partition by running following command on the single user mode.
# mount | grep root
> > You may notice that root partition is reported to be
'ro'
(Read Only). We need to have read-write permission on root partition to change the root password.# mount -o remount,rw /
Also cross check, if the root partition is mounted with read-write permission mode.
# mount | grep root
> Now you can change the root password by typing the passwd command. But that is not done. We need to relabel SELinux context. If we skip relabeling the whole SELinux context we would be able to login using using password.
# passwd root [Enter New Password] [Re-enter New Password]
# touch /.autorelabel
> Reboot and login again to root account and see if everything works ok or not?
# exec /sbin/init
Fixing Emergency Mode Error
Instructions from Molesbite Hacks
Type
systemctl
You'll get a list of logs, scroll till you find the error highlighted in red.
Type
fsck /dev/mapper/fedora-root
Hit Y (yes)
When I initially ran fsck /dev/mapper/fedora-root
, I got a error that wouldn't allow me to commit the changes
I decided to run systemctl
and look for the red error
In my case, the error was in /dev/mapper/fedora-root
I modified the directory to be /dev/mapper/fedora-home
, matching the one listed by systemctl
Why We Unmount And Remount The Root Partition To Reset The Root Password
As explained in the TecMint article, we unmount and remount (with mount -o remount,rw /
) the root partition so that we have read-write access to modify the root's password.