UEFI NTFS: Bootable Windows USB from Linux

Published on September 27, 2015 . Updated on: -
Installing Windows from USB drive in UEFI mode requires a FAT32 formatted USB drive. How to create that bootable USB is described in Make a bootable Windows USB from Linux (Ubuntu). However that method is unusable in some cases where install.wim is larger than 4 GB.

The procedure that is about to follow should work with any Windows version that supports UEFI boot (Windows 7 on 64 bits and all the newer versions). It has been successfully tested only in VirtualBox but it should work on real hardware too.

We will make two partitions on the USB drive, one that is FAT32 and will hold an EFI bootloader and the other is NTFS and holds Windows installation files. The bootloader will use a NTFS driver to read the NTFS partition and boot Windows.

UEFI NTFS: Bootable Windows USB from Linux

1. Format USB

This is done as usual using GParted. But you will make two partitions. The discussion here is about choosing the right partition table. Actually both MBR and GPT work. And I suggest MBR. UEFI can read MBR FAT32 contents and boot from it. Launch GParted, select the correct drive and unmount it if necessary. Then, from Device menu choose Create partition table. Select msdos and Apply.

Create partition table in GParted - screenshot
GParted create partition table
Next, you'll make an 30 - 80 MB FAT32 partition at the end of the USB drive. This will hold the EFI bootloader. Right click the unallocated space and add a New partition with the following specification:

GParted new partition dialog
Create the FAT32 partition
Right click again the remaining unallocated space and add a NTFS partition. The labels are not mandatory but are a way to remember what will that partition hold.

GParted new partition dialog
Create the NTFS partition
When you're finished, the partition scheme on USB drive should look like below. You could reverse partition order, but I strongly suggest you keep the FAT32 one containing EFI loader at the end!

GParted main window
USB drive partition scheme
Keep in mind what number gets assigned to the NTFS partition. You will need to specify it to GRUB configuration. You can close GParted now.

2. Copy Windows files

Mount the big NTFS partition (windows in my example) and copy all Windows files from mounted ISO or DVD to it. Then look on the USB drive, in efi/boot folder for bootx64.efi file.

If the OS you are making a bootable USB for is Windows 7, browse the efi/microsoft folder and copy the entire boot folder from this path one level up in the efi folder. Merge folders if boot already exists.

Here is what to do if you don't have the bootx64.efi file in efi/boot folder. Browse into the mounted Windows ISO image into the sources folder. Open install.wim with your archive manager (you will need 7z installed). Go to the path ./1/Windows/Boot/EFI and extract the file bootmgfw.efi anywhere you want. Rename it to bootx64.efi and put it on the USB drive, in the efi/boot folder. If you can't find bootmgfw.efi in install.wim then you probably have a 32 bit Windows ISO or other types of images (recovery disks, upgrade versions).

When you're done, you can unmount the partition.

3. Make it bootable

Method A

This method is simple. You are probably wondering what files we put in the FAT32 partition. We will use Pete Batard's UEFI:NTFS driver. Grab his FAT32 disk image from here: uefi-ntfs.img and mount it using Disk Image Mounter on Ubuntu. You will find an EFI folder and a readme file. Copy the entire EFI folder and its contents to the root of your FAT32 partition from thumb drive. Unmount. You can now boot from that USB drive.

Method B

Here we will use GRUB. It is a little more difficult to install and configure. It doesn't matter what architecture is your current Linux distribution as long as it is booted by GRUB. You will need the grub-efi-amd64-bin package installed (if you're running an EFI x64 distro you already have it installed). It's very important to pay attention to possible conflicts when installing it and abort installation if there are any. I will install the package in Ubuntu using Synaptic.

Synaptic - install grub-efi-amd64-bin
Installing required package. Notice nothing gets removed!
I'm not using an UEFI booted Ubuntu. Installing this package should not interfere with other GRUB packages that are responsible for correctly booting your system. See in my example that no package gets removed in order to solve conflicts.

Mount the FAT32 small partition (named loader in my example) and note its mount point. If you clicked on it in the Files manager, it should be mounted at /media/<username>/<partition_label>. Also note the USB drive device (e.g. /dev/sdb).

First of all we need a directory to install GRUB in it. So make a directory named boot either using Files or the Terminal (cd /media/<username>/loader && mkdir boot). We can now install GRUB. In Terminal:
sudo grub-install --target=x86_64-efi --boot-directory=/media/<username>/loader/boot --efi-directory=/media/<username>/loader /dev/sdX
Read this command carefully and adapt it to your situation. --boot-directory is the boot folder from the FAT32 partition. --efi-directory is the mount point of the small FAT32 partition. /dev/sdX is the USB drive device. Failing to use the correct values in this command may make your system not bootable. If you're not EFI booted, you'll see some warnings but installation will proceed anyway.

Browse the small FAT32 partition and look in EFI folder for another folder that contains an .efi file. Since I used Ubuntu for this, I got ubuntu folder and grubx64.efi file (/EFI/ubuntu/grubx64.efi). In EFI folder make a boot folder. Then copy the grubx64.efi to boot folder and rename it to bootx64.efi. You should get a file at /EFI/boot/bootx64.efi.

Here are my commands executed from Terminal (grub-install is used a little different, partition names are diferent):

Gnome Terminal install GRUB
Installing GRUB and copying EFI loader
GRUB needs a configuration file. Go on the FAT32 partition (loader), in the boot/grub folder and create a text file named grub.cfg. Write the following in it:
menuentry 'Start Windows Installation (EFI)' {
    insmod ntfs
    set root='hd0,msdos2'
    chainloader /efi/boot/bootx64.efi
Note that 'hd0,msdos2' must be replaced with 'hd0,gpt2' if you used a GPT partition table! msdos2 or gpt2 must be replaced with msdos1 or gpt1 respectively if GParted assigned number "1" to the NTFS partition.

That's it. Boot from USB and start installation.


Q1: My USB drive is not bootable. Why?
A: Is your computer UEFI capable? The USB drive is not bootable from classic BIOS! Does the grubx64.efi file exists? Did you get any errors when installing GRUB? Post them in a comment.

Still not bootable? Start over again, but this time use a GPT partition table instead. Leave flags as they are (msftdata for both partitions) and try to boot. Doesn't work? Plug back the USB in the Linux PC, launch GParted and put the esp flag on the FAT32 partition (msftdata will get unchecked).

Q2: Can I use 32 bit installation?
A: If supported by Windows and your target PC, yes. If using method B you will need to install grub-efi-ia32-bin. You will use --target=i386-efi and you will rename grubia32.efi to bootia32.efi.

Q3: When installing Windows, I see the USB drive in the HDD partitioning dialog. Is it OK?
A: Probably this will only happen to me (because of using VirtualBox) and to anyone else who uses a hard drive instead of removable media. This is how the problem looks: the partition containing EFI loader is marked as System. If that's not the case, skip the following instructions and proceed with installation as usual.

Windows partitioning tool
Installation media appears as hard drive
Now, you must make some partitions on your actual hard drive. When you create the first partition, Windows will inform you that it needs more and it will create them. It obviously needs an ESP (EFI System Partition) and here comes the issue. If it finds an ESP on your installation media it will use that and you will have a Windows installation that only boots when you plug the device you used for installation. This happens when the FAT32 partition is already flagged as esp. This is why I avoided that! You can spot this behavior easily. Let Windows make its partitions. If it doesn't make a System type one, then quit the installation. Here is what confirms that you avoided the problem: two System partitions (the one from the installation media and the one from your hard disk):

Windows partitioning tool
Two system partitions on different drives
As long as there are two System partitions on two different drives everything is OK. Remember to look for this behavior only when your installation media (USB drive) appears in the partitioning tool!

Q4: I'm thrown to GRUB command line. What happened?
A: There is something wrong with the grub.cfg file. Don't worry. While you are at the command line type one by one the following commands:
insmod ntfs
set root='hd0,msdos2'
chainloader /efi/boot/bootx64.efi
These are the exact commands from grub.cfg. You should be booting Windows now.

Other issues or errors? Post a comment with your problem or error message.

From the same category:

Share this page:


Post a Comment

Please read the comments policy before posting.