How to: Recovering Linux grub boot loader password

by LinuxTitli · 4 comments

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 using following method/Procedure:

* Use Knoppix cd
* Remove password from Grub configuration file
* Reboot system
* Change root password
* Setup new Grub password if required (optional)

Knoppix Live cd

The best way to recovering (or reset) a password (and to solve many other problem) is use Knoppix Live CD. First downloaded knoppix and 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

Mount a partition

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

Remove Grub password

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


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

Change Root password

Now your Grub password removed from system. You need to login to system without password. To restore root user password boot system into single user mode.

1) At Grub prompt press 'e' to edit command before booting.

2) Select second line

3) Again, press 'e' to edit selected command

4) Type following line
init=/bin/shORinit=/bin/bash

4) Press 'b' to boot system

5) Now you are at shell prompt. Just change root password with passwd command:
# passwd
Please note that depend upon your Linux distribution you may need to remount root partition in read/write mode before running above command.

See also:

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 4 comments… read them below or add one }

1 Anonymous 02.26.06 at 2:55 pm

If you can’t change the password after booting in single mode , then run the following list of commands:
(In most cases the root filesystem system will be mounted readonly , so we need to remount it)

#mount -t proc proc /proc
#cp /proc/mounts /etc/mtab
#mount -o remount,rw /

2 M. Mohamed Rafi 09.10.07 at 9:52 am

give the some instruction

3 lohith 01.12.09 at 7:56 am

this is for grub i want the settings for redhat if it is same i not able to enter the single user mode.
kernel /vmlinuz-2.4.20-8.ro root=LABEL= /hda=ide-scsi

after this line i press e and it enter to the edit mode after that i confused i change the settings it may cause the problem in OS
please help me
if u posible in detail

4 reise 01.21.10 at 2:25 pm

I added init=/bin/sh to the end of the kernel line but it stills goes to prompt and not to shell directly. What I’m doing wrong?

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: