Sunday, February 01, 2009

Windows 7/Vista Dual Boot with Linux; how to make it work again after you installed Windows.

I recently installed Windows 7 on my Desktop PC. I was cautious and installed it on a partition that I hardly used and had sufficient room on it. The idea was to triple boot with Vista and Linux (gOS a Ubuntu derivative).
However, after Windows 7 had installed, it was only nice enough to give the option of booting either Vista or 7. The Linux OS was completely ignored. In hindsight I should have checked on this because the web is abundant with warning about this. However, I did not have a choice anyway and in the end it was relatively easy to recover from this situation, with bits n pieces of info found on a number of blogs. Ok, so without further ado, here is the fix for prosperity:

First we'll need to make sure GRUB is installed onto the Linux partition itself.
  1. Boot with a Linux Live CD (or a normal linux install CD and use the rescue mode)
  2. Open a terminal window and enter "sudo grub"
  3. At the grub prompt, enter "root (hd0,2)". Now 0 is the harddisk nr and 2 the partition on that HD, so you need to make sure that is right in your case. You can check this from within either windows (diskpart) or in linux (fdisk).
  4. Then at the grub promt, enter "setup (hd0,2)". note that this may give an error in the last stage, something about Reiser FS. If you enter the command once more (arrow up), it will work tho. This seems to be a long time bug...
  5. Now enter "quit" to exit grub
Ok now this done, you can boot with Windows (Vista or 7) again and we're going to first make a copy of the boot sector on the Linux partition. In order to do this we'll need the program dd for windows (easily found through a google search). Or dd for Linux because the latest version available for Windows no longer runs on Windows 7 RTM.
  1. Open a cmd prompt and enter "dd --list". This will show you you a list of all partitions. You'll need to match up the \\?\DeviceHardDiskXPartitionX with the \\?\DeviceHardDiskVolumeX. If you do this on Linux of course the usual /dev/sda[nr.] notation needs to be used.
  2. Now enter "dd if=\\?\DeviceHardDiskVolume2 of=linux.boot bs= 512 count=1" (this is based on my partitioning scheme, check yours). This will create the linux.boot file (you can name it whatever you like of course).
  3. Now copy the linux.boot file (or whatever you called it) to the root of C:
  4. Now enter the following command "bcdedit /create /d "Linux" /application BOOTSECTOR”.
    It will say it created an entry with a name such as {3eaa81f2-e508-11dd-9049-806e6f6e6963}
  5. Next enter "bcdedit /set {3eaa81f2-e508-11dd-9049-806e6f6e6963} device boot". Make you enter your particular identifier here.
  6. Next enter "bcdedit /set {3eaa81f2-e508-11dd-9049-806e6f6e6963} PATH linux.boot".
  7. Next enter "bcdedit /displayorder {3eaa81f2-e508-11dd-9049-806e6f6e6963} /addlast".
  8. Finally enter "bcdedit /timeout 10". Or whatever you feel is appropriate in terms of timeout value.


Now next time you reboot Linux is the last option in the Windows boot menu.

No comments: