Friday, May 30, 2008

Linux - Recovering grub and root password


If you have, a password protected grub boot loader and you forgot both root and grub password, then you can recover grub-boot loader password.


The best way to recovering (or reset) a password (and to solve many other problem) is to use Knoppix Live CD. First downloaded knoppix and then burn it on CD. Put CD into CD/DVD rom and boot system. You need to boot system into single user mode, at boot: prompt type linux single:

boot: linux single


You need to mount a partition where you grub configuration file is stored. Depend upon Linux distribution the location of Grub configuration file changes. Following list summaries Grub configuration file location:


Debian Linux Grub configuration file location: /boot/grub/menu.lst

Suse Linux Grub configuration file location: /etc/grub.conf

Red Hat/Fedora Linux Grub configuration file location: /boot/grub/grub.conf


 


If you forgot partition name use fdisk -l command to obtained partition list.

# fdisk -l


Mount your partition:

# mount /dev/sdb1 /mnt


a) If you are using Debian Linux you need to modify /boot/grub/menu.lst file:

# cd /mnt/boot/grub

# vi menu.lst



b) If you are using Suse Linux you need to modify /etc/grub.conf file

# cd /mnt/etc

# vi grub.conf


c) If you are using Red Hat / Fedora Linux you need to modify /boot/grub/grub.conf file

# cd /mnt/boot/grub

# vi grub.conf


Once file opened using text editor, locate password line and remove it:

password --md5 $1$9sdflksdf/sdf44k


Save file and reboot the system.

# sync; sync

# cd /

# umount /mnt

# reboot


 


How to: Recovering root password


If you cannot remember your root password, you need to boot your system as linux single.


If you are using GRUB, once you have loaded the GRUB boot screen, type e for edit. You are presented with a list of items in the configuration file for the boot label you have selected.


Choose the line that starts with kernel and type e to edit this boot entry.


At the end of the kernel line, add:


single


Press to exit edit mode.


Once the GRUB screen has returned, type b to boot into single user mode.


If you are using LILO, press [Ctrl]+[x] to exit the graphical LILO screen and gain access to the LILO boot: prompt.


Next, enter linux single at the LILO boot: prompt.


Once you have booted into single user mode using either GRUB or LILO and have access to the # prompt, you must type passwd root, which allows you to enter a new password for root. At this point you can type shutdown -r now to reboot the system with the new root password.


If you cannot remember your user account password, you must become root. To become root, type su - and enter your root password when prompted. Then, type passwd <username>. This allows you to enter a new password for the specified user account.


 

No comments: