How can I prevent Windows from overwriting GRUB when using a dual-boot machine

Windows will overwrite the boot sector whenever you install it, upgrade it to a new version, or use tools like bootrec /fixmbr, bootrec /fixboot, or the older fdisk /mbr. In general, install Windows first, then Linux. The boot sector will stay put until you do one of the things above. (And perhaps there are also other ways to write onto the MBR.) But, if you lose GRUB, it is easily restored:

  • Boot from a live CD (CD/DVD or flash drive).
  • Become root or use sudo with commands below.
  • List the available partitions if needed: fdisk -l
  • Windows will almost certainly exist on /dev/sda1: mount /dev/sda1 /mnt
  • Reinstall GRUB in the MBR: grub-install --root-directory=/mnt/ /dev/sda
  • Reboot: shutdown -r now
  • Restore the GRUB menu: update-grub

You could also install 100% Unix, Linux, or BSD and simply run Windows in a virtual machine if the computer is strong enough for that.

Also: your computer's BIOS may have an option to protect the boot sector.


I think I will go with a vanilla GRUB setup and not mess with the bootloader.

If you use any form of grub, you are messing with the boot loader. GRUB stands for "grand unified bootloader". And there are two versions -- grub v1 adn grub v2. All modern linux systems use grub2 automatically. If you install any linux system, grub is the default bootloader unless you specifically go with LILO, which I would not suggest.

I personally have a dual boot system with xp and Wheezy. I keep xp from over writing grub by disabling "windows restore" option.

Before I disabled the restore option, I would have to fix grub at least once a week as windows bootloader kept overwriting grub.

I am fixing to install windows 8 on an external hard drive through a usb port. I am hoping this goes without a hitch and doesn't mess with my mbr.


A solution I found somewhere online (unix.stackexchange.com) involves deactivating windows boot manager. Get into Linux (either the original install, if you can or live CD/DVD) and run this command:

efibootmgr

Note that this method will only work if Linux has been installed in UEFI mode, so you'll get an error if Linux has been installed in Legacy mode. If you installed it in UEFI mode, you'll get some info and a list. You'll notice Windows boot loader/manager and Linux somewhere in the list. It's likely that Windows will have higher priority (boot order is above the list).

There are also stars* beside some, if not all, of the entries, marking them active.

Look at the 4 digit boot number next to Windows entry and run

sudo efibootmgr --bootnum #### --inactive

This will deactivate Windows entry. Also, make sure that now deactivated Windows has higher priority if it doesn't already:

sudo efibootmgr --bootorder ####,$$$$,&&&&,%%%%

where #### is Windows boot number.

If you reboot now, you'll boot to grub, if the Linux option is enabled with the highest priority.

Note that Windows doesn't seem to recognize that it's been deactivated, so this will not get reverted by booting into Windows or updating it.

I participated in a local Linux installfest where we install Linux for interested people, most often as a secondary OS next to Windows. I've yet to see this method fail, and I've tried it on several distros (mostly Ubuntu and Mint) and several vendors (Asus, Acer, HP, Lenovo).