Windows 7 + linux dualboot using BCD instead of Grub

A few months ago I formatted my laptop and installed Windows Seven x64 RTM on it and it works great, no problems at all; my display can now power off and hibernation works (which wasn’t the case with Windows Seven x64 RC1).
Until I installed openSuse next to Windows Seven and all of a sudden it wouldn’t hibernate anymore, to me it was obvious what happened: Windows Seven needs to make some changes to the boot information but since I had Grub installed in the MBR this wouldn’t work anymore. The only solution I could think of was replacing Grub with Microsoft’s bootloader again and configuring it for dualboot.

However, BCD isn’t as easy to work with compared to the old ‘boot.ini’ method. Instead of altering a small text document using notepad, you now have to use bcdedit.exe, a command line utility (btw, there are alternatives like easybcd or bellavista, but both failed on my laptop so I had no choice but using bcdedit.exe).
I therefore decided to write a small guide. It’s more something to get you in the right direction, so you’ll need to be a little bit geeky to understand all this 😛 . Also, everything you do is at your own risk. It’s your responsibility to create backups of your data and it’s not my fault if you screw up your computer because of this guide 😀 .

Preparing Linux
You shouldn’t do much to prepare linux, just make sure that it can boot from the root partition (or the partition where /boot/ is located). I have no clue how to get this done outside openSuse 11.2 (need some Ubuntu input here), but in openSuse you should go to Yast > System > Boot Loader. Sorry that I can’t provide it for other distributions but I just don’t feel like copy-pasting some other guide from the internet 🙂 (read: Google it).

So, the first thing you need to find out is which partition is bootable. In a command prompt, type

sudo /sbin/fdisk /dev/sda

assuming you have the root password and that linux is installed on the first sata disk (for pata disk it is /dev/hda for the first and /dev/hdb for the second, etc …)
Now press ‘p’ and you should see something like this

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x20000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          10       80293+  de  Dell Utility
/dev/sda2              11        1316    10485760    7  HPFS/NTFS
/dev/sda3            6538       14594    64709632    7  HPFS/NTFS
/dev/sda4   *        1317        6537    41937682+   f  W95 Ext'd (LBA)
/dev/sda5            1317        1447     1052226   82  Linux swap / Solaris
/dev/sda6            1579        6537    39833136   83  Linux

Notice the little asterisk next to /dev/sda4, that means this is the partition you’re looking for.

Next (assuming that your Windows 7 partition (c:) is mounted as /Windows7) you should copy the boot information from this partition to your c: drive.

sudo dd if=/dev/sda4 of=/Windows7/linux.bin bs=512 count=1

That’s pretty much it 🙂 .

Preparing Windows
Again, it’s all command line here so you’ll need to open a command prompt with administrative rights. Open the start menu and type ‘cmd’ but don’t press enter yet. There is probably only one result ‘cmd.exe’, rightclick on this and select ‘Run as administrator’.
First we need to check if bcdedit works, so just type bcdedit in the command prompt and something like this should show up:


Windows Boot Manager
identifier              {bootmgr}
device                  partition=C:
path                    \bootmgr
description             Windows Boot Manager
locale                  en-US
inherit                 {globalsettings}
default                 {default}
resumeobject            {3eedabce-c752-11de-a753-b4a4c545c5c8}
displayorder            {current}
toolsdisplayorder       {memdiag}
timeout                 3

Windows Boot Loader
identifier              {current}
device                  partition=C:
path                    \Windows\system32\winload.exe
description             Windows 7
locale                  en-US
inherit                 {bootloadersettings}
recoverysequence        {3eedabd0-c752-11de-a753-b4a4c545c5c8}
recoveryenabled         Yes
testsigning             Yes
osdevice                partition=C:
systemroot              \Windows
resumeobject            {3eedabce-c752-11de-a753-b4a4c545c5c8}
nx                      OptIn

In some cases, bcdedit isn’t able to find the bootsector and you’ll need to tell the application where it can find the bootloader via the /store parameter. On my laptop, the bootloader was located in C:\Boot\BCD, thus the command should look something like

bcdedit /store c:\Boot\BCD

Now it’s time to alter the bootloader 🙂 .
To begin, we’ll start by creating an entry for our linux installation.

bcdedit /store c:\Boot\BCD /create /d “enter name of linux here” /application BOOTSECTOR

This command will return a guid for this entry, it’s a unique identifier and you’ll need it througout this small guid, so don’t loose it wink . In my case it return {4c05bddc-df6e-11de-8b3c-0019b95ad51c}, but I’ll refer to it as {ID} for simplicity (don’t forget the {} !).

Now we need to tell on which partition we’ve stored the linux.bin file, in my case it was on the c: drive.

bcdedit /store c:\Boot\BCD /set {ID} device partition=c:

Next we need to locate the path to the file, if it’s c:\linux.bin, you just need to say \linux.bin.

bcdedit /store c:\Boot\BCD /set {ID}  path \linux.bin

Okay, now that we have configured the entry we only have to add it to the menu

bcdedit /store c:\Boot\BCD /displayorder {ID} /addlast

This will add the linux entry as the last entry in the list, you can also use /addfirst if you want linux on top of the list =) .

If you’d like, you can alter the timeout (the value is in seconds)

bcdedit /store c:\Boot\BCD /timeout 30

And if you want the change the default os:

bcdedit /store c:\Boot\BCD /default {ID}

That’s it for now 😀 . Now it’s time to reboot. Don’t be surprised if Grub appears, this is normal because we haven’t replaced it yet. However, select Windows in Grub and you’ll notice that instead of the fancy windows logo you’re now presented with a (fugly) list with the option to boot Windows 7 or Linux. If you choose linux you’ll get back to Grub, if you choose windows, it’ll start Windows, can’t be more straightforward 🙂 .
If you choose linux and you get a black screen and nothing happens, then you’ve copied the wrong data from the wrong disk in the first step (Preparing Linux). Repeat this step until everything works as it should. You can just overwrite linux.bin without having to reconfigure BCD 🙂 .

Replacing the MBR
This is maybe the most easy step. Insert you Windows 7 DVD and boot from it, select your language and input and press next. In the next screen click on the link that says that you want to repair your computer.
The following step might be a bit confusing tough. You’ll get the option to select the operating system you want to repair, but the list is empty, don’t worry, this is normal (and stupid). If you’re sure you don’t need to load and SATA drivers, just click next (otherwise choose the second option, load the drivers and continue).
And than, the final step … just click the button that says you want to fix boot problems, wait a bit et voila, BCD is in the MBR.

//edit: okay, today I noticed that the automatic boot repair doesn’t work anymore. Now, don’t worry, there is another way. Instead of clicking on the “fix boot problems” button, click on the command prompt button. There you execute following commands:

bootsect /nt60 all /mbr /force

This is the fixmbr alternative for Windows 7 😉 .

Happy dualbooting :mrgreen:

ps: more info on bcdedit can be found here:

This post was originally posted on my My.Opera blog on Thursday, December 3, 2009 9:18:05 AM. This post has been copied to my WordPress blog since the My.Opera blogging service will be discontinued.


5 thoughts on “Windows 7 + linux dualboot using BCD instead of Grub

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s