Sometimes you will make a mistake and wipe your disk's MBR (Master Boot Record), or some misbehaving program does it, or you dual boot with Windows and catch a virus that does it. So, you say, I won't be able to boot my system anymore, right? Wrong! There are many ways to recover the boot record.
To recover your boot loader you will need a boot disk. Without a boot disk of some kind you might be completely lost[22].
Put the diskette in the floppy drive and reboot your computer from it. What you do next varies according whether you use LILO or GRUB. No matter which boot loader you use, all the commands you must execute will need to be run as root.
If you use LILO, you just need to issue the following at the command prompt: /sbin/lilo. This will re-install LILO in your disk's boot sector and will fix the problem.
If you use GRUB things are a little bit different than with LILO.
The following example will assume that you are trying to install GRUB in the MBR of your first IDE drive, and that the file stage1 is in the /boot/grub/ directory.
First, invoke GRUB's shell by issuing the command: grub. Once there, issue the following command: root (hd0,0); this will tell GRUB that the files it needs are in the first partition (0) of your first hard disk (hd0). Then issue the following command: setup (hd0); this will install GRUB in the MBR of your first hard disk. That's it!
You can also try to use grub-install /dev/hda to install GRUB on your first hard drive's MBR, but the method described above is the preferred one.
Windows 9x, NT, 2000 and XP upgrades. If you are running a dual-boot system, be very careful to always have a GNU/Linux boot disk prepared. Windows (all versions) usually replaces LILO or GRUB (the boot loader that starts up GNU/Linux and other operating systems) without any warning at all, and if you don't have a boot disk, you will not be able to boot GNU/Linux after you perform the Windows upgrade.
To make a backup copy of your hard disk's Master Boot Record, insert a blank floppy in your floppy disk drive and issue the following:
# dd if=/dev/hda of=/dev/fd0/mbr.bin bs=512 count=1 |
If you want to restore a backed up copy of your hard disk's MBR, insert the floppy containing it into your floppy disk drive and issue the following:
# dd if=/dev/fd0/mbr.bin of=/dev/hda bs=512 |