Wednesday 6 January 2016

Rescuing a Non-booting GRUB on Linux

Rescuing a Non-booting GRUB on Linux

1. To check what partition available in linux use
grub> ls

Output:
(hd0,1) (hd0,msdos1)

2. To verify the file available in particular partition


grub> ls(hd0,1)

Output:
ost+found/ bin/ boot/ cdrom/ dev/ etc/ home/  lib/
lib64/ media/ mnt/ opt/ proc/ root/ run/ sbin/
srv/ sys/ tmp/ usr/ var/ vmlinuz vmlinuz.old
initrd.img initrd.img.old


In the output we can find the root file system is present in (hd0,1) partition. Now we can start our rescue of linux

3. booting from grub

a) to set the boot files and boot the system from the grub> prompt. We know from running the ls command that there is a Linux root filesystem on (hd0,1), and you can keep searching until you verify where /boot/grub is. Then run these commands, using your own root partition, kernel, and initrd image:

grub> set root=(hd0,1) # sets the partition that the root filesystem is on
grub> linux /boot/vmlinuz-3.08.0-28-generic root=/dev/sda1 # tells GRUB the location of the kernel you want to use
grub> initrd /boot/initrd.img-3.08.0-28-generic # sets the initrd file
grub> boot #boots your system

b) On some Linux systems the current kernels and initrds are symlinked into the top level of the root filesystem:
$ ls -l /
vmlinuz -> boot/vmlinuz-3.08.0-28-generic
initrd.img -> boot/
initrd.img-3.08.0-28-generic
to boot grub like this follow the below steps,
grub> set root=(hd0,1)
grub> linux /vmlinuz root=/dev/sda1
grub> initrd /initrd.img
grub> boot

4. Boot from grub-rescue mode:

If you're in the GRUB rescue shell the commands are different, and you have to load thenormal.mod andlinux.mod modules:
grub rescue> set prefix=(hd0,1)/boot/grub
grub rescue> set root=(hd0,1)
grub rescue> insmod normal
grub rescue> normal
grub rescue> insmod linux
grub rescue> linux /boot/vmlinuz-3.08.0-28-generic root=/dev/sda1
grub rescue> initrd /boot/initrd.img-3.08.0-28-generic
grub rescue> boot


5. to make the permanent repair:

When you have successfully booted your system, run these commands to fix GRUB permanently:
# update-grub
# grub-install /dev/sda
When you run grub-install remember you're installing it to the boot sector of your hard drive and not to a partition, so do not use a partition number like /dev/sda1.




No comments:

Post a Comment