Thursday, September 11, 2008

Reset root's Password (with GRUB)

If you lost your root's password, but you have GRUB boot loader installed. Here's the list of steps to reset it:
  • Power up your machine and press ESC while GRUB menu starts.
  • If there is a 'recovery mode' option, select it and press 'b' to boot into single user mode.
  • Press 'e' (to edit) to the default menu option.
  • Highlight the line with 'kernel' and press 'e' again.
  • Append 'single' at the end of the line.
  • Press 'b' to boot into single-user mode.
With this, you should end up getting a shell with root privilege (#).

Note, some distribution might require you to re-mount the partition (with /etc inside) with read-write:

mount -o rw,remount /dev/hda1 /
Another way is to reset password with Live CD.
  • Boot the machine with a LiveCD.
  • Search the partition that hold the /etc/passwd file: sudo fdisk -l
  • Make a directory mount point: sudo mkdir /media/sda1
  • Mount the partition with the mount point: sudo mount /dev/sda1 /media/sda1
  • Change root to the mount point: sudo chroot /media/sda1
  • Change the password: passwd root