Recover lost root password
The scenarios may differ but we all have and will(may be) face problems whose solutions are related to the recovery of lost root passwords. I used to face this problem a lot of times and after trying out a lot of different methods I finally came up this article. So, here are a few tips and methods which can help you to recover or change root passwords in different situations.
From the Grub or Grub2
Once you are on the grub menu, press 'e' to edit the menu entries and scroll to the line starting with kernel or linux depending on whether it is grub legacy or grub2 respectively, add "single" at the end and hit enter to save it. The final edited line should look something like this.
linux /boot/vmlinuz-2.6.31-14-generic root=UUID=b8080487-b557-4f55-b288-d7ef2c2b9cc1 ro quiet splash single
P.S. - The first word would be kernel in place of linux if you are using grub legacy.
Now, boot from your edited boot entry and you will be dropped to a shell as root. This is more or less similar to the recovery mode option we see now a days in modern distros. But if you are prompted for a root password (which is mandatory in some systems if you are trying to boot into a single user mode) then you may want to try adding "init=/bin/bash" at the end of the line instead of single. So, the boot entry will look something like this.
linux /boot/vmlinuz-2.6.31-14-generic root=UUID=b8080487-b557-4f55-b288-d7ef2c2b9cc1 ro quiet splash init=/bin/bash
This will boot into a very basic system, using the bash shell instead of init. After you are dropped to the bash shell, you may have to mount the root partition read-write. If you know the root partition then run this command to mount it.
$ mount -o remount,rw /
After that you can change the password using the passwd command.
[root]$ passwd
But what if you are unable to edit the grub menu because grub is password protected. Don't worry, the best part of being a linuxer, there is always way out of everything. Read on!!
Using LiveCD
So, we are here because the Grub is locked. Boot into the live user mode and mount the root partition. If you don't know the root partition then run this command to get a list of diff. partitions on your disk.
[root]$ fdisk -l
Now, find your root partition and mount it. Lets assume that your root partition is /dev/hda1 and run the following command.
[root]$ mount -o,rw /dev/hda1 /mnt
You may check if its the right partition by listing the files in /mnt directory (plz. don't ask, how to do that). Now, chroot mnt directory and change the password.
[root]$ chroot /mnt
[root]$ passwd
Happy now!! But what if the computer has a BIOS level protection ie. you can't boot a Live CD or USB. In such cases its better to consult the BIOS vendor for the solution.



























5 Comments
Post new comment