Wednesday, March 4, 2015

Recovering Linux when it dumps you to the GRUB rescue prompt

This post is for if/when you can't boot Linux, and instead see the GRUB rescue prompt:

GRUB>

For starters, from the GRUB prompt, you can put in

help

To view commands, and

help {command name}

To view help on a specific command.

Side note, REMEMBER, Linux filenames are case-sensitive! So be sure the filename cases match what they need to be (e.g. /ETC/FSTAB does not exist, /etc/fstab does).

But, this should get you running:

First, let's list the available hard disks and their partitions:

ls

Just to be clear, GRUB uses (hd0,1), whereas Linux uses /dev/sda1 to refer to 1st partition on 1st hard disk, you will see later the difference between the root and kernel commands below - the kernel command is loading the Linux kernel and passing info to it about where the Linux kernel's root is located, and the root command is for GRUB to know it's own root.

Mmkay, let's say you had just one hard disk with two partitions on it, so, let's see what's inside:

ls (hd0,1)/

This lists root directory / of first hard disk's 1st partition - if you find /boot on that partition then that's the one you want, if not, try other disks / partitions

cat (hd0,1)/etc/fstab

This reads the /etc/fstab file to the screen; write down the UUID of your linux install partition

Now,

root (hd0,1) This tells GRUB which hard disk it's booting from, replace 0,1 with the correct numbers referencing the partition you found /boot on <NOT $Boot from Windows!> for example, mine was (hd0,5) - the root command also lets you omit the (hd#,#) prefix for anything located in the same hard disk and partition # as root

Now, type the following and use the tab key at the end until you see a list of kernels, then finish typing the name out (use the newest one unless it gives you problems).

kernel (hd0,1)/boot/vmlinuz{press Tab key until you see list} root=GUID={guid from /etc/fstab} ro

e.g. kernel (hd0,1)/boot/vmlinuz-3.2.0-34-generic root=UUID=1b16b1fb-8699-4e73-8ff0-17b75677a552 ro

This loads your kernel.

Now, load the initial ramdisk image:

initrd (hd0,1)/boot/initrd{press tab and finish}

e.g. /boot/initrd.img-3.2.0-34-generic

Finally,

boot

This pulls the trigger. If you get dumped to a busybox prompt maybe you got the guid wrong, or the GUID has changed. In the kernel line, try using root=LABEL=/dev/sda ro{sdb is second, ide drives use /dev/hda or hdb}

See these links for more comprehension:

The Linux Kernel HOWTO Appendix C - GRUB Details And A Sample grub.conf
Linux Forums: Red Hat / Fedora Linux "root=LABEL=/" in grub.conf

After a successful boot, re-install grub by:
sudo grub-install --recheck /dev/sda {installs the GRUB bootloader  to MBR of 1st HDD} {to install to PBR of 1st HD 1st/partition use /dev/sda1 instead / as well}
sudo update-grub
{and also possibly} sudo grub-mkconfig

Ubuntu Documentation - GRUB2 / Installing
Ubuntu Forums - Grub in 10.10 not detecting all Operating Systems

If you want to view how your GRUB is currently set, you can:

cat (hd0,1)/boot/grub/grub.cfg

Corrections / additions / other comments welcome.  :)