Create a bootable Windows 10 USB drive (UEFI) from Linux

61,960

Solution 1

You did all right. Make gpt table with fat32 and copy all data from iso on it. But you also need to set flag "msftdata"(not "boot") on this partition with e.g. parted.

Solution 2

Windows 10 October 2018 release UEFI bootable USB drive on any Linux distribution.

Notice, that since Windows 10 October 2018 release the installation file sources/install.wim is larger than the maximum FAT32 file size, so we will format USB drive to NTFS. Windows installer also cannot work with an EFI partition (code ef00), so we will use Microsoft basic data partition type (code 0700).

Variant A (For PCs with NTFS support)

Steps for creating USB drive with name /dev/sdc (Replace all commands with YOUR device name!):

  1. Insert USB drive to computer and make sure it is unmounted. Some distributions like to automount USB drives, so make sure you unmount them. Mounted partitions can be found with mount -l | grep '/dev/sdc', then unmount with sudo umount /dev/sdcX (where X is partition number).
  2. Open USB block device using gdisk /dev/sdc, configure it as GPT and create Microsoft basic data partition (code 0700), then write changes and quit (Next steps will destroy partition table in your USB drive!!!).
sudo gdisk /dev/sdc
o
> This option deletes all partitions and creates a new protective MBR.
> Proceed? (Y/N): y
n
> Partition number ... > hit Enter
> First sector ... : > hit Enter
> Last sector ... : > hit Enter
> Current type is 'Linux filesystem'
> Hex code or GUID (L to show codes, Enter = 8300): 0700
p
> Should print something like:
> Disk /dev/sdc: 15646720 sectors, 7.5 GiB
> Model: DataTraveler 160
> Sector size (logical/physical): 512/512 bytes
> Disk identifier (GUID): ...
> Partition table holds up to 128 entries
> Main partition table begins at sector 2 and ends at sector 33
> First usable sector is 34, last usable sector is 15646686
> Partitions will be aligned on 2048-sector boundaries
> Total free space is 2014 sectors (1007.0 KiB)
> Number  Start (sector)    End (sector)  Size       Code  Name
>    1            2048        15646686   7.5 GiB     0700  Microsoft basic data
w
> Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!
> Do you want to proceed? (Y/N): y
q
  1. Format new partition as NTFS (thx @Alex for -Q idea):
sudo mkfs.ntfs -Q /dev/sdc1
  1. Mount new USB partition to temporary directory in your home:
mkdir ~/tmp-win10-usb-drive
sudo mount /dev/sdc1 ~/tmp-win10-usb-drive
  1. Download Windows installation ISO, create new temporary directory in your home and mount it there:
mkdir ~/tmp-win10-iso-mnt
sudo mount Win10_1809Oct_English_x64.iso ~/tmp-win10-iso-mnt
  1. Copy all files from mounted ISO to USB drive (you can use rsync to see progress):
sudo cp -rT ~/tmp-win10-iso-mnt/ ~/tmp-win10-usb-drive/
  1. Unmount Windows ISO and USB drive and remove temporary directories:
sudo umount ~/tmp-win10-iso-mnt/ ~/tmp-win10-usb-drive/
rmdir ~/tmp-win10-iso-mnt/ ~/tmp-win10-usb-drive/
  1. Insert USB drive to new computer and boot from it.

Variant B (For PCs without NTFS support)

Steps for creating USB drive with name /dev/sdc (Replace all commands with YOUR device name!):

  1. Insert USB drive to computer and make sure it is unmounted. Some distributions like to automount USB drives, so make sure you unmount them. Mounted partitions can be found with mount -l | grep '/dev/sdc', then unmount with sudo umount /dev/sdcX (where X is partition number).
  2. Open USB block device using gdisk /dev/sdc
  3. Configure it as GPT
  4. Create first partition of 1GB size and type Microsoft basic data (code 0700).
  5. Create second partition of rest of the size and type Microsoft basic data (code 0700).
  6. Write changes and quit (Next steps will destroy partition table in your USB drive!!!).
sudo gdisk /dev/sdc
> o
> This option deletes all partitions and creates a new protective MBR.
> Proceed? (Y/N): y
> n
> Partition Number: Enter
> First sector: Enter
> Last sector: 1G
> Type: 0700
> n
> Partition Number: Enter
> First sector: Enter
> Last sector: Enter
> Type: 0700
> p
# Should print something like:
> Disk /dev/sdc: 30031250 sectors, 14.3 GiB
> Model: Ultra USB 3.0   
> Sector size (logical/physical): 512/512 bytes
> Disk identifier (GUID): C657C0AF-3FE2-4152-8BF1-CE3CCA9F3541
> Partition table holds up to 128 entries
> Main partition table begins at sector 2 and ends at sector 33
> First usable sector is 34, last usable sector is 30031216
> Partitions will be aligned on 2048-sector boundaries
> Total free space is 4061 sectors (2.0 MiB)

> Number  Start (sector)    End (sector)  Size       Code  Name
>    1            2048         2048000   999.0 MiB   0700  Microsoft basic data
>    2         2050048        30031216   13.3 GiB    0700  Microsoft basic data

w
> Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!
> Do you want to proceed? (Y/N): y
q
  1. Format first partition as FAT32 and second as NTFS:
sudo mkfs.fat -F32 /dev/sdc1
sudo mkfs.ntfs -Q  /dev/sdc2
  1. Mount new USB partitions to temporary directories in your home:
mkdir ~/tmp-win10-fat-usb-drive
mkdir ~/tmp-win10-ntfs-usb-drive
sudo mount /dev/sdc1 ~/tmp-win10-fat-usb-drive
sudo mount /dev/sdc2 ~/tmp-win10-ntfs-usb-drive
  1. Download Windows installation ISO, create new temporary directory in your home and mount it there:
mkdir ~/tmp-win10-iso-mnt
sudo mount Win10_1809Oct_English_x64.iso ~/tmp-win10-iso-mnt
  1. Copy following files with from mounted ISO to FAT32 formatted USB drive (basically copy everything besides sources/ but include sources/boot.wim):
sudo cp ~/tmp-win10-iso-mnt/* ~/tmp-win10-fat-usb-drive/
sudo cp -r ~/tmp-win10-iso-mnt/boot ~/tmp-win10-fat-usb-drive/
sudo cp -r ~/tmp-win10-iso-mnt/efi ~/tmp-win10-fat-usb-drive/
sudo cp -r ~/tmp-win10-iso-mnt/support ~/tmp-win10-fat-usb-drive/
sudo mkdir ~/tmp-win10-iso-mnt/sources ~/tmp-win10-fat-usb-drive/
sudo cp ~/tmp-win10-iso-mnt/sources/boot.wim ~/tmp-win10-fat-usb-drive/sources
  1. Copy everything from mounted ISO to NTFS formatted USB drive:
sudo cp -rT ~/tmp-win10-iso-mnt/ ~/tmp-win10-ntfs-usb-drive/
  1. Unmount Windows ISO and both USB partitions and remove temporary directories:
sudo umount ~/tmp-win10-iso-mnt/ ~/tmp-win10-usb-fat-drive/ ~/tmp-win10-usb-ntfs-drive/
rmdir ~/tmp-win10-iso-mnt/ ~/tmp-win10-usb-drive/
  1. Insert USB drive to new computer and boot from it.

Solution 3

I've used woeusb on Ubuntu the following way (Warning: this will overwrite your whole partition table!):

sudo woeusb --tgt-fs NTFS --device Win10_1809Oct_Hungarian_x64.iso /dev/sdc

If you encounter this error message:

Partition is still detected after wiping all signatures, this indicates that the drive might be locked into readonly mode due to end of lifespan.

do the following: sudo fdisk /dev/sdc, and choose d and then finally w.

(Source: https://github.com/slacka/WoeUSB/issues/219.)  After this, try again to run the above command.

Anyway, with this method woeusb created a gpt partition table with two partitions:

partition      file system    label          size          flags
----------------------------------------------------------------
/dev/sdc1      nfts           Windows USB     57.00 GiB
/dev/sdc2      fat16          UEFI_NTFS      512.00 KiB    lba
unallocated                                    4.00 MiB

Finally, all I had to do is to put the boot flag with gparted for the /dev/sdc2 partition (alongside lba).

This way, I could sucessfully boot in UEFI mode and install Windows 10 from my USB stick.

Solution 4

I did some search, and found a perfect script: windows2usb.

Since woeusb doesn't support UEFI, this tool supports BIOS and UEFI(with rufus driver), FAT32 and NTFS.

Update: If the NTFS driver in windows2usb fails for you, you may also try ventoy. It's easier to use if you have multiple OS images in one USB stick.

Solution 5

Try using Rufus with Wine.

Regards.

Share:
61,960

Related videos on Youtube

Victor Aurélio
Author by

Victor Aurélio

Updated on September 18, 2022

Comments

  • Victor Aurélio
    Victor Aurélio over 1 year

    How can I create a bootable Windows 10 USB drive from Linux ?

    Please note:

    • WinUSB doesn't work with Windows 10.
    • UNetbootin doesn't work either.
    • dd method didn't work as well.

    Beside this, I've tried creating a GPT partition table and one partition of type ef00 and formatted as fat32, and then copied all ISO contents to it. It boots OK, but when I go to start installation it shows the prompt for media dialog.

    Update

    Another try:

    1. Created a GPT
    2. Created a FAT32 at end of drive of 50 MB
    3. Created NTFS at remaining space
    4. Put UEFI:NTFS on FAT32
    5. Copied ISO content to NTFS

    The installation starts ok, but at start of progress shows error 0xc0000005 (if i remember correctly).

  • Victor Aurélio
    Victor Aurélio over 8 years
    The problem is that soon as the installer begin the process it throws an error, described in the question.
  • Pingers
    Pingers over 8 years
    you've tried with a different iso? I would suspect my source. Grab the latest one as described in my answer. If you boot with that on your usb, and you still get an error, I would start to question hardware...
  • Victor Aurélio
    Victor Aurélio over 8 years
    yes I've tried it too...
  • Victor Aurélio
    Victor Aurélio almost 8 years
    This isn't a "linux" solution.
  • Victor Aurélio
    Victor Aurélio almost 8 years
    For those using gdisk: instead of creating a ef00 create a 0700 partition.
  • antonioalopezfernandez
    antonioalopezfernandez almost 8 years
    But it works OK.
  • akhmed
    akhmed almost 7 years
    Rufus is open source. Quick, efficient, works on Linux. Thanks!
  • gpanda
    gpanda almost 6 years
    set flag "msftdata"(not "boot"), thank you @Feretj, you save my life
  • Victor Aurélio
    Victor Aurélio over 5 years
    Some firmwares doesn't check for boot files in a NTFS partition, someone correct me if m i wrong.
  • mevdschee
    mevdschee about 5 years
    You can compress install.wim to be smaller than 4GB using "wimtools" and "solid" compression level. This way you can simply use FAT32, see tqdev.com/2019-cannot-copy-windows-10-install-wim
  • Benjamin Marwell
    Benjamin Marwell almost 5 years
    You cannot put all data onto a FAT32 drive as of June 2019. The latest update contains a windows.wim which is larger than 4.1 GiB.
  • That Brazilian Guy
    That Brazilian Guy almost 5 years
    Commenting just to remind myself to upvote if it works.
  • Rob
    Rob over 4 years
    You can significantly speed up the formatting of the stick when you skip filling it with zeros first: sudo mkfs.ntfs -Q /dev/sdc1
  • testUser12
    testUser12 over 4 years
    I came here to say that I too was experiencing the issue described by @VictorAurélio - my laptop would not boot an NTFS partition correctly formatted and flagged with gdisk. I resolved the issue by using FAT32 and the command ` wimlib-imagex optimize install.wim --solid` described in the article linked by @mevdschee
  • mevdschee
    mevdschee over 4 years
    @Ben You can when you compress the install.wim file using dism or wimtools, see tqdev.com/2019-cannot-copy-windows-10-install-wim.
  • DavidPostill
    DavidPostill about 4 years
    Please do not post the same answer to multiple questions. If the same information really answers both questions, then one question (usually the newer one) should be closed as a duplicate of the other. You can indicate this by voting to close it as a duplicate or, if you don't have enough reputation for that, raise a flag to indicate that it's a duplicate. Otherwise tailor your answer to this question and don't just paste the same answer in multiple places.
  • XavierStuvw
    XavierStuvw about 4 years
    The bottleneck is that the ISO files now contains too large files for fat32 to accept them. This is the case for Wndows10 1909 for example.
  • XavierStuvw
    XavierStuvw about 4 years
    @mevdschee I would warmly encourage you to promote your remark to an answer. It is a sensible option, and it can hardly be spotted tucked under one of several other answers. That could solve the bottleneck of using a fat32 file system and deal with recent installation files that are too big for it.
  • XavierStuvw
    XavierStuvw about 4 years
    It does work. The target-filesystem option --tgt-fs NTFS is necessary because the files in the new Windows installations are larger than 4GB and cannot be supported by a fat32 file systems. fat32 file systems are essential for UEFI boot loading. However, woeusb works around this under hood and produces a USB immediately recognized with Secure Boot disabled (and provided the device's boot loader has the USB drive suitably high of its priority list). I did not need to add the boot flag to any partition.
  • Darragh
    Darragh about 4 years
    for anyone that lands on this in the future, be aware you need to unmont the partitions but not the disk, e.g /dev/sdb1 , /dev/sdb2 once thats done the application will work, /dev/sdb doesn't need to be umounted. If one uses the gnome file manager it will unmount the entire disk and woeusb won't find it. also you need an active internet connection as the uefi-ntfs.img file is downloaded from github, it depends on the Rufus project for that.
  • mevdschee
    mevdschee about 4 years
    @XavierStuvw thank you for your kind words, but I don't have enough reputation on this site to do that. I hope somebody else will answer it with that content.
  • XavierStuvw
    XavierStuvw about 4 years
    @mevdschee Please do create a new answer of your own. There is no reputation threshold for that.
  • mevdschee
    mevdschee about 4 years
    @XavierStuvw yes there is.. as this is a "Highly active question" and is protected.. you need 10 rep points.
  • XavierStuvw
    XavierStuvw about 4 years
    @mevdschee Sorry, I had overlooked this. I encourage you to keep this improvement in mind for when you reach the necessary credentials. Happy hacking on SE!
  • Lirt
    Lirt about 4 years
    Agree @mevdschee, you should add new answer. I want to keep this answer to be doable without any external utilities on any linux distribution. Thanks for idea with -Q @Alex, I included it in answer.
  • mevdschee
    mevdschee about 4 years
    @Lirt, you may add that if this method does not work (many EFI firmwares do not support NTFS), then you may create two partitions (one FAT32 and one NTFS) as described here: tqdev.com/2019-cannot-copy-windows-10-install-wim (no external tools needed)
  • John McGehee
    John McGehee about 4 years
    I used Rufus on Windows 10 and I can confirm that Rufus does solve this problem...on Windows, however.
  • knoftrix
    knoftrix about 4 years
    I doubt if Rufus will work with wine, according to Rufus developer wine is missing low level API for USB detection and there are many problems. See github.com/pbatard/rufus/issues/1411#issuecomment-554811956
  • JorgeeFG
    JorgeeFG over 3 years
    I tried this and didn't work (and a lot of other things like exFat format for newer Windows 10 isos) So in the end I gave up, went to Windows and downloaded their Media Creator Tool. After that I checked and the USB worked. I checked the flags and they are boot and lba
  • Hugh Perkins
    Hugh Perkins over 2 years
    variant B worked for me :) (tried soooo many other methods first... :O )