I managed to lock myself out of my Dell Inpiron 8600 again. Here's the story of how I fixed it.

My Dell laptop is dual booted with Windows XP and Fedora Core 3 (FC3) Linux. The partions on the main disk were:

/dev/hda1 = some partition for Windows
/dev/hda2 = the main NTFS partition for Windows
/dev/hda3 = another(?) partition for Windows
/dev/hda4 = extended partition to hold the remaining 'virtual' partitions
/dev/hda5 = the root (/) partition
/dev/hda6 = /home partition
/dev/hda7 = /usr/local partition
/dev/hda8 = /opt
/dev/hda9 = Linux swap


I decided I'd like to have an extra vfat (FAT32) Windows partition in the middle somewhere that could be mounted from Linux and available as another drive on Windows. This would be a nice way to share data easily between the two halves without having to mount an external drive or mount the NTFS partition as read-write.

Using Partition Magic I resized the /dev/hda2 (C: drive) partition to free up 1GB, formatted as FAT32. After a reboot the changes were made, and all was looking good. Once the changes finished, another reboot would bring me back to test the system. Here's where the problem occurred.

I should have thought about it ahead of time. Adding a new partition in the middle pushed all the later device numbers up by one. So the VFAT was now /dev/hda3, displacing the device numbers as:

/dev/hda1 = some partition for Windows
/dev/hda2 = the main NTFS partition for Windows
/dev/hda3 = new FAT32/vfat partition for sharing between OSes
/dev/hda4 = extended partition to hold the
/dev/hda5 = another(?) partition for Windows remaining 'virtual' partitions
/dev/hda6 = the root (/) partition
/dev/hda7 = /home partition
/dev/hda8 = /usr/local partition
/dev/hda9 = /opt
/dev/hda10 = Linux swap


As you see, the root (/) partition went from /dev/hda5 to /dev/hda6. The root partition holds the /boot/ directory from which grub launches and from which Linux is booted. Upon the reboot, instead of the familiar Grub menu options all I got was a black screen with a grub> prompt. Withouot a menu to choose from I was stuck... for a while.

I decided to insert a Knoppix 3.3 Live CD, and then boot from it. Live CDs provide a completely bootable system where the guest OS runs off the CD itself instead of the hard drive, and it provides read (and possibly write) access to all file systems on the machine. With Knoppix loaded, I was able to mount /dev/hda6 to find my /boot/grub/grub.conf configuration file. From this I wrote down the boot parameters for Linux and for Windows.

After removing the Knoppix CD, I rebooted and got the grub> prompt back again. Here I entered each of the following lines, one at a time followed by hitting the Return key:

root (hd0,5)
kernel /boot/vmlinux-(version) ro root=LABEL=/ rhgb
initrd /boot/initrd-(version).img
boot


Upon hitting Return after the boot command, the system correctly began the boot sequence to bring up Fedora Linux.

You see, the problem is that the Master Boot Record (MBR) still contained a reference to the grub menu and splashscreen on the (hd0,4) partition which translates to /dev/hda5. The new partition bumped the bootable partition up to /dev/hda6 so I had to edit grub.conf (hd0,5) to indicate the 6th partition (partitions start at 0). The MBR was pointing to the wrong place.

Instead of going through all the trouble to start up Knoppix and examine the file system to find out where my bootable partition was, I could have just issued the find command at the grub prompt to discover that I could boot from (hd0,5) such as:

grub> find /boot/grub/stage1
(hd0,5)


So now I was booted in Linux again, but I had to fix the missing grub menu or I'd have to always enter boot commands when ever I started up. I decided to reinstall grub on the MBR using the command:

/sbin/grub-install /dev/hda
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.

(hd0) /dev/hda


A final reboot and there was the familiar grub menu again with the Fedora splash screen. All was well. Linux and Windows booted as normal, and the whole file system was intact. Now I had my hard-worked-for E: drive acting as a shared FAT32 partition, writable by both Linux and Windows.

Don't let this happen to you! Check out this nice tutorial on using grub at the commandline, found here: http://www.desktop-linux.net/grub.htm