Traduction française disponible sur http://grub.enbug.org/GRUB2LiveCDInstallGuide-FR
If you just want to see the commands without all the text scroll down to the bottom.
GRUB 2: Live CD Install Guide
I am not an expert on linux, and much less on GRUB. These are steps I took in repairing my GRUB 2 installation, with major assistance from fezie (aka FelixZielcke), of course.
History
A little bit about why this guide ended up being written. You can skip this section and go straight to Step One: Booting. For those of you interested only in the list of commands executed, scroll down to the bottom of the page.
I read somewhere during the upgrade process that GRUB 2 does not use menu.lst anymore, so I thought the old gushy stuff would be cleaned up. However, this wasn't the case, but before I noticed that, I went ahead and read the new config file, modified it to my liking, etc. when all of a sudden I see a menu.lst. My ignorance led me to thinking that all of the files inside the /boot/grub folder were from GRUB Legacy (that's just simply not the case, though) and so I decided to clean out the folder and ran grub-mkconfig -o /boot/grub/grub.cfg to recreate the config again. The command executed and created a new grub.cfg for me and proceeded to tell me that the file was created fine. After this I think to myself, "Viola! I'm done! So fresh and so clean, clean!"
Mind you, (another side note) grub-install is the key command to run if you want to actually install GRUB 2, but unfortunately I didn't run it manually, either I ignored something or it isn't mentioned anywhere during install. Anyhow, I went ahead and restarted my machine all happy and dandy thinking I would be seeing a whole new and improved GRUB. I wait and see the usual "Stage 1.5" part (which belongs to GRUB Legacy, not GRUB 2, but I didn't know this then) and just half a second later, I am presented with this beautifully written text saying "Error 15." Great, no system to boot into and no idea on how to go about this issue either and so this is where all the hours of Googling started to no avail. I found a page of someone saying that they had fix a problem they had by going on the IRC channel and I jumped on that bandwagon too and got my problem fixed.
I received an enormous amount of help from fezie (aka FelixZielcke) in the IRC channel. Unfortunately, he doesn't have a personal wiki page, so he gets mentioned by name.
PS. Regardless of how I botched up my system, you should be able to reinstall GRUB 2 using these instructions.
Step One: Booting
- Grab a Live CD and boot your system with it. Just for reference's sake, I used the Ubuntu Live CD, but any other distribution should be just as good.
Step Two: Mounting and chroot'ing
Open a Terminal window and type sudo fdisk -l (That's a lowercase L at the end).
Now this part can be tricky because you have to figure out which one of those listed devices is your linux installation. The easiest way is to see which one is listed as Linux, so remember this value. Mine was /dev/sda1 and so I will use that as reference in this guide.
If you got a separate /boot partition, you'll have to mount it too.
Let's proceed to mounting your installed system into the /mnt folder by doing so, sudo mount /dev/sda1 /mnt
If you got a separate /boot, sudo mount /dev/sda2 /mnt/boot. Be carefull, the "/boot" may (can) be /dev/sda1 and the root "/" be /dev/sda2.
Once we have our system mounted, we need to mount the devices that the Live CD found, sudo mount --bind /dev /mnt/dev
On Ubuntu/Debian you also need to mount /proc and /sys for os-prober. sudo mount --bind /proc /mnt/proc and sudo mount --bind /sys /mnt/sys
Your system should be ready to be chroot'd into, sudo chroot /mnt
- And you should have just arrived as root into your installed system.
Step Three: GRUB 2 Install
Prefix: once you chroot into a system you should technically be considered root (hence the name), however, there is hundreds of linux distributions and not all should follow the exact same steps. This means that you might encounter a system where you will still need to type sudo before any command.
In case you don't have already grub2 installed and you're using Debian or Ubuntu, then run apt-get install grub-pc
Make sure you edit the /etc/default/grub file (only if you know what you are doing!) to your liking then run the following command, grub-mkconfig -o /boot/grub/grub.cfg (While I did received some errors during the execution of this command, pertaining to detection of the installed file system. It attempted NTFS and some others, I ignore them since I know for a fact it's linux and it's an ext3 format. It also gave some messages prior to the errors that it successfully updated the config file)
Once the config file is created and no major error was reported, type grub-install /dev/sda (I am assuming you want to install it on the hard drive MBR. If you know what you are doing and you only want to install it on a partition's bootsector, I *think* it should work with /dev/sda1 too)
If by any chance the previous step gives you trouble as far as detecting which is the boot device, try grub-install --recheck /dev/sda
Step Four: Unmounting
This step might not be absolutely necessary, but I like to do it just for my own peace of mind.
Press Ctrl+D to exit out of the chroot.
Once you exit back to your regular console, undo all the mounting, first the /dev with sudo umount /mnt/dev
Secondly, unmount the root system, sudo umount /mnt
- And you should be free to restart your system right into GRUB 2 and then into your system installation.
Commands list
This is a list of the commands executed in order,
sudo fdisk -l
sudo mount /dev/sda1 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
(optional, only if you're on Ubuntu/Debian) apt-get install grub-pc
grub-mkconfig -o /boot/grub/grub.cfg
grub-install /dev/sda (try grub-install --recheck /dev/sda if it fails)
Ctrl+D (to exit out of chroot)
sudo umount /mnt/dev
sudo umount /mnt