Friday, August 14, 2020

MacOS: create a bootable Windows 10 install USB drive

Sources: 

Identify USB device

jerome@centurion ~ % diskutil list

This shows the USB drive is using /dev/disk4 in my case.

Format USB drive

jerome@centurion ~ % diskutil eraseDisk MS-DOS "WIN10" MBR /dev/disk4

NB: It is crucial to use MBR and not GPT in order to avoid the infamous error "Windows could not prepare the computer to boot into the next phase of installation. To install Windows, restart the installation." during setup on my laptop after that.

Mount Windows 10 ISO

jerome@centurion ~ % hdiutil mount ~/Desktop/Windows10.iso

This will create /Volumes/CCCOMA_X64FRE_EN-US_DV9

Copy Windows files to USB drive

One file of the installation, install.esd, is more than 4 GB, which is not supported on FAT32.

So, copy all files but this one.

jerome@centurion ~ % rsync -vha --exclude=sources/install.esd /Volumes/CCCOMA_X64FRE_EN-US_DV9/ /Volumes/WIN10

In order to copy install.esd, we will have to split it with wimlib, so install wimlib first.

jerome@centurion ~ % brew install wimlib                                                              

Then, split install.esd into 2 files of less than 4 GB, and copy them to the USB volume.

jerome@centurion ~ % wimlib-imagex split /Volumes/CCCOMA_X64FRE_EN-US_DV9/sources/install.esd /Volumes/WIN10/sources/install.swm 4000
[ERROR] Splitting of WIM containing solid resources is not supported.
        Export it in non-solid format first.
ERROR: Exiting with error code 68:
       The requested operation is unsupported.

install.esd is actually a solid archive compressed with LZMS, and apparently it cannot be split. So, export it to non-solid WIM as advised. For this, follow WIMEXPORT

jerome@centurion ~ % wimexport 
/Volumes/CCCOMA_X64FRE_EN-US_DV9/sources/install.esd all 
~/Desktop/install.wim --compress=LZX            
Using LZX compression with 12 threads
Archiving file data: 13 GiB of 13 GiB (100%) done

 Then try splitting again.

jerome@centurion ~ % wimlib-imagex split ~/Desktop/install.wim /Volumes/WIN10/sources/install.swm 4000
Writing "/Volumes/WIN10/sources/install.swm" (part 1 of 2): 0 MiB of 6037 MiB (0%) written
Writing "/Volumes/WIN10/sources/install2.swm" (part 2 of 2): 3997 MiB of 6037 MiB (66%) written
Finished writing split WIM part 2 of 2
 

Then eject WIN10, and you're good to go to install Windows 10 by booting from the USB drive.