06/05/2010

Dual boot Windows 7 64bit and OpenSuSE 11.1 Linux - GRUB magic

After having installed OpenSuSE 11.1 on my office machine quite a long time ago and found, that Windows 7 was not bootable any more I simply repaired the boot by using the Windows 7 Installation DVD and forgot about Linux on that machine. A few days ago the necessity of having Linux as well showed up again and I wanted to integrate both systems into GRUB, which for whatever reason failed. (I guess it is due to the 64bit Version which in my case added an invisible boot partition of roughly 100 MB as first partition on the hard drive.) I finally ended up integrating GRUB into the Windows Boot Loader using mainly this entry (thanks and credits to the author!) which I will fine tune and enrich with additional information in the following:

What you should have ready:
  • A live-linux cd or dvd of your choice containing the version of GRUB you have on your system. I prefer Xubuntu 8.10
  • The Windows 7 installation DVD, 32bit or 64bit depending on your OS.
  • Windows and Linux installed
  • A USB stick or write-access to one windows-readable partition within your Linux installation
How to reinstall grub
Normally, you will have installed Windows first, then Linux and then have repaired your Windows Boot using the Automatic Repair of your Windows 7 installation DVD, which means, you cannot access your Linux any more. Therefore you will need to reinstall GRUB.

  • Boot the live-linux of your choice
  • Open a console and become root (according to the live-linux distro)
  • Cast grub on the console and you will get
    grub>
    You are in the "interactive mode" of grub.
  • Find the partition where GRUB resides by casting find /boot/grub/stage1 to grub - you will get something like:
    grub> find /boot/grub/stage1
    (hd0,5)
    grub>
  • Tell grub to take the partition (in my case (hd0,5) ) as root partition, install the boot loader and quit afterwards:
    grub>root (hd0,5)
    grub>setup (hd0,5)
    grub>quit
  • After successful isntall you can restart and boot into your Linux system.

Great, Linux starts and Windows 7 will, if you had an entry for it in your GRUB menu, tell you "BOOTMGR missing" if you try booting into it.

To include GRUB into the Windows 7 boot loader, it has to be installed in the root partition of your Linux installation:
  • boot into your installed Linux (if not already done so) and open a root console
  • find the partition where your Linux resides using fdisk -l. The response will look somewhat like /dev/sda5.
  • install grub into that partition with the command
    grub-install /dev/sda5
    (change the /dev/section to meet your output.) There might be minor errors which are marked "non fatal". You should get a successfully installed message in the end.
  • Export the Linux boot sector using (again change /dev/sda5 to the device where your Linux resides):
    dd if=/dev/sda5 of=/tmp/linux.bin bs=512 count=1
    and copy the file /tmp/linux.bin to a location which you can access via Windows 7
    cp /tmp/linux.bin /yourmountpoint/

Now you need to get back the access for Windows: boot with your Windows 7 installation DVD, choose: "install now" --> "Choose language" --> "Use Recovery Tools" "Startup repair" and restart. If your Windows 7 doesn't start however, boot again with your Windows 7 DVD, choose: "install now" --> "Choose language" --> "Use Recovery Tools" --> "cancel" --> "Command Prompt", navigate to the root directory of your DVD and cast the command: bootsect /nt60 SYS /mbr. After that, restart your computer, and you should be able to boot into Windows 7 as usual.

Add Linux to the Windows Boot loader
  • boot into your Windows 7 installation, if not already done so
  • copy linux.bin created before into the root directory of your Windows installation (normally C:\)
  • start a command prompt with administrative rights: to do so, click start, type cmd into the start text field, DON'T press RETURN, but press CTRL+SHIFT+RETURN.
  • in the command prompt cast bcdedit /create /d "GRUB" /application BOOTSECTOR This will give you back an SID like {63ea1432-234ff-44da-bd24-ceb4e3230e14} which I refer to as {yourSID}
  • cast bcdedit /set {youSID} device boot - which sets the destination of the Linux boot
  • cast bcdedit /set {yourSID} PATH \linux.bin - which sets the path for the destination
  • cast bcdedit /displayorder {yourSID} /addlast which sets the menu entry
  • optionally, set the waiting time using bcdedit /timeout 15 or whatever waiting time you want.
A reboot should offer you a booting choice of either Windows 7 or the Linux GRUB.

Side note: this should work for almost any Linux distribution out there, which uses GRUB as boot loader.

No comments: