Grub
From Foomagic
If you have managed to mess grub up (probably from installing windows after debian) and need to use the Sarge d-i installer to fix your MBR, then hopefully this might help. This page is aimed at the new Debian user who doesn't yet have much knowledge in using the install cd for rescue purposes.
Firstly, the d-i uses devfs, so you *will not* be able to use "mount /dev/hda? /foo" (many rescue cd's you can use this, but not the d-i installer)
From the Debian installer FAQ.
Question 28: Can I use d-i as a rescue system? What pitfalls are there?
Yes, you can use d-i to mount your hard disks and fix /etc/shadow if you forgot your password.
And you can also use d-i to boot your system to chroot into your installation and execute your boot-loader (grub, lilo, yaboot, ...) if you cannot boot from hard disk any more.
- ignore this part (unless you have an etch d-i cd)* If you have a version of the installer that is later than that released in sarge, proper rescue support is included, just boot the installer with "rescue" and follow the prompts until it mounts your hard disk and gives you a shell chrooted into your system.
Otherwise, just boot the installation system as if you were starting a new installation, proceed to the point where you get to partitioning harddisks and stop there. Next switch to VT2 (using alt-F2) or back out to the menu and start a shell from there. Create a directory /target, manually mount the partition(s) where you installed Debian on /target and execute chroot /target. Note: the installer uses devfs, so you will find your harddisks under /dev/discs. You cannot use the d-i menu item "install boot-loader" because the menu systems uses dependencies which require a Debian install (on a clean partition...) which you don't want.
Well, as you can see, you cannot use /dev/hd[foo], so once you have let the installer run up to the partitioning page (you need to do this so that all your devices are detected) its a simple matter of getting to VT2 and running a few commands and grub will be back where it belongs. Remember you can use tab completion here, which helps take the guesswork out of what you need to put in next. For those who aren't really aware of this, whenever you get stuck as to which dir to put in next for your mount command, if you hit <tab> twice it will show you the directories below the one you are in at the moment. Also, if you put the first letter in of the directory you want, and hit <tab>, then it will complete the directory name for you (as long as there is only one dir starting with that letter, otherwise you need to hit tab twice to see all options) So here basicically are the commands you need to run if your debian partition is on hda and its partition 2.
#mkdir /rescue #mount /dev/discs/disc0/part2 /rescue #chroot /rescue #grub (here you will get a > prompt) > root (hd0,1) >setup (hd0) >quit
Thats it, during the grub installation it should say its detecting drives etc, and then tell you if it succeeded or failed, all you need to do now is reboot and you should be greeted with the grub screen. Instead of running grub as I have you could also just run the grub-install script which does it automagically without any input needed except for you to say your happy with its choices. The code for grub-install would be like so. Basically after the chroot, you are running your'e debian installation so the full range of cli tools are available to you from that point.
#grub-install /dev/hda
Personally I like to run plain old Grub, but do whatever you're happy with. For those that are confused by the grub commands heres a quick explaination. Its very simple, in that grub starts its naming from 0 instead of 1. So, hda (the first hard drive) is hd0 and partition2 is (hd0,1) partition 3 is (hd0,2) and so on. Once you have read this and fixed your'e debian system, then you might want to install the grub-doc package and read up on all the things that grub can do.
