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).
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.
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.GParted create partition table |
Create the FAT32 partition |
Create the NTFS partition |
USB drive partition scheme |
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.Installing required package. Notice nothing gets removed! |
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/sdXRead 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):
Installing GRUB and copying EFI loader |
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.
Installation media appears as hard drive |
Two system partitions on different drives |
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 bootThese 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.
Hi,
ReplyDeleteThanks 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,
Have you tried without ESP flag? Just leave the FAT partition without flag.
DeleteThis worked for me for Windows 10 in 2019! Thank you!
ReplyDeleteI just had to partition my table as GPT as mentioned in FAQ.
Windows also asked me to partition my HDD as GPT.
Hi! Your blog is too useful for me.
ReplyDeleteIs 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)?
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.
DeleteHi,
ReplyDeletethe 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
Suberb method A is working for me date 15 aprill 2020 thank you.
ReplyDeleteOr just fat32 with splitted install.wim? Worked with win10 1909
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteto add legacy mode booting:
Delete[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]
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).
ReplyDeleteI 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?
ReplyDeleteWhat method did you use? A or B?
Deletewhen 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?
ReplyDeleteThank 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.
ReplyDeleteIn 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!
ReplyDeleteCopy all files from the Windows ISO to USB drive. No other file moving requirements for Windows 10.
Deletehi i used method A but still when i go to the boot sequence the usb still doesn't appear
ReplyDelete