Reinstall a corrupt Grub2

So.. My trusted 5 old Seagate HDD crashed on me during a reboot. Grub was installed on its MBR and hence I couldnt even boot to my Windows 8 partition and Gentoo without reinstalling Grub.

While trying to do it from a Ubuntu LiveCD, I found that it wouldnt boot at all. I found a Debian LiveCD and managed to boot to terminal based Rescue mode and run e2fsck on the HDD. But surprise, surprise..No errors on the Seagate HDD were found. Only my Hitachi containing Gentoo was present on it. Ubuntu was on Seagate. I had just upgraded to Kubuntu 12.10 yesterday after a painful upgrade process. Painful because of my slow internet speeds.

Anyway, I got Debian and fixed the disk. I then tried to fix the Grub2 with Debian, but it seemed to have issues even doing a chroot. Finally I booted off the Ubuntu LiveCD and initially having i get stuck at boot.

The solution to boot the Ubuntu LiveCD was to do a acpi=off, noapic, nolapic option. To get this, press any key during boot when the pink Ubuntu screen shows up with a small icon at the bottom. Now you get a full fledged boot menu, Hit F6 after choosing your language and choose the options mentioned. Now it ought to boot.

Once booted, type “Terminal” in Unity, and get to the shell. Alternately, you can Hit Ctrl-F1-6 for shell. Hit Ctrl-F7 to get back.

Now, locate the disk where your boot partition is located with:

sudo parted -l


Find the ext4 partition(s), mount it, chroot to it.

sudo mount /dev/sda7 /mnt


ls -l /mnt will show you whether /mnt/boot is present. If not, you chose the wrong disk.

sudo mount --bind /dev /mnt/dev

sudo mount --bind /proc /mnt/proc

sudo chroot /mnt

Note: For a split boot an / partition, you need to first mount your partition containing /, to /mnt; then mount the partition for /boot, to /mnt/boot.

Now you’re in your old linux installation. You can now install Grub.

sudo grub-install /dev/sda


Note that this is the main disk and not an individual partition. You need to install it to MBR (in my case).

After rebooting, you will find grub installed. However Windows might be lost from grub menu. You can readd it with the following commands:

sudo su -

After rebooting, you’ll get Windows back on the grub2 list. If you need Windows to always come first in the menu, do this.

Since my distro was Gentoo, I found an issue. It gave me an error:

/dev/root: Not found or not a block device.[/code]
To fix, I had to do an additional command:
grep -v rootfs /proc/mounts > /etc/mtab


Details here

The command actually sends the entire list of partition info to the file mtab.

Now repeat the command and it works:

sudo grub-install /dev/sda

Read more:

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Change GRUB boot order – Ubuntu 11.10

My grub boot menu showed linux as first. It was fine while I was working on the kernel source. But now I tend to use a lot of Win gui apps. So I had to change it.

You can either do:

  • Manually edit the grub config file followed by updating grub menu

sudo emacs /etc/default/grub
sudo update-grub

Change the number in GRUB_DEFAULT line. First boot menu is numbered 0. If it is 6th boot menu, type in GRUB_DEFAULT=5.

Problem was that I didnt remember what order my Win 7 came at. So I had to use a gui tool: startupmanager

  • Or use a gui tool called startupmanager

sudo apt-get install startupmanager

Very nice to configure:

Finally I reopened the file /etc/default/grub and found that the order was actually 5:


The good thing about this tool is that it actually shows you what the name that appears in the title is.

Update: Using the above didnt help me fine tune the startup menu and I found myself manually editing the /boot/grub/grub.cfg to reorder the menu. Note that if you wish your Windows option to be listed above Linux, just rename 30_os-loader to 09_os-loader (above 10_linux)

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.