Repairing Boot Issues


There's always a sinking feeling, deep in the pit of your stomach, when a system won't boot. In the past, a failure to boot meant you'd spend hours fiddling with config files in an often fruitless attempt to fix the problem, or worse, a re-install of the OS. Now a boot problem doesn't have to mean a big time loss because Knoppix can often be used to fix issues that arise when you first start up your computer. In fact, you may be surprised just how easy it is to wield Knoppix as a powerful fix-it tool.

Note 

We know that we sure could have used Knoppix eight years ago when we tried to install Red Hat on a Windows box to create a dual-boot machine and instead ended up staring in horror at the blinking LI.. on the computer monitor, certain that we had lost a lot of data on the hard drive. Oh, the humanity!

Restoring a Missing MBR

Quite often, the cause of a boot issue involves a corrupted or missing MBR (Master Boot Record). The MBR is vitally important to your computer. It is a 512-byte area at the beginning of your hard drive that contains two critical items: the information that enables your computer to boot, and your partition tables. If your MBR gets messed up, you're normally up a creek. How does the MBR get messed up? Well, attempting to create a dual-boot system but installing Windows after Linux usually does the trick nicely (always install Windows first, and then install Linux!), and so will running fdisk /mbr from within Windows. Sometimes it just gets corrupted for no discernable reason.

Because the MBR is so vitally important, you really should back it up regularly, just in case disaster strikes. You can back up the MBR from within Knoppix by using the following command (which assumes that you're copying the MBR on the machine named Homer onto a USB flash drive):

 $ sudo dd if=/dev/hda of=/mnt/uba1/mbr_homer_backup bs=512 image from book    count=1 

The dd command creates images of drives, but this command uses the bs (block size) option to tell dd to output only 512 bytes at a time, while the count option means that dd should only do so once. Because the MBR is contained in the first 512 bytes of the hard drive, this command copies it. (For more information on the dd command, see the section "Backing Up Partitions" later in this chapter.) Now the boot sector and the partition table for Homer are backed up on your USB flash drive, which should make you feel safer.

Tip 

Yes, you can use Knoppix, but really, you should back up the MBR no matter what OS you're using. Don't wait until you're using Knoppix to perform the backup!

With your MBR backed up, you can restore it if it ever gets nuked. To do so, simply reverse the directories in the preceding dd command:

 $ sudo dd if=/mnt/uba1/mbr_homer_backup of=/dev/hda bs=512 count=1 

Keep in mind that this will restore both your boot code and your partition table. Every time you change your partition scheme, you must back up your MBR again (fortunately, most people rarely if ever alter their partitions, so one backup should do the trick). If you have not changed your partitions, this command should be just fine. If, however, you have altered your partition table since the original backup of your MBR (Bad computer user! Bad!), then you want to run the following command:

 $ sudo dd if=/mnt/uba1/mbr_homer_backup of=/dev/hda bs=446 count=1 

The MBR's boot code is located in the first 446 bytes of that 512-byte area; the last 66 bytes contain the partition table. Restore the first 446 bytes and you have your boot code back; restore the full 512 bytes and you have your boot code and partition table back. Now that is good stuff to know!

Caution 

Be very careful typing those numbers in the dd command! Fat-fingering them and typing 521 instead of 512 can lead to disaster.

Fixing LILO

LILO (LInux LOader) is the old standby when it comes to Linux boot loaders, the code that resides in the first 446 bytes of the MBR. It's possible to break LILO by upgrading the kernel and misconfiguring lilo.conf, the LILO configuration file. It can be broken in other ways as well. Fortunately, you can fix it.

To restore LILO, you need to know which partition on your hard drive was your root partition. To find this out, locate the partition containing /etc/lilo.conf. In many cases, this will be /dev/hda1, but not always, so be very sure about which partition you need to work with. The examples in this section assume it to be /dev/hdal.

By default, Knoppix mounts partitions without the dev option turned on; however, to repair LILO, you must mount the root partition with the dev option turned on (if you're curious, the man page for mount explains that the dev option tells Linux to "Interpret character or block special devices on the filesystem"), like this:

 $ sudo mount -o dev /mnt/hda1 

To repair LILO, you need to fool it into thinking that /mnt/hda1 (or whatever your root partition may be) under Knoppix is actually / if the machine had booted without Knoppix. To do this, use the chroot command, which tells processes started with it to treat a given directory as the root directory. Now that the /mnt/hda1 partition is mounted, restore LILO by running the following:

 $ sudo chroot /mnt/hda1 lilo 

This tells the system to treat /mnt/hda1 like it was actually /, and to run lilo, which restores LILO just the way you want it. Take Knoppix out, reboot, and LILO should work.

Fixing GRUB

The process for fixing GRUB (the GRand Unified Bootloader), a more modern bootloader than LILO, is pretty much the same as fixing LILO. You first need to find the partition on your hard drive that acts as the root partition and holds the GRUB config file /boot/ grub/menu.1st. You need to mount the partition that contains GRUB's config file with the dev option turned on, like this:

 $ sudo mount -o dev /mnt/hda1 

Just as with LILO, you need to use chroot with GRUB, but the full command is different because, of course, this is a different bootloader:

 $ sudo chroot /mnt/hda1 grub-install /dev/hda 

Now reboot, and GRUB should work. Woohoo!

Note 

More and more distros are using GRUB instead of LILO because it's a newer, more flexible, more powerful boot loader. It's really in your best interest to learn it.



Hacking Knoppix
Hacking Knoppix (ExtremeTech)
ISBN: 0764597841
EAN: 2147483647
Year: 2007
Pages: 118

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net