How to boot Linux using Windows bootloader (XP)

You want to setup dual boot on your computer but do not want to install Grub or Lilo (You still are use LILO?), then read on….

Otherwise, if you are tired of Windows over writing Grub or LILO every time you setup Windows, then you can sacrifice the powers of Grub and shift to Windows Boot Loader to boot you into Linux.

Here are the steps: (Ideal case)

Windows XP Loader (NT Loader) needs Linux Master Boot Record (MBR) to boot into Linux.

If you can boot into Linux, grab the first 512 bytes of boot sector from the root partition of Linux  where Grub is installed (/dev/sdaN) to an external drive.

 dd if=/dev/sdaN of=grub.bin bs=512 count=1

Here is the twist!

In my case, I had an existing Linux installation but I could not boot into Linux and I didn’t have a rescue disk. I installed Ext2 IFS For Windows and copied MBR which I had extracted previously before I wiped out Grub  /boot/grub/stage1 and named it grub.bin (Your MBR is nothing but stage1 boot-loader used by GRUB).

To setup Windows bootloader to load Linux, we need to add an entry corresponding to Linux.

Boot into Windows. Set appropriate attributes for boot.ini so that it is editable.

attrib -r -w -s c:\boot.ini

Add the following entry to the file boot.ini

 c:\grub.bin="Ubuntu Linux 7.10"

Restart the machine and Windows XP boot loader shows Ubuntu Linux 7.10 as one of the options.

Select this option and viola! you should see Linux booting 🙂

For more detailed instructions follow this : http://www.tprthai.net/bootmgr.htm

http://www.supergrubdisk.org/ provides a specialized rescue disk to restore Windows/Linux. I haven’t used it anytime though.

22 responses to “How to boot Linux using Windows bootloader (XP)

  1. It doesn’t work for me. After booting in ‘linux’ i get a blank screen and the computer restarts. It looks like he’s executing garbage and then restarts.

    Any suggestions?

  2. Do you see grub loading after you chose Linux from Windows bootloader menu?

    If your screen doesn’t show any messages at all, then I guess you don’t have the right MBR copied. Verify that the size is 512 bytes. Alternately try replacing that with a clean copy from some other source

  3. I tried using Ext2 IFS for Windows to copy the file and followed the steps. But when I boot it up I just get a GRUB word. Any help ?

  4. @ttwj
    I simulated your scenario, /boot/grub/stage1 *DOESN’T* work.
    When I tried to boot into Linux, the screen showed error message “GRUB Disc Geometry…”

    If I understand it right, /boot/grub/stage1 doesn’t reflect the current disk geometry, hence it can’t identify bootable partition. For you, the only option seems to be
    * booting into Linux using a rescue disk and restore back Grub.
    In case you want to use NTLOADER and not Grub,
    * extract MBR and follow the steps mentioned above

  5. This week I setup Linux on Dell D830 notebook. This system had MS Windows XP pre-installed. I wanted to convert this into a dual boot without touching the MBR (since Dell has DSR enabled). I used Ubuntu installer CD, resized the MS Windows partition to make room for my Ubuntu. I chose to install GRUB on boot partition of Ubuntu (eg./dev/sda5) instead of MBR. Post installation I booted Ubuntu using live CD and extracted GRUB bootloader onto an external device. Then followed the steps mentioned above (in the post) to setup Windows bootloader to load Ubuntu Linux.

  6. Worked!

    I have two hard drives on my PC. The first has Windows XP. I wanted to install Ubuntu 8.10 on the second. This is what I did:

    – Install Ubuntu on second hard drive (guided partition on sdb to use all drive)
    – I selected to install the boot loader on sdb (neither sda or sd1 etc where is Windows, nor sdb1, sdb2 etc)
    – After than Windows boot up normally and couldn’t see the formated drive with Ubuntu.
    – I booted with Ubuntu live cd, went to root dir and copied (as mentioned above) and did: “dd if=/dev/sdb of=ubuntu.bin bs=512 count=1”
    – Then I copied the file to my flash drive (formatted in fat32 or fat) e.g. “cp ubuntu.bin /media/KINGSTON/ubuntu.bin”
    – Booted on windows
    – Copied the file on a folder e.g. C:/LnxBoot/ubuntu.bin
    – Right Click on my computer –> properties –> advanced –> start-up and recovery –> settings –> edit
    – Added the line C:\LnxBoot\ubuntu.bin=”Ubuntu 8.10″

    That’s it! Now when I turn on the PC I go to the windows bootloader and I have the options Windows XP Pro or Ubuntu 8.10
    If I select windows I actually go to grub and then I can go to Ubuntu.

    I guess it was not necessary to install boot loader when I had to install Ubuntu… but the fact that it FINALLY works makes me happy enough to stop more experimenting…
    Thanks!

  7. I am getting error like hal.dll is missing.

    My windows is on d drive.
    and my generated file name is fedora_grub.bin.
    So, i am writing following entry in boot.ini.
    d:\fedora_grub.bin=”linux fedora 9″

    but it is not working….

  8. Here is a check to see of you DID copy the real MBR. Run this command in linux “hexdump boot.lnx”. The last set of numbers should be ff88.

    Hope that helps

    ionize.ca

  9. Whatever i do, the only result is an empty screen.

    I used a live CD, opened Terminal, went to the root of the drive where i installed Linux, and ran the command from the post (adjusting the HDD and partition) – i copied the resulting file to a flash drive, and booted into windows, where i copied it and made the adjustments to the boot.ini file.

    Still nothing – also, hexdump only gives me a bunch of zeroes when i run it on the ubuntu.bin file, ending with 00000200.

    I have no idea what to do next – i tried extracting from everywhere, and the resulting file never ended with “ff88”, nor did it boot into Ubuntu.

  10. Hi,

    I have installed Mandriva 2009 successfully, I am unable to copy the boot.lnx to my windows partition. I tried using the unix cp command at the console in rescue mode. I mounted the windows drive and copied the generated boot.lnx to windows dir. But after rebooting i am unable to see the boot.lnx file in windows. Mandriva does not give any option of creating the boot cd. I do not have floppy drive. Can somebody suggest a work around?

    Thanks,

    Sesha

  11. It is possible to copy the MBR of any disk into Windows by using a Windows program and therefore skipping the use of a memory stick or floppy disk.

    There exists several ports of the dd command to Windows, but I think it is easier and more safe to use another program. MBRFix and MBRWizard are command line programs that are available as free downloads, while MbrWhisky is a GUI frontend to MBRWizard.

    You can also use the program HxD to view and edit any file or sector of the disks.

    I have Windows XP installed on one disk, and Linux is installed on another physical disk, with the GRUB stage1 loader installed in the MBR of that disk.

    To be able to boot Linux from Windows XP’s boot.ini I had to first copy the MBR of the Linux drive to a file on the Windows C-drive. But to be able to boot from the second disk, the disk number (81 hex) had to be written to address 40 hex of the copy of the MBR (e.g. C:\ubuntu.mbr). The original value was in my case FF hex (which means that the boot drive is selected in the BIOS), but you may also see the value 80 hex (which is the number of the first disk).
    NOTE! I would recommend that you do not edit the disks directly using HxD, it can make all data on the disk unavailable if you are unlucky.

    Links:
    I found the details on the MBR in: http://www.geocities.com/thestarman3/asm/mbr/GRUB.htm
    MBRFix: http://www.sysint.no/nedlasting/mbrfix.htm
    MBRWizard: http://mbrwizard.com/
    MBRWhisky: Could not find a download link now, I once downloaded it as part of creating a disk using WinBuilder.
    HxD: http://mh-nexus.de/en/hxd/
    5 Free Tools to Backup and Restore Master Boot Record (MBR): 5 Free Tools to Backup and Restore Master Boot Record (MBR)

  12. How do I use MBRWiz to copy the first 512 bytes of the linux boot partition

  13. If you have more than one disk, you must find which disk number to use by asking MBRWiz to list info on the disks. the /LIST options give the following output on my PC:

    C:\> mbrwiz /list

    MBRWiz – Version 2.0 **beta** for Windows XP/2K3/PE April 30, 2006
    Copyright (c) 2002-2006 Roger Layton http://mbr.bigr.net

    Disk: 0 Size: 191G CHS: 24321 255 63
    Pos MBRndx Type/Name Size Active Hide Start Sector Sectors DL Vol Label
    — —— ———- —- —— —- ———— ———— — ———-
    0 0 83-Linux 258M Yes No 63 530,082 —
    1 1 83-Linux 40G No No 530,145 81,915,435 —
    2 2 0F-EXTEND 6.1G No No 82,445,580 12,578,895 F: Old_Data
    3 3 07-NTFS 121G No No 143,878,140 246,838,725 —

    Disk: 1 Size: 715G CHS: 91201 255 63
    Pos MBRndx Type/Name Size Active Hide Start Sector Sectors DL Vol Label
    — —— ———- —- —— —- ———— ———— — ———-
    0 0 07-NTFS 150G Yes No 63 307,210,932 C: PROGRAM
    1 1 07-NTFS 350G No No 307,210,995 716,804,235 E: DATA

    Based on the partitions on the disks, it is easy to see that the disk that MBRwiz is numbered 0 it the one with Linux.
    Other programs may use other numberings!

    To backup the MBR (the first sector) of disk 0 you can use:

    C:\MBRFix>MBRWiz /Disk=0 /Save=c:\MBR-disk0.mbr

    MBRWiz – Version 2.0 **beta** for Windows XP/2K3/PE April 30, 2006
    Copyright (c) 2002-2006 Roger Layton http://mbr.bigr.net

    The MBR was successfully saved to c:\MBR-disk1.mbr

    To verify that the file contains the MBR yoy wanted to copy, display the partitions using the /SHOW option:

    C:\> MBRWiz /Show=c:\MBRWiz-MBR-disk0.mbr

    MBRWiz – Version 2.0 **beta** for Windows XP/2K3/PE April 30, 2006
    Copyright (c) 2002-2006 Roger Layton http://mbr.bigr.net

    Displaying contents of MBR from file: c:\MBRWiz-MBR-disk0.mbr

    Pos MBRndx Type/Name Size Active Hide Start Sector Sectors
    — —— ———- —- —— —- ———— ————
    0 0 83-Linux 258M Yes No 63 530,082
    1 1 83-Linux 40G No No 530,145 81,915,435
    2 2 0F-EXTEND 6.1G No No 82,445,580 12,578,895
    3 3 07-NTFS 121G No No 143,878,140 246,838,725

    To edit the BOOT.INI file, I prefer using this method which does not require using the ATTR DOS command:
    Start – Control Panel – System – Advanced
    Here you can change the default boot entry of boot.ini, change the time that the boot menu swukk be displayed, and EDIT the boot.ini file in Notepad.

    Finally, I would like to add the URL that I missed out in my previous post:

    5 Free Tools to Backup and Restore Master Boot Record (MBR) –
    http://www.raymond.cc/blog/archives/2008/11/10/5-free-tools-to-backup-and-restore-master-boot-record-mbr/

  14. i am having the hal.dll problem too. anyone knows how to solve it?

  15. it show the message:

    Windows could not start because the following file is missing or corrupt:
    \System32\hal.dll
    Please re-install a copy of the above file.

    anyone knows how to solve it?

  16. already solve the 1 problem. but know when i choose launch linux, it lauches the grub. Anyone help me?

  17. ok. all problems solved.

    for the hal problem was that my file was named linux.bin.bin and in the boot.ini i put linux.bin. NOOB! the Win hides the extension by default.

    the other problem:
    i had on disk “sda” and 3 partitions: win, linux, swap.
    when i formated the windows i destroyed the partition… then when i created the part again the number changed. before linux was in sda3 but know is in sda2.

    just swaped the lines in fstab e voila.!

  18. This hal.dll error also comes if the partitions are not numbered correctly in the windows boot.ini file. Once i numbered the partitions correctly in the boot.ini file my error was fixed.

  19. Thanks for the tutorial, better than a lot of the ones I found before finding yours through Google. I have my system up and running and I’m very happy 🙂

  20. bleh, didn;t work for me.
    1) dumped the MBR of disk1 where ubuntu resides with both live cd and the mbr utils giving the same result (not ending with ff88, but aa55 btw)
    2) added bin to boot.ini on disk 0 where XP is

    all I ever end up with is the word GRUB_ and that’s it. Even hexedited hex position 40 to reflect 80 and 81 (org. was FF), result: zip

    I’m gonna go with grub on my XP disk 😦 I saved the MBR in case anyone has a viable alternative. Thanks for the comprehensive info though.

  21. I am completely new to linux. I didn’t even know what it was until I realized aircrack-ng would only work on “Linux”

    I am dual-booting with xp.
    Where is “grub.bin” (or whatever you decide to call it) stored?
    I can’t copy it to my flash drive if i can’t find it

    help, please

Leave a reply to rafael Cancel reply