Download Knoppix Hacks, Second Edition (O`Reilly, 2008)

Transcript
HACK
Repair Grub
H A C K
Repair Grub
#66
Use Knoppix to restore grub to the Master Boot Record (MBR).
Hack #66
There are two popular bootloaders for Linux: lilo and grub. Lilo has been
around longer, and many distributions default to installing it, but most also
offer grub packages. Grub has many interesting features that have made it
popular, including the ability to change kernels and any other grub options
at boot time. Grub also reads from its configuration file at boot, so you can
change options in that file and don’t have to reinstall it just to make
changes. Like lilo, grub sometimes gets overwritten by a Windows install or
by an accidental installation of lilo to the MBR. The procedure to restore
grub to the MBR is almost identical to restoring lilo.
First, identify your root partition as in the lilo hack
ple, the root partition is /dev/hda1.
[Hack #65].
In this exam-
If you want to make any changes to your grub configuration,
now is the time to mount the partition read/write and edit
the /boot/grub/menu.lst file.
Next, mount the partition with the dev option enabled and with write permissions, so if the filesystem is not yet mounted, mount it with:
knoppix@tty1[knoppix]$ sudo mount -o dev,rw /mnt/hda1
If the filesystem is already mounted, then remount it with:
knoppix@tty1[knoppix]$ sudo mount -o remount,dev,rw /mnt/hda1
Once the filesystem is mounted, restore grub with the following command:
knoppix@tty1[hda1]$ sudo chroot /mnt/hda1 grub-install /dev/hda
Of course, replace /mnt/hda1 and /dev/hda with your mounted root partition and the device to which you wish to install grub, respectively.
If you use devfs, or for some reason, the chroot environment
doesn’t work, mount the filesystem with write permissions,
then run sudo grub-install -root-directory=/mnt/hda1
/dev/hda.
Install grub on a System Without grub
Once grub is installed on an MBR, all it needs is the contents of the /boot/
grub/ directory to boot your system. That means you can use Knoppix to
install grub to a system that doesn’t have grub binaries on it. Obviously,
once you have the grub configuration files set up, you want to find and
Chapter 6, Repair Linux |
203
#66