Switching Windows 7 and Ubuntu to UEFI

UEFI Logo

UEFI Logo

After upgrading my hard disk on my Laptop I planned to switch to a GPT (GUID Partition Table). But since I’ve a Windows 7 installation as well I had to switch to UEFI boot mode because Windows 7 does not support booting from GPT using the old BIOS/MBR bootmanager/bootloader (You can find a good Q&A about GPT support of Windows at MSDN). Luckily my old HP Elitebook 8530w already includes an UEFI enabled BIOS (without Secure Boot). It supports (like many others) the old boot mode as well as the new UEFI boot mode. By selecting the “UEFI” entry in the boot menu one can make sure that the UEFI boot mode is enabled. After reading some documentation (especially the once from Roderick W. Smith) I decided to use the rEFInd boot manager and the kernel provided EFI stub bootloader (part of the mainline kernel since 3.3.0). I’m using Ubuntu 12.10 which comes with Linux 3.5 and enabled EFI stub bootloader in the stock kernel…

I document the whole process I did including my errors. One could make it in a more straight forward matter. The easiest way would be just installing the the operating systems in UEFI mode by boot the installers in UEFI mode in first place. Also my setup doesn’t involve secure boot mode.

I started by creating a EFI System Partition (ESP) under Ubuntu. First I had to shrank my first partition using gparted (this can take a while, depending on the size of the partition). Using fdisk (I’m still using an old MBR) I created a 512 MiB partition the very beginning of the disk with 0xef as type. I reordered the partitions using x (extra functionality), f (fix partition order) and w (write table to disk and exit). Then I formatted that partition using mkfs.vfat:

mkfs.vfat -L HP_TOOLS

The label is somewhat special for my setup, since HP requires it in order to install and Boot their utilities and load a customized BIOS screen (HP provides EFI based utilities such as HP QuickLook or HP System Diagnostics. More info about the Elitebook UEFI BIOS implementation can be found in the EFI Guidlines whitepaper). I’d like to mount the UEFI partition into its usual directory. Fist I had to extend the fstab with the new entry for my ESP (get your partition ID by using blkid /dev/sda1)

# <file system>  <mount point>   <type>  <options>               <dump>  <pass>
UUID="1234-1234" /boot/efi       vfat    rw,noexec,nosuid,nodev  0       2

Then I installed the rEFInd boot manager from Ubuntu following the official guide (I opted for the manual installation which was quite easy). Because my Ubuntu did not started through UEFI, i could not execute the efibootmgr command (Step 6). More on that later. I then copied the Ubuntu kernels and init images manually onto the EFI System Partition into the folder /EFI/Ubuntu (EFI absolute).

mount /boot/efi
mkdir /boot/efi/EFI/Ubuntu
cp /boot/vmlinuz-3.5* /boot/efi/EFI/Ubuntu
cp /boot/initrd.img-3.5* /boot/efi/EFI/Ubuntu

To provide rEFInd the Kernel options I created an Ubuntu specific configuration file at /EFI/Ubuntu/refind_linux.conf (alter the UID according to you root filesystems UID, use blkid again):

"Boot with UID" "root=UUID=12ab34cd-ea74-4069-b061-ab12cd3456ab ro quiet splash vt.handoff=7"
"Boot recovery" "root=/dev/sda2 ro recovery nomodeset"
Boot From EFI File

Boot From EFI File

Time to start the boot manager: Because I couldn’t create an boot entry in EFI using efibootmgr I have to start the rEFInd boot manager manually by selecting “Boot From EFI File” and choose /EFI/refind/refind_x64.efi from the new ESP partition. I could then already start Ubuntu using UEFI (while still using the old MBR/DOS partition table!)

Now I wanted to try to boot Windows 7 using UEFI and MBR/DOS partition table (although I read at several places that it doesn’t work without GPT… Wanted to see what happens :-)). To do this, I converted my Windows 7 from MBR-boot mode to UEFI boot mode (taken from this guide). I did just step 3.5 (Setup the Windows Bootloader in the UEFI System Partition) directly from my Ubuntu installation:

mkdir -p /boot/efi/EFI/Microsoft/Boot/
cp -R /path-to-windows-c/Windows/Boot/EFI/* /boot/efi/EFI/Microsoft/Boot/

When I start the Windows Boot Loader from rEFInd at this stage, it just ends with an error message:

File: \EFI\Microsoft\Boot\BCD
Status: 0xc000000f
Info: An error occurred while attempting to read the boot configuration data.

This is because there is no BCD (Boot Configuration Data) in place since I just copied the boot loader. Well, Step 3.6 (Recreate the Boot Configuration Data) should solve this problem. It’s necessary to boot the Windows installer in UEFI mode. I created the bootable USB flash drive using Microsoft’s Utility “Windows 7 USB DVD Download Tool” which formatted it with NTFS. But UEFI BIOSes are (today) not able to boot from a NTFS file system. So I moved all files to a temporary location, reformatted the USB flash drive using FAT32 and copied the files back. Also I had to add the UEFI boot loader using this guide (german). A simple way how to create a new bootable UEFI USB flash drive is described in this Technet blog post.

I then opened the boot menu (F9) again, choose “Boot From EFI File” and selected the bootloader under EFI/Boot/bootx64.efi from the USB stick. After booting I choose “Repair your computer”. But this ended in the following error message:

Diese Version der Systemwiederherstellungsoptionen ist nicht mit der zu reparierenden Windows-Version kompatibel. Verwenden Sie einen mit dieser Version von Windows kompatiblen Wiederherstellungsdatenträger.

or in english

This version of System Recovery Options is not compatible with the version of windows you are trying to repair. Try using a recovery disc that is compatible with this version of windows.

This error appears because I tried to repair a Windows installation on a disk using MBR/DOS partition table while using using the Windows repair console in UEFI mode (it also appears if you do it visa verca).

Well then, its time to convert my partition table to a GPT partition table. Using Ubuntu, I backed up my old MBR on a USB flash drive using dd:

dd if=/dev/sda of=/mnt/mbr-sda.dd bs=512 count=1

Converting to GPT is very easy, simple start the gdisk utility and it will create the GPT partition table from the current MBR/DOS partition table. Write the new GPT using “w” and confirm with “Y”.

Now I tried to recreate the Boot Configuration Data again. After starting again from the USB flash drive in UEFI mode I could successfully select the “Repair your computer” option. It did not recognized my Windows installation, nevertheless I could start the system startup repair which tooks a while to succeed. After restarting, I was able to boot Windows 7 too.

Switching is possible and with a running Ubuntu installation not that hard. Still, you have to take care and have one or two bootable USB flash drives at hand, just in case.. Also while the whole process I had still a copy of my partitions on the old hard drive, just in case!

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>