Repairing the GRUB boot loader

Repair of GRUB after damage to the Master Boot Record (MBR) on a Feisty installation.

Boot from a Knoppix CD;
Repair GRUB boot loader.

As with any installation on any computing platform, it is good practice to ensure important data is backed up in case unforeseen difficulties arise.
Review all instructions on this page before you begin.

Page dependencies (ensure you have access to everything you need before you begin).
Commands issued at the command prompt in this section are done so as superuser or root unless otherwise specified. When installed, Feisty does not ask for a root password to be specified. Either set a root password using sudo passwd root so that you can log in as superuser, or enter the commands listed in this guide prefixed with 'sudo'.
The instructions on this page require you have access to a Knoppix CD. To download Knoppix, visit

Text file editing from the command line.
This guide uses the Nano application for text editing because of its simplicity. Alternative text editors are available. Basic Nano key combinations to remember are CTRL-O to save and CTRL-X to exit.

Page format.
Text in this format indicates command line entry by the user.
Text in this format indicates an error returned by the system.
Text in this format indicates a normal return from the system.
Beware of similar characters such as 1(one), l(lowercase L), 0(zero), O(uppercase 'o'), | (pipe – Shift ' ' usually).
Text enclosed in [square brackets] indicates a build-specific variable such as a version number or user name.

This page was written for Ubuntu 7.04 and may contain content or instructions that are not relevant to other distributions.
This information is provided for guidance only. Use of these instructions is deemed to be at your own risk.
R3UK Limited welcomes comment on this information but cannot guarantee a reply and provides no technical support. Please use one of the many dedicated Linux forums or IRC channels if you require assistance.
Text colours and fonts used in the formatting of this page relating to command input and output are used for illustration purposes. Actual command line colours and fonts will vary according to individual system preferences.

My Vaio is configured for dual boot between XP and Feisty. Some security software I was playing with while booted into XP trashed the Master Boot Record (MBR) and I found it would no longer boot at all (it would reboot immediately after starting the GRUB boot loader (i.e. before the GRUB menu even came up).

I thought I'd document how I got it repaired (in case I ever break it again). Hopefully it will get someone else out of the same hole....

First, I booted from a Knoppix CD. Knoppix is great for getting your ass out of tight corners and an ISO can be downloaded from here if you don't already have a CD.

Once in Knoppix, I opened a Terminal and logged in as su.

The first thing to find was the partition that Linux was installed on so I used the fdisk command with the -l switch...

fdisk -l

... which returned the following result in my case...

Device Boot Start End Blocks Id System
/dev/hda1 * 1 5367 43110396 7 HPFS/NTFS
/dev/hda2 5368 7703 18763920 f W95 Ext'd (LBA)
/dev/hda3 7704 9729 16273845 83 Linux
/dev/hda5 5368 7608 18000801 7 HPFS/NTFS
/dev/hda6 7609 7703 763056 82 Linux swap

... so my Feisty installation is on partition hda3.

Knoppix should automatically mount the Linux partition and in my case /dev/hda3 was mounted to /mnt/hda3. If Knoppix hasn't mounted the drive, then use something like mount /dev/hda3 mnt/hda3 (although your device names/numbers or mount points may differ).

Finally I ran the following command to repair GRUB....

grub-install --root-directory=/mnt/hda3 --recheck /dev/hda

I gave it a reboot and was treated to the wonderful sight of GRUB appearing and offering me a choice of Ubuntu or XP again.

Did the information on this page help you? If so, please help to fund this site by clicking one of our sponsored ads...