Using the Windows boot manager

One of the options for booting linux is to use the Windows boot manager, which is part of recent versions of Windows.

The use of the Windows boot manager does not replace grub or lilo.  You still need a way to load the linux operating system.  The Windows boot manager provides an alternative place where you can select the desired operating system from a menu.

If you are installing linux for the first time, I recommend that you use the defaults, which will probably set grub as the boot manager for choosing your system.  Don’t even think about using the Windows boot manager at initial install.  That’s because it takes a bit of effort to set it up, so it is better to get linux up and running first.  You can switch over to using the Windows boot manager at a later time, should you so choose.

In my case, when I first installed linux on this computer, I went with grub.  I later made it possible to use the Windows boot manager.  So it depends on which partition I set as active in the partition table.  If I set the Windows partition as active, then the system will boot to the Windows boot manager and I can select linux from there if I prefer.  If I set the appropriate linux partition (in my case, the one for “/boot”) as active, then the system boots straight into the grub menu and I can select Windows from there if I prefer.

There’s actually an advantage to setting up the Windows boot manager, even for Windows users.  When booting Windows, you can hit F8 to get additional boot options.  But, with modern computers, the system may boot before you have time for that.  Using the boot manager as a selector gives you a little more time to hit F8.

This post is mostly about how to setup the Windows boot manager for booting linux.

The linux boot sector

In order to use the Windows boot manager, you will need to have a copy of the linux boot sector in a file.  This will show how to create a file “bootsect.lnx” containing the linux boot sector.

You first need to know which partition it is.  One way is to run the command

# fdisk -l /dev/sda

You would run that as root.  Here’s the kind of output you might see:

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63      208844      104391   83  Linux
/dev/sda2          208845    39294989    19543072+   7  HPFS/NTFS/exFAT
/dev/sda3        39294990   136970189    48837600    7  HPFS/NTFS/exFAT
/dev/sda4       136970190   625137344   244083577+   f  W95 Ext'd (LBA)
/dev/sda5       136970253   141066764     2048256    7  HPFS/NTFS/exFAT
/dev/sda6       141068813   141478412      204800   83  Linux
/dev/sda7       141480461   361681420   110100480   8e  Linux LVM
/dev/sda8       361683469   372169228     5242880   82  Linux swap / Solaris
/dev/sda9       372171277   414114316    20971520   83  Linux
/dev/sda10      414116365   424602124     5242880   83  Linux

Note the “*” in the boot column for “/dev/sda1”.  If your system boots straight into linux or the grub menu, then there’s a good chance that the “*” marks the partition with the linux partition boot record.  So you would use “/dev/sda1” for the boot sector.  If you installed grub in the MBR, you would normally use “/dev/sda” as the boot sector.  But you might not even want to setup the Windows boot manager in that case.

Having found the partition with the boot sector then, as root, cd to a partition where you want to save the boot sector to a file.  That would normally be the Windows main directory, though it could also be a USB if you prefer to first save the boot sector there.

Next, use the command:

# dd if=/dev/sda1 of=bootsect.lnx count=1

This assumes that the boot sector is in “/dev/sda1”. Change that, as appropriate.

Here “dd” is a data copying command.  It copies from the input file to the output file.  The argument “if=/dev/sda1” identifies the input file.  And “of=bootsect.lnx” identifies the output file.  The “count=1” is important, and says that only one sector should be copied.  The resulting output file should be of length 512.  If you happen to have a non-standard disk with a sector size of 1024, then add “bs=1024” as an additional parameter on that command line.

We now have the boot sector in a file.  The next step depends on whether we are using older Windows versions (Win2K or WinXP), or newer versions (Windows 7 or Vista).

Windows 2K and Windows XP

For Win2K and WinXP, you will need to edit the file “boot.ini” on your Windows partition.  If you do that in Windows, you will find that the file is hidden.  So you may need to run:

attrib -rhs \boot.ini

before you can access that file.  Then, simply add a line at the bottom:

C:\bootsect.lnx="linux"

and you are set.    This assumes that “C:” is your main windows drive.  The path given should be the path to the “bootsect.lnx” file.  The quoted word “linux” will be used as the prompt in the Windows boot manager.  You can change that prompt as desired.  Make sure that you use a plain text editor.  Do not use MSWORD for editing this file.

If you prefer to edit the file in linux, that can work too.  But there’s a risk.  The linux editors use a different way of marking the end of a line.  So don’t edit in linux unless you know how to add a Windows line ending.

Vista and Windows 7

To add an entry to the Windows boot manager in Vista or Windows 7, you will need to use the command BCDEDIT in a command prompt.  Start that command prompt with “run as Administrator”.  But we are getting ahead of ourselves.  If your system is set to boot directly into linux, you won’t be able to do this.  So, the first thing you will need to do is get into “fdisk” on linux, and change the active partition to the Windows partition.  With the partition table shown above, I would use:

# fdisk /dev/sda
p
a1
a3
p
w

That removes the active flag from partition 1 and adds it to partition 3, then saves the result.  Next, boot to Windows.  The system should boot straight into Windows.

With the system booting into Windows, you can now use BCDEDIT.

Here’s what I did on one of my systems:

C:\Windows\system32>bcdedit /create /d "linux" /application BOOTSECTOR
The entry {d2b935e1-30de-11e1-96ce-d17cd8616f47} was successfully created.
C:\Windows\system32>bcdedit /set {d2b935e1-30de-11e1-96ce-d17cd8616f47} device boot
The operation completed successfully.
C:\Windows\system32>bcdedit /set {d2b935e1-30de-11e1-96ce-d17cd8616f47} PATH \bootsect.lnx
The operation completed successfully.

C:\Windows\system32>bcdedit /displayorder {d2b935e1-30de-11e1-96ce-d17cd8616f47} /addlast

C:\Windows\system32>bcdedit /timeout 30
The operation completed successfully.

Let’s go through those steps.

The first of those commands adds an entry to the boot configuration data, to be used with a boot sector.  The response indicates that the ID for that data is “{d2b935e1-30de-11e1-96ce-d17cd8616f47}”.  You will see a different ID.  Whatever ID is displayed, that is what you will need to use in subsequent commands.  The quoted word “linux” will be the prompt used – change as desired.

The next command indicates that the file containing the boot sector is on the boot device.  The following command gives the name for the file containing the boot sector.  And, finally, the last command adds an entry to the boot menu (as the last entry).

That’s it.  When you next boot your system, it should boot into the Windows boot manager.  You can select the “linux” entry to boot linux, and get to the grub menu.  From within linux, you can now use “fdisk” if you wish to restore the active flag to the linux partition.  That way you will normally boot to grub.  Or, leave it as it is to normally boot to the Windows boot manager.  That’s your choice.

Advertisements

Tags:

About Neil Rickert

Retired mathematician and computer scientist who dabbles in cognitive science.

6 responses to “Using the Windows boot manager”

  1. maarten says :

    Hm. Thanks for your good intentions, but I followed your description for XP. Asterisk comes where it is in your output example: /dev/sda1 *
    But after modifying the boot.ini file, also according to your instructions, I still get the GRUB boot menu. Then, when I choose to boot into Windows XP, I subsequently get the Windows boot menu, showing the option to either boot into XP or Ubuntu (so when I want to go to windows, I get two boot menu’s: first GRUB, then the other one). When I choose Ubuntu from the GRUB menu, I immediately go to Ubuntu. Any help would be really appreciated.

    Like

    • Neil Rickert says :

      I forgot to mention that possibility.

      It looks as if grub is installed in the MBR of your disk. So everything goes through grub, no matter what.

      This is not so easy to deal with, because your grub install probably depends on it being in that location. You would need to install grub elsewhere, such as in the root partition, and then you would need to restore the generic boot code to the MBR (such as Windows puts there). It’s hard to do that without making your system unbootable to linux or to Windows (or perhaps to both).

      Like

      • maarten says :

        Thanks for your answer. In the meantime, I fixed the old MBR (fortunately, I had a backup 😉 and then used the procedure that you actually advised against. I’m not saying this method is safe or full-proof, but it worked really well for me, and it prevented the original MBR from being overwritten (again). I’ll describe it here, as an alternative for newbies like me (if it’s ok with you ;).

        After booting from the Ubuntu live-USB, I selected “something different”, subsequently created the swap partition and the Ubuntu partition (I chose primary partition and ext4 as filesystem). Then, before proceeding, at the bottom of the same menu, I selected the Ubuntu partition from the drop-down menu that specifies where GRUB must be installed (in my case that was /dev/sda2, but this could be different for someone else). Note that it is really important to make sure that you select the correct (Ubuntu) partition for GRUB at this point, before proceeding. Directly after installing Ubuntu this way, your system will not see GRUB, so you cannot yet boot into your newly installed Ubuntu. I used the procedure from the following page to copy the GRUB file from the UBUNTU partition to my C:\ drive in Windows:
        http://www.supergrubdisk.org/wiki/Howto_Boot_Grub_from_windows
        (directly below “Classical Final Solution” and directly above “Windows XP/Windows 2000/NT/Windows”). Essentially, it works the same as described on this page, only, you will need to boot Ubuntu once from your live-USB to access your Ubuntu partition (/dev/sda2 in my case), in order to get a copy of the GRUB boot sector. After that, I further followed the instructions on this page, to place the copy on the C:\ drive in Windows and edit the boot.ini file. Note that you can also make the Windows system files visible by making changes in “View” under “Folder-options”. Now, when I start my system, the Windows boot-menu will let me choose XP or Linux. When I choose Linux, I will be redirected to the GRUB menu, where I can start Ubuntu. I guess it would be possible to edit the GRUB menu, so that GRUB will immediately start Ubuntu, but I don’t feel the need for that.

        Like

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: