UEFI Dual Boot – Preinstalled Windows 8 and Linux on a Laptop

arch linuxlinuxmulti-bootuefiwindows 8

I am trying to set up Windows 8 and Arch Linux on a new Sony Vaio E14 with preinstalled windows 8.

So far:

  • installed W8 to my new SSD (switched for the original HDD) using Recovery Media
  • shrunk the W8 partition, deleted recovery partition, disabled swap
  • confirmed W8 booting just fine

On to Arch:

  • disabled Secure Boot in bios
  • confirmed W8 booting just fine
  • Booted Arch off the CD and installed everything to 4th and 5th partition
  • set up rEFInd for EFIstub kernel bootloader

After that it got worse. I was unable to boot anything else than Windows 8 (although I was glad that they at least kept working just fine).

Tried:

  • creating EFI\refind\ and putting the .efi there (as per Arch manual
  • overwriting EFI\boot\bootx64.efi
  • overwriting EFI\Microsoft\Boot\bootmgr.efi
  • overwriting EFI\Microsoft\Boot\bootmgfw.efi — YAY rEFInd shown up!

So far, so good. I've kept the whole W8 Boot\ directory in EFI\windows8 and set up a boot menuentry for it; and it booted just fine.

But, upon restart, everything was wrong — 'Operating system not found' instead of any bootloader (refind or w8).

Booted back into Arch using the live CD to find out that the EFI partition had erroneous FAT table. fsck.vfat fixed it, and I've found that EFI\Microsoft\Boot was back to it's original state (all refind files deleted and replaced with W8 bootloaders). I've overwritten them again and got back to rEFInd showing up correctly and Arch being perfectly bootable.

After that I've tried only renaming EFI\Microsoft\Boot\bootmgfw.efi to bootmgfw.001.efi (then copying refind's .efi to bootmgfw.efi and keeping EVERY OTHER file as it was), but with exactly the same result. Tried marking the GPT EFI partition as read-only, same result.

Now I'm kinda out of luck. Arch boots fine, so does W8 but it destroys the EFI partition in the process.

Thanks for any ideas, Googling brought me this far and I can't find any better.

PS — windows 8 MAYBE destroys the partition upon shutdown — when I order a shutdown in W8, it takes unusually long (about half a minute instead of ~5 seconds). So in theory I could solve this by hard-resetting the laptop instead of a normal shutdown, but that's just not nice.

Best Answer

It might be worth doing a cold shutdown (hit the power button) in Windows to see if you can boot afterwards, just as a test. Obviously you wouldn't want to do this on a regular basis, but it might be helpful to confirm that Windows is overwriting your revised ESP data. If it's actually damaging the filesystem on Windows shutdown, then this sounds like a Windows bug that should be reported to Microsoft. If it's just replacing the bootmgfw.efi file, then that's technically within Microsoft's purvue, so it's not really a bug.

More broadly speaking, though, have you tried using linux's efibootmgr program to register rEFInd with the EFI under its own name (say, EFI/refind on the ESP)? This is described in rEFInd's documentation, in the section on manual Linux installation. Alternatively, you could install using the install.sh script. Either method will require an EFI-mode boot to succeed, but you should be able to do this using a rEFInd CD or boot from an emergency disc in EFI mode.

If efibootmgr doesn't work, try using bcfg in an EFI shell program, as described on this Arch wiki page.

If these procedures don't work, try using efibootmgr or bcfg to remove the entry for bootmgfw.efi from the NVRAM and then install rEFInd as EFI/BOOT/bootx64.efi. In theory, the computer might then launch rEFInd, which should work normally and enable booting either OS. There are two potential gotchas, though: The firmware might favor EFI/Microsoft/boot/bootmgfw.efi over EFI/BOOT/bootx64.efi; and Windows might check its boot options and add its own boot loader back to the NVRAM when it boots. Still, this method is worth a try.

The EFI spec requires computers to honor their NVRAM settings (which are managed by efibootmgr in Linux, bcfg in an EFI shell, or similar programs), so if these utilities don't work, your firmware is broken, and you may want to consider returning the computer for another model. (Be sure to tell Sony why you returned the computer if you do so, though!) This type of problem is actually fairly common; I've got a Gigabyte board with a "Hybrid EFI" that keeps forgetting its NVRAM settings, for instance. At least with this board, though, it's possible to bypass the problem by naming my boot manager/loader of choice EFI/BOOT/bootx64.efi.

If you can't get it working and are unwilling or unable to replace the computer, I do have two other suggestions for workarounds:

  • You could keep a bootable CD or USB flash drive on hand with rEFInd on it, and use it when you want to boot Linux. This may require using a function key to tell the computer to boot from the removable media rather than from the hard disk whenever you boot, though.
  • You could wipe the partitions from the disk, repartition using MBR, and re-install both OSes in BIOS mode rather than in EFI mode. This will remove any EFI flakiness from the picture and enable you to use a BIOS-mode GRUB as your boot loader. This will probably require a retail copy of the Windows 8 installer, though; at least for Windows 7, the OEM copies were inflexible about the installation mode (BIOS vs. EFI). Alternatively, it may be possible to convert from an EFI-mode boot to a BIOS-mode boot without re-installing. The opposite switch is possible (I was going to post a link to a site where it's described, but this site won't let me post more than two links; sorry), and I seem to recall running across descriptions of doing an EFI-to-BIOS conversion somewhere, but I don't have a URL handy. A Google search may turn something up.

I stumbled across this page after posting my first answer, and it has another possible cause for at least part of your problem: Apparently Windows 8 uses a shutdown method that's more akin to a suspend-to-disk operation. The result is that mounted partitions can become corrupted if you shut down Windows and then boot Linux. Although the ESP isn't normally mounted in Windows 7, AFAIK, it could be that Windows 8 does things differently, or maybe the ESP is mounted in Windows 7 and just seems to be hidden. In any event, you can disable this feature of Windows 8 by typing the following command in an Administrator Command Prompt window:

powercfg /h off
Related Question