I have a feeling the following scenario is more common than you might guess, and certainly is more frustrating than it ought to be. I had a Windows laptop, to which I wanted to add a Linux partition. There are plenty of guides available online; some of the best are here (Linux installed first) and here (Windows installed first). However, at least one piece of backup software assumes that the Windows bootloader, NTLDR, is used as the primary bootloader. So I needed to boot Windows from NTLDR, and Linux from GRUB...but in installing Linux I had wiped NTLDR and replaced it with GRUB. This how-to guides you through restoring NTLDR as the primary bootloader, with GRUB chained onto it. Evidently the Vista bootloader is less ugly than this hack, but here's how it goes:
- You have a computer where:
- There are two primary partitions (a Dell recovery partition and a Windows partition)
- There's an extended partition containing at least two logical partitions (Linux + its swap partition) as the first logical partitions.
- GRUB was installed in the MBR of the disk, and overwrote NTLDR MBR.
C:\NTLDRexists, and is the Windows bootloader- You don't have a Windows installation disk, or you don't have an administrator password to Windows, and hence can't use the Recovery Console.
- Boot into Linux. Run
sudo grub. Within grub, runfind /boot/grub/stage1<== This will tell you something like(hd0,4), which is the drive and partition number for Linuxroot (hd0,4)<== use the same results as the previous stepsetup (hd0,4)<== Do NOT use setup (hd0), as that overwrites the disk's MBR. Using the partition number installs it into the partition instead- quit
- Mount a drive that can be read by Windows. (In my
case, I've mounted the Windows partition itself as
/windows/c/.) - Run
sudo dd if=/dev/sda5 of=/windows/c/grub.mbr bs=512 count=1. Here,sda5is the partition that Linux is installed in, the output file is in the root directory of the Windows partition, and the remaining arguments pull out the first 512 bytes, i.e. the bootloader, of this partition. - Reboot into Windows. Run
attrib -r -h -s c:\boot.inito remove its protections. Edit boot.ini to include the lineC:\grub.mbr="Ubuntu Linux". This is the main hack: it will cause NTLDR to load the specified file as a bootloader...and conveniently we've stashed GRUB into that file. It will be configured to look for the right menu.lst file in the Linux partition, because it was setup properly in step 2. Restore boot.ini's privileges withattrib +r +h +s c:\boot.ini. - At this point, if you reboot, GRUB is still the
bootloader. Presumably, you've placed a Windows boot
entry in
menu.lstbefore, which will cause the Windows partition's NTLDR to run...and now boot.ini contains a line that launches the faked GRUB inC:\...which has a menu entry to boot Windows, which launches NTLDR... So you have a cycle in the loaders, which is mildly amusing... - Download mbrfix.exe from
http://www.sysint.no/en/Download.aspx, with
description at
http://www.sysint.no/nedlasting/mbrfix.htm.
Run
mbrfix.exe /drive 0 fixmbrfrom a cmd.exe shell. This overwrites the MBR with the Windows MBR and points it to useC:\boot.ini. - At this point, if you reboot, NTLDR is now the
bootloader. It will use boot.ini that will have a
Windows entry and the new Ubuntu entry, which in turn
launches GRUB (from
C:\grub.mbr), which can still launch Windows' NTLDR... If everything works correctly, both OSes should be bootable from their respective bootloaders. - Protect grub.mbr by
attrib +r +h +s c:\grub.mbr - Reboot into Linux, and remove Windows' entry from menu.lst.
Contact
- Email (essential):
- (first initial + last name) {at} ccs.neu.edu
- Location (likely):
- West Village H, Office 326
- Post (possible):
-
Northeastern University
Khoury College of Computer Sciences
360 Huntington Ave, 2nd floor
Boston, MA 02115


