Search This Blog

Loading...

Saturday, August 22, 2009

Reset a forgotten root password with a live CD

If you have forgotten the root password of a system, you can very easily reset it with a live CD
Any live Linux cd from standard Linux distros such a ubuntu , knoppix etc can be used.

Boot the system with the live CD
Open a terminal and use dmesg command to find out the hard disk.
The ide hard disk are generally named as hda, hdb etc. SATA and SCSI disks are named sda sdb etc. My SATA hard disk is detected as below.

[ 3.206832] sda: sda1 sda2 sda3 sda4 <>
[ 3.266679] sd 0:0:0:0: [sda] Attached SCSI disk

The above hard disk has several partitions. sda2 , sda2 ,sda3 are primary partitions , sda4 is divided into several logical partitions. You have to find out where your root partitions is mounted.
You can use cfdisk to find out the partitions.
$sudo cfdisk /dev/sda

I am getting the following screen .





You can examine the screen and find out the Linux partitions . If you have multiple installations , this can be tricky. You can quit from cfdisk and return to terminal. Now, try to mount the desired partition into some directory. ( Assuming that you Linux partition is /dev/sda2 , the following commands are described.)

Aquire root powers on the terminal with ( in the case of ubuntu live cd which I use)

$sudo su
 # mount /dev/sda2  /mnt/  
Now, chroot to /mnt
  #  chroot /mnt
Change the password

# passwd

Next unmount the partition and enjoy .

# umount /mnt

1 comments:

rationalbeing said...

Nice post, but you don't need a live cd to recover lost root password. In ubuntu all you need to do is, go to the grub menu and select the option which says something like 'recovery partition'(not exactly, but something like it). Afterwards a menu will come up where you have the option to drop into a root shell. That's it, now simply type 'passwd username' and change the password. Hope it helps :-)