technology and zen of life

“A heisenbug (named after the Heisenberg Uncertainty Principle) is a computer bug that disappears or alters its characteristics when an attempt is made to study it.”

Dual-booter’s Dilemma

Do you dual-boot Windows and Linux on your computer? Then you may have faced this issue: you have a working copy of both Windows and Linux, but one fine day, when you reinstall Windows, you can no longer boot into Linux. Your PC does not give you a list of installed operating systems and ask you to pick one. What is wrong, and how can it be fixed?

Here’s what actually happened. The initial 512-byte-region of your hard-disk is called the Master Boot Record (MBR). This is the region that contains boot code, and is executed automatically at startup. Normally, in a dual-boot system, this area contains the first stage of GRUB – the GRand Unified Bootloader. When you reinstalled Windows, the setup application overwrote this code with its own, thereby forcing the system to load Windows automatically. The fix to this problem is to re-install the GRUB code in the MBR.

To do this, use a Linux setup disk to enter rescue mode. How this can be done depends on the specific flavor of Linux that you are using. For instance, with the Fedora or Redhat installer disk, you should type linux rescue at the boot prompt to enter rescue mode. In this article, we make use of the first installation disk of the Fedora distribution. The instructions will be similar (but not the same) for others.

Once you have a working shell, you can proceed with the installation. To do this, type:

# grub-install /dev/sda

Replace sda with the correct hard-disk name for your system. The command fdisk -l will list these devices. Read the footnote below for further information on using fdisk.

In an ideal scenario, that would have been it. In other cases, you may need to tweak things a little to get this command to work. If you encounter any errors, first mount your existing Linux root and boot partitions in a suitable folder. If you are using the Fedora or Redhat disk, you are asked if you want to do this automatically. Assuming you answered yes, the root partition is mounted at /mnt/sysimage and the boot partition is mounted at /mnt/sysimage/boot. To do this manually, see the footnote below.

1. If you encounter an error that says that /sbin/grub could not be found, then you should make a link to the copy of this file in the /sbin folder, by running this command:

# ln -s /mnt/sysimage/sbin/grub /sbin/

2. If the installer complains about being unable to find the root directory, then add the --root-directory=/mnt/sysimage option to the command.

# grub-install /dev/sda –root-directory=/mnt/sysimage

Using fdisk to identify your partitions

fdisk is a versatile hard-disk partitioning utility. Here, we only look at its basic partition-listing functionality.

Once you’ve booted into rescue mode, you can use the command fdisk -l to list all the partitions. If you know the size and types of the partitions on your system, you can use this information to identify your hard-disk partitions. For example:

# fdisk -l

A typical output of fdisk -l looks like this:

Device Boot Start End Blocks Id System
/dev/hda1 * 1 19377 9765976+ 7 HPFS/NTFS
/dev/hda4 19378 77545 29316672 f W95 Ext’d (LBA)
/dev/hda5 19378 20370 500440+ 82 Linux swap / Solaris
/dev/hda6 20371 39747 9765976+ 83 Linux
/dev/hda7 39748 77545 19050160+ b W95 FAT32

As you can see, /dev/hda1 is an NTFS partition, which is probably the system partition on Windows (popularly referred to as C drive). The number under the Blocks column has a direct relation to the actual size of the partition. The largest Linux partition is /dev/hda6. This is likely to be the root partition (also known as ‘/’).

Under certain configurations, there is an additional, smaller Linux partition that is used to store the boot files, such as the Linux kernel, and GRUB itself.

Once you’ve identified the root partition, mount it in an empty folder. Here, we will use the /mnt/sysimage folder.

# mount /dev/hda6 /mnt/sysimage

Check if the folder /mnt/sysimage/boot contains your boot files and the grub folder. If the folder is empty, this probably means that you have a separate /boot partition that needs to be mounted. For example, if /dev/hda3 contains your boot files, then mount this partition too.

# mount /dev/hda3 /mnt/sysimage/boot

If you are still unsure about your partitions, try mounting each partition into an empty folder and checking the contents. For example:

# mkdir /root/temp
# mount /dev/sda1 /root/temp
(If an error occurs, ignore it and go on to the next partition.)
# ls /root/temp
(Check the output to see what the folder contains.)
# umount /root/temp

Most problems go away with the application of some logical thinking. Best of luck!

Update 2007-04-17: Corrected some typos

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

5 Responses

  1. helpful stuff, thank you. myself I have just found this cool CD for booting Windows at at, testing it right now.

  2. Idetrorce says:

    very interesting, but I don’t agree with you

  3. Thanks Rohit. I will do that whenever I get the time.

  4. Rohit says:

    Hey I have a suggestion … why dont u write a blog on How to get ur videos and music goin on a RHL or Fedora Linux System….. ?

  5. Rohit says:

    NIce wrk Ramnath…… I used to face similar problems but now a master of this job… nicely xplained….

    I guess this will b vry helpful to all the new users of LINUX OS.


The views expressed on this blog are personal. We do not claim to be a representative voice of the views of any organisation whatsoever. We are not responsible for the content present on the blogs to which we have linked.Views expressed are solely that of the author and does not reflect a collective opinion of contributors.
%d bloggers like this: