Howto: repair Grub's menu on a Linux installation that wouldn't boot
This is a simple
recipe
that will be obvious for many users of Un*x
systems,
but which proved useful to me when I needed to fix
Grub
on my laptop. I'm sharing it here for future personal reference, and in
case anyone out there knows even less than I do about booting Linux and
about Grub. This recipe assumes that there is a /boot/
partition
containing valid Linux kernels. In other words, it just creates a
missing menu.lst
file for Grub — it does not deal with other more
complicated, lower-level boot issues. Last time I installed
Ubuntu, I
somehow messed with the boot loader settings. I'm running Ubuntu on a
MacBook Pro with an Intel processor; but I also have Mac OS installed,
and I use
rEFIt
to handle both OS's. Whatever option Ubuntu ticks by default regarding
Grub, I thought it wasn't the right one for my setup. It turned out that
either Ubuntu didn't know how to install Grub correctly for my partition
layout, or I screwed it myself. Anyway. The system was installed
successfully, but once the installation finished, Linux wouldn't boot.
rEFIt detected the new OS correctly, but when it was selected, Grub fell
back to its own limited command line. Now, if I knew more about Grub,
I'd be able to find an image of the Linux kernel and boot the system
with it, using Grub commands. Then I would edit the file
/boot/grub/menu.lst
myself. What I did, instead, was the following:
-
Run Linux from a live CD distro. You can boot using the same CD you used to install Ubuntu (but any live distro which includes Grub in its base system will do).
-
Fire up a terminal.
-
Temporarily rename the
/boot/
directory:$ sudo mv /boot/ /boot.DISABLED
-
Create a symbolic link to the partition on your hard drive that contains the Linux kernels, and call it
/boot/
(if your live system did not mount that partition automatically, find the right device and mount it first under/media/
, or mount it directly onto/boot/
):$ sudo ln -s /boot /media/sda3/ # Your device might not be this one
-
If there is already a
/boot/grub/
directory, disable it:$ sudo mv /boot/grub/ /boot/grub.DISABLED
-
Run
update-grub
(if it returns an error, you might need to create the directory/boot/grub/
yourself first):$ sudo update-grub
-
Restore the original live
/boot/
:$ sudo unlink /boot/ $ sudo mv /boot.DISABLED /boot
-
Reboot the system and extract the live CD; this time Grub should show the menu of available kernels and load the one that you choose.
N.B. Although update-grub
's man
page asks you
to run the command first, then set some options in menu.lst
, and
finally run the command again, update-grub
looks idempotent to me
(anyone knows what I'm missing?).