Adding Linux to the Windows7 boot menu

When I create a Windows / Linux dual-boot computer I usually add Windows as an option to my LILO boot menu. That is the easiest way, and works always.

However, I ran into a situation where I could not use LILO as the primary boot loader and I had to look into the Windows7 “boot configuration data” or BCD. Actually it was Windows Vista, not Windows7, which was the first to abandon good old C:\boot.ini and start writing its bootloader configuration into a binary block of data. I wrote this post just to have this procedure available as a reference.

Windows7 contains the command-line program BCDedit which you are supposed to use for editing your Windows boot menu. A total load of crock it is. It will not support any OS that does not boot from the same hard disk that Windows7 is installed to… so I had some issues getting my Slackware added to the Windows boot menu because I had installed it on a second hard disk.

In the end I decided to shrink the Windows partition a little bit and add a small Linux partition where I could install LILO.

Microsoft has added a basic partition manager to Windows7 – something they do more often. If a 3rd party creates an invaluable add-on to provide functionality Microsoft did not include into Windows, then Microsoft will eventually copy its basic functionality into a half-hearted clone. Anyway, the freed-up hard disk space was allocated to a small partition which became Slackware’s “/boot” and I installed LILO to that /boot partition.

Then, just like in the days of Windows NT and “c:\boot.ini”, I extracted the first 512 bytes from the root sector of that /boot partition (in my case, that partition was “/dev/sda3“) and wrote it to a USB stick which I had mounted on “/mnt/hd“:

dd if=/dev/sda3 of=/mnt/hd/linux.bin bs=512 count=1

Rebooted to Windows7 and transfered that 512 byte file called “linux.bin” from the USB stick to the root of the Windows C: drive.

Next, I used BCDedit to add an entry to Windows7’s BCD store. Note that administrative privileges are required to use BCDedit!. What you do is navigate to “Start->All Programs->Accessories“, Right-click on “Command Prompt” and select “Run as administrator“.

In this command window, enter the BCDedit commands. Start by creating an entry for Slackware Linux. I use “Linux” as the label for the boot menu. The actual label you choose is arbitrary of course:

bcdedit /create /d “Linux” /application BOOTSECTOR

BCDedit will return an alphanumeric identifier for this entry. Copy that string into a text file and do not lose it!

In the remainder of this article I will refer to this string as {ID}. You would replace {ID} with the actual identifier as returned by the command you ran. An example of what you can get for an {ID} is {244ebca6-432f-11df-ab86-ce0c22f636af}.

The next step will be to specify which partition holds the copy of the Linux boot loader sector (our “linux.bin” file):

bcdedit /set {ID} device partition=c:

Then specify the actual path to the “linux.bin” file on that C: drive:

bcdedit /set {ID}  path \linux.bin

The Windows boot menu needs an entry for our Slackware Linux OS:

bcdedit /displayorder {ID} /addlast

Usually you won’t see the boot menu at all (after all, it does not contain any other entry than Windows7 itself). In order to allow the user of the computer some reflection time, we add a delay to the menu’s display timeout. Say, the boot menu should remain visible for 30 seconds before booting into the default selection:

bcdedit /timeout 30

That would be all. You can test the new Windows boot menu by rebooting the computer. You should be able to select either Windows7 (default) or Linux to boot into. When you choose “Linux”, you’ll be taken to Slackware’s familiar LILO menu.

If at any time you would have to remove the “Linux” menu option, you can run the following command … provided you wrote the {ID} string down somewhere:

bcdedit /delete {ID}

Have fun, even with Windows,

Eric

30 thoughts on “Adding Linux to the Windows7 boot menu

  1. This was already tricky to do that with MS Windows XP, I hope to never need to do that with the actual Microsoft system… Anyway it’s still good to know, just in case.

    Thanks a lot for this documentation!






  2. bonjour Mr eric
    first excuse my english
    well a have the same case that you discribe in this post,
    and i a apply all the commandes successfully , then i reboot
    it good i have 2 choises windows and linux ; but when i click linux i have just black screen that all
    i need u help
    thanks


  3. Hi Khalid

    It looks like one of two possibilities:

    (1) you did not successfully copy the first 512 bytes of your linux boot sector into a file and to the C: partition of your Windows installation. or

    (2) You copied the first 512 bytes of your linux bootsector successfully, but you never checked if your Linux installation was bootable at all.

    If those 512 bytes copied out of the Linux bootsector have to boot your Linux from the Windows menu, then Linux must be able to boot too. Did you use LILO, or GRUB to setup your bootsector in Linux? Both should work.

    Eric


  4. hello eric
    i use lilo
    i installed /boot in /dev/sda4 and lilo there too i think, with lilo expet but iam not an expert!
    then i rundd if=/dev/sda4 of=/media/disk/linux.bin bs=512 count=1
    hereis my df

    khalid@libre ~> df
    Filesystem Type Size Used Avail Use% Mounted on
    /dev/root ext4 97G 11G 81G 12% /
    /dev/sdb3 ext4 231G 448M 219G 1% /home
    /dev/sda4 ext4 1.4G 48M 1.3G 4% /boot
    /dev/sda2 fuseblk 280G 53G 227G 19% /winc
    /dev/sda3 fuseblk 393G 99M 393G 1% /wind
    /dev/sdb2 fuseblk 350G 60G 290G 18% /winf
    tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
    ~
    root is on /dev/sdb1
    and there is another windows partition recovery on sda1
    thats it
    thanks Mr eric for your reactivity



  5. Khalid,

    I’m gonna take a shot in the dark here. I recently ran into a minor snag when trying to install windows XP on an acer netbook. That notebook also had a windows recovery partition, and whenever I tried to load anything other than windows 7 off that drive, it would start windows recovery automatically. I had to remove the partition before I was able to finish the windows XP installation. Is there any way that your recovery partition might be interfering similarly?


  6. Pingback: Can't boot Windows 7 after Slackware install

  7. Hello Eric!

    I used the same way to multiboot for many years.
    It is “finger braking” but it works. Creating 1 sector long file (lilo boot
    sector) and copy it to windows boot partition every time lilo.conf changed
    was my nightmare.

    So I was forced to find another solution.
    The result was brilliant and free GAG: http://gag.sourceforge.net/

    It has some excellent features I need – hides all primary partitions
    except the boot one. So I could install many windows OSes all with boot
    disk C: (each on other primary partition)
    The physical boot disk is not an issue any more. You can boot from any
    physical or logical disk as long as disk with GAG is present.

    For me GAG is magic boot loader.

    Linux: after executing lilo (writing new boot sector) all is done, just
    reboot to use new lilo configuration.

    Try it, it is real time saver.

    Regrads

    Zdenko


  8. Hi

    Just tried this instruction on my notebook HP Compaq 6720S. I have just installed Slackware64 13.37 side-by-side Windows 8, and now observing very weird behaviour, and don’t know whether it is intended to be because of Windows loader, or it is my notebook’s tricks:
    turned on notebook power. after boot device selection it show black screen a little, then it show windows booting screen(windows flag-log+running progress bar). then it suddenly shows boot loader menu where I can select linux. If I do select windows, it almost instantly load windows. When I select Linux – I observer black screen again(for ten second or like) and, surprise, my notebook reboots. After POST screen and boot device selection, it almost instantly loads into boot screen of Lilo and I finally can choose kernel to load.
    Is this normal for Windows (visra/7/8) bootloader to load windows and only then show bootmenu(and then reboot system Windwos cannot unload itself)? Or it is just trick of my notebook?

    PS. It worth to mention that after user updates lilo on boot partition he must update linux.bin too.


  9. Pingback: Booting Slackware 14 with UEFI and GPT

  10. The part that I’m not clear on is the lilo part.
    I have a win8 system where win8 was already installed so slack is on sda6. Do I use the /boot/boot.008 file? I had initially installed XFS but there was no boot loader
    in /dev/sda6 I reinstalled with ext3 but still not working.

    I did this to run lilo after slack14 install
    mkdir /sl14
    mount /dev/sda6 /sl14
    mount –bind /proc /sl14/proc
    mount –bind /dev /sl14/dev
    mount –bind /sys /sl14/sys
    chroot /sl14
    vi /etc/lilo.conf
    lilo -v

    Thanks for the tips here.


  11. I should say that after reinstall and using ext3 I did dd if=/dev/sda6 of=/usb/linux.bin bs=512 count=1



  12. Pingback: Dual boot with separated disks and Windows 7

  13. Pingback: Dual Boot

  14. Pingback: Newbie Interested in installing Slackware, questions

  15. Hello!

    As of March 21, 2012 at 15:46 above:
    All problems with multiboot (windows all versions, linux, or whatever) are elegantly solved with free GAG: http://gag.sourceforge.net/.
    This is a boot loader that installes itself in MBR of a bootable device (whatever it is). Then you have a choice to install whatever OS you want wherever you want: first physical disk, second, primary partition, secondary, extended.. You just do a normal install of an OS and when it boots and works as expected, you simply add that OS to GAG boot menu. No more copy of first boot sector of Linux to windows and any menu creation in Windows to multiboot. Just plan install of every OS you want and adding in to GAG boot menu. That’s all. Simple as nothing else. When you do some changes to Lilo (new kernel for example) there is no need to do any changes regarding multi booting. Just save new Lilo to boot sector. That is all.
    Please give a chance to GAG and you’ll never go back!

    Regards all,

    Zdenko




  16. Pingback: Experience Booting Linux Using the Windows 7 Bootloader | The Linux Experiment

  17. Pingback: Cannot boot with ext4

  18. Pingback: Windows 7 + Slackware 14.1 dualboot SSD

  19. Pingback: Installer Hangs on MacBook Pro [Video showing problem]

  20. Thank you SO MUCH Eric!

    Never coulda done this without you

    “bcdedit /set {ID} path \linux.bin”

    resulted in ERROR and unable to boot Slackware

    Checked the output of bcdedit and learned that the EXISTING path of my {current} device c: path was \Windows\system32\winload.exe

    so instead of:

    bcdedit /set {ID} path \linux.bin

    i used:
    bcdedit /set {ID} path \Windows\system32\linux.bin

    I moved the linux.bin file from \Windows to \Windows\system32

    Slackware now successfully boots on my Windows7 machine


  21. Pingback: dual boot win7/slackware 14.2 64bit in legacy mode on gpt disk | SOPEE.NET IT KNOWLEDGE BASE


Leave a Reply to snowglobe Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.