UEFI NTFS: Bootable Windows USB from Linux

 Posted by:   Posted on:   Updated on:  2018-02-01T14:55:57Z

If you have a modified Windows installation source, larger than 4 GB you can't format the USB drive to FAT32. See how to make a NTFS formatted UEFI bootable Windows installation USB using Linux (Ubuntu).

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
    boot
}
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.

Q&A

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
boot
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.

18 comments :

  1. Hi,

    Thanks for posting some valuable information in here.. Actually I tried your way, but finally I'm getting error like "Unknown error" after I ran the command of "grub> boot"

    * Current running system is "Ubuntu (EFI - 64 Bit)
    * USB 32 GB (msdos), FAT32, Flag: esp (msfdata flag is not there for me right now, tried by both "esp, boot" & 'esp' only)

    I correctly, followed that "grub.cfg" file commands one by one... Could you please help me to fix this issue..?

    Error Screenshot: https://drive.google.com/file/d/1S7tt1wfz6IhCxJy9ugLXRMaQ6SLYIiRB/view?usp=sharing


    Thanks,



    ReplyDelete
    Replies
    1. Have you tried without ESP flag? Just leave the FAT partition without flag.

      Delete
  2. This worked for me for Windows 10 in 2019! Thank you!

    I just had to partition my table as GPT as mentioned in FAQ.

    Windows also asked me to partition my HDD as GPT.

    ReplyDelete
  3. Hi! Your blog is too useful for me.
    Is there a way to create a multiboot flash drive having windows 10, Ubuntu and a macrium system rescue bootable environment, all in one flash drive(using grub)?

    ReplyDelete
    Replies
    1. I have never tried this, but I think GRUB is able to do it. I don't know how well it will be supported by the booted OSes because they will be in different folders (or partitions) on the USB drive.

      Delete
  4. Hi,
    the first steps went like a charm, but when installing grub on the FAT32 partition following error appears:

    "grub-install: error: efibootmgr failed to register the boot entry: No such file or directory."

    im quite sure that i put the correct names of my folders.
    Any help will be appreciated
    Thanks

    ReplyDelete
  5. Suberb method A is working for me date 15 aprill 2020 thank you.

    ReplyDelete
  6. Or just fat32 with splitted install.wim? Worked with win10 1909

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. to add legacy mode booting:
      [CODE]grub-install --target=i386-pc --boot-directory="/<mount point of ntfs partition" /dev/sdX[/CODE] On most distros will have to install grub-pc/grub-i386pc package
      add a grub.cfg to the ntfs partition grub folder with this in it
      [CODE] ntldr /bootmgr
      boot[/CODE]

      Delete
  8. This tutorial worked for me (Jan 2021) in a Ubuntu 18.04 with the GPT table partition (no need for changing the flags in the FAQ).

    ReplyDelete
  9. I followed all the steps but, when i try to boot from my pendrive, the screen stay black with a white bar blinking on the corner, what could be?

    ReplyDelete
  10. when i got to boot the usb there is no uefi option and just usb, when it boots i get a flashing underscore and nothing can be keyed in. any ideas?

    ReplyDelete
  11. Thank you for the article. It worked for me for a Win 10 installation. I only had to switch off Secure Boot in BIOS. I had an SD card in an USB card reader, so it was a bit slow, but worked.

    ReplyDelete
  12. In the 2. Copy Windows files step can you show some output of which files are getting copied to which destination? It's confusing which files are going where and if moving files is even required for Windows 10. Thank you!

    ReplyDelete
    Replies
    1. Copy all files from the Windows ISO to USB drive. No other file moving requirements for Windows 10.

      Delete
  13. hi i used method A but still when i go to the boot sequence the usb still doesn't appear

    ReplyDelete

Please read the comments policy before publishing your comment.