Tuesday, December 30, 2008

Reinstall grub from live CD

Yesterday I had to install win$ XP again on my machine (until now I was using wine, which is great, or win$ as a virtual machine inside vmware server, but sometimes that's not enough...). As usual, the installation breaks the boot loader, whether you have lilo or grub, and you have to reinstall it again in order to be able to boot your linux (or whatever OS that's not a windows).
This is not always as easy as it should be, or at least I always forget how to do it. So yesterday, what worked for me (twice) was:
1. boot from a Knoppix Live-CD (it's just the one I have always lying around, and Knoppix is great)
2. Don't need a graphical session, just type Ctrl+Alt+F1 and go to the terminal: you're already as root
3. mount the file system you have your /boot files in, my case:
mount /media/hda2 (once mounted, check that this really contains or is your boot directory)
4. install grub:
grub-install --no-floppy --root-directory=/media/hda2 /dev/hda
where:
- I have to put --no-floppy, otherwise it fails (guess my floppy drive is not working, I never use it ;) )
- I always install grub on the Master Boot Record of the first drive: /dev/hda (if you have sata drives, then it should be /dev/sda
- root-directory has to point to the mount point from where you can see your boot directory, not to the boot directory itself (e.g. if you put /media/hda2/boot the grub install works, but you will have a new boot dir inside the previous one, and you won't find your usual menu.lst file).

No comments: