-- MikeGore - 14 Dec 2012

GRUB2 and Windows 7 Dual Booting


  • Windows 7 likes to overwrite the MBR - Master Boot Record so it stomps on the GRUB2 boot loader
  • Solution: We Use Windows to boot GRUB2 - and let GRUB2 boot Linux.
    • To do this we install GRUB2 in the PBR - Partition Boot Record - NOT the MBR as before


  • This is just a basic formula - partitioning is up to you
    • Install Windows first because once installed it has hard coded references to its parition all over the place - registry and in files*
    • Linux can me moved around later with just changes to grub and fstab
  • Example
    1. Install Windows 7 using half the disk
    2. Install Ubuntu and SWAP using the remainder of disk
      • Make sure that you install GRUB2 in the Linux Partition and NOT in the MBR
        • Ignore the warning the GRUB2] gives!
    3. While still in Linux, but after the GRUB2 setup do the following steps. ( If you missed this step then boot RIP via the network or via CD)
      • sudo bash - become root
      • fdisk -l
        • note the Windows Partition - assume /dev/sda2 for this example
        • note the Linux Partition - assume /dev/sda5 for this example
      • Next we get a copy of the PBR for GRUB2 and Linux
        • mount /dev/sda2 /mnt - we mount the Windows Partition
        • dd if=/dev/sda5 of=/mnt/linux.bin bs=512 count=1 - Grab the PBR
        • umount /dev/sda2 - unmount the Windows Partition
      • Next we have to update the Windows Boot Menu - see the next section

Windows 7 Boot Menu Editing

  1. Boot the Windows Boot CD
  2. Proceed to the Command Prompt of the Recovery Environment (it will do some diagnostics first)
  3. There are three parts to a boot menu entry:
    1. Application Drive
    2. Application Path
    3. Description
  4. Note about drive letters
    1. When assigning drive letters in the recovery console you will use D: to refer to C: - yes it is confusing!
  5. Note: We are going to add D:\linux.bin to the boot menu
    • (really it is C:\linux.bin at boot time)
    • We have already saved linux.bin under D:\ previously as /dev/sda2 ( C:\ at boot time! )
  6. Type the following commands
    • bcdedit /create /d "Linux" /application BOOTSECTOR
      • This will return a string enclosed in {} you need to copy this
        • ALT SPACE -> Edit -> Copy -> Highlight the string including the {}
    • bcdedit /set {the string you copied} device partition=D: (Note: we use D: for C: here)
    • bcdedit /set {the string you copied} path \linux.bin
    • bcdedit /displayorder {the string you copied} /addlast
  7. Verify
    • bcdedit /enum - will list your partitions

List BCD

  • bcdedit /enum

Fixing Broken MBR

  • bootrec.exe /FixMbr

Fixing Broken Windows 7 Boot Menus

  • References
  1. Backup existing BCD
  2. Boot the Windows Boot CD
  3. Proceed to the Command Prompt of the Recovery Environment
  4. Backup BCD
    • bcdedit /export c:\bcdbackup
    • attrib c:\boot\bcd -h -r -s
    • ren c:\boot\bcd bcd.old
    • bootrec /rebuildbcd
  5. Add any additional boot menus you needed

Old Obsolete notes

  • Windows 7 now overwrites part of GRUB2 - so GRUB2 cannot be used to boot
    • see ST#75001 and ST#73845
Wed, Nov 3 2010 13:28          psamsono          created the request
The Windows 7 bootloader conflicts with [[CF.GRUB2][GRUB2]]. In order to dual-boot Windows 7 and Ubuntu, the following steps must be taken (See RT 73845)
  • Using the Windows 7 bootloader instead of GRUB2
  1. Install Windows.
  2. Install Ubuntu.
  3. Boot into Ubuntu.
  4. Run gparted to see what partition numbers your Windows and Linux partitions got. In my case, Windows uses /dev/sda3 and Ubuntu uses /dev/sda1
  5. Ubuntu installs GRUB2 to the MBR by default, with no option to install it to a partition. In this case, GRUB2 needs to be at the root of the Linux partition, since it needs to be extracted. Run the following command:
    • grub-setup --force /dev/sda1
      • You will get some warnings, but that's fine.
  6. Mount the Windows partition
    • mkdir -p /mount/windows
    • mount /dev/sda3 /mount/windows
  7. Copy over the boot record
    • dd if=/dev/sda3 of=/mount/windows/linux.bin bs=512 count=1
    • You might want to open that file with a hex editor to ensure that data actually copied over. If the file is empty, GRUB2 did not install to the root partition. Retry step 5.
  8. Boot into Windows 7. Check that a linux.bin file exists at the root of your C drive.
  9. Open the command prompt as an administrator. To do that, open the start menu, type "cmd", but don't press Enter. Right click on the cmd program that came up in the menu and select "Run as Administrator".
  10. Create a Linux entry in the boot menu:
    • bcdedit /create /d "Linux" /application BOOTSECTOR > c:\bootID.txt
    • The file c:\bootID.txt now contains the unique ID for that boot option. It is fairly long, so this ensures that you do not type it incorrectly.
  11. Configure that entry using the following commands:
    • bcdedit /set {LinuxID} device partition=c:
    • bcdedit /set {LinuxID} PATH \linux.bin
    • bcdedit /displayorder {LinuxID} /addlast
    • bcdedit /timeout 5
    • Where {LinuxID} is the ID string you got in step 10. The ID string must be enclosed in braces ({}) for the command to work.
    • Notes:
      • An option called Linux will be added to the boot menu. When you select Windows 7 in GRUB2, or boot to it by default, this menu will be shown. Choosing the Linux option opens GRUB2. It is possible to switch between GRUB and the Windows bootloader indefinitely.
      • When these steps are performed, GRUB2 still remains the default bootloader.
  • Further modifications to the boot sequence:
    • To make the Windows bootloader the default one, boot up the Windows 7 install disk.
      • Go into the recovery menu and open the console.
      • Enter bootrec /fixmbr
        • The Windows bootloader now gets written into the MBR. Do not do this before you extracted the GRUB2 UUID string from the root partition, since you will not be able to boot into Ubuntu.
    • Changing the timeout value to 1 second in the /etc/default/grub file and running grub-mkconfig -o /boot/grub/grub.cfg does work, despite GRUB being installed in a different location.
  • Problems:
    • However, Ghost can't handle this image. Regardless of the -nolilo switch, both Windows 7 and Linux fail to boot with a 0xc0000225 error.
      • With Acronis, both fail to boot with a 0xc000000e error. Googling suggests that there is no concrete fix for the former, aside from manually recovering every system imaged, but the latter is caused by imaging a smaller disk to a larger disk. I am in the process of installing Ubuntu and Windows 7 on the 500GB disk on the Golden Master to see if this will fix the problem.
    • Testing recorded in this RT https://www.cs.uwaterloo.ca/cscf/internal/request/UpdateRequest?74825 shows that removing the hard drive from the Golden Master and using it on another machine directly works fine. That RT also contains Acronis licensing information.
Wed, Nov 3 2010 13:28          psamsono          set Owner to "psamsono pbedlows"
Wed, Nov 3 2010 13:28          psamsono          set Responsible to "pbedlows"
Wed, Nov 3 2010 13:33          psamsono          commented
The second hard drive on the Golden master will have the following partitions:

200GB ext4 Ubuntu partition
4GB swap space
100MB Windows 7 boot partition
~300GB NTFS Windows 7 partition

I will also experiment with taking an image of one of the ASRock boxes and applying it on the other one.
Wed, Nov 3 2010 13:34          dkeenan          changed Responsible to "pbeldows" from "pbedlows"
Wed, Nov 3 2010 13:34          dkeenan          changed Owner to "psamsono pbeldows" from "psamsono pbedlows"
Wed, Nov 3 2010 14:37          psamsono          commented
Acronis needs to map each partition in the image to a partition on the disk. Since the bootable media seems to lack any sort of proper partitioning tool, it would be easier to destroy the partition table by removing the first 524 288 bytes of the disk (bs=512 count=1024) using dd. In this case, Acronis is able to create partitions of the correct size.
Wed, Nov 3 2010 14:47          psamsono          commented
The backup process on the ASRock only created a 10GB file. Booting into Linux only gives a black screen and a flashing cursor. Booting into Windows 7 works perfectly fine.
Wed, Nov 3 2010 15:25          psamsono          commented
Imaging the backup from the ASRock onto one of the larger machines resulted in a perfectly bootable Linux install, somehow, even though I did enable the option for possibly different hardware on the ASRock, but not on the large machine. I will investigate this further. 
Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r9 - 2013-12-02 - MikeGore
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback