# Install Windows 11 (UEFI) via USB 3.0 Drive

Installing Windows 11 in UEFI mode from a USB 3.0 drive proves to be rather painful but luckily sticking together a few different workarounds for various issues sourced from all over the internet makes it possible - though rather convoluted...

---

## Problem 1: Creating the bootable USB drive: FAT32 File System limit
Right off the bat, creating the drive manually *instantly *presents a problem; the Windows Imaging file for installation, `install.wim` is too large (> 4GiB) for the FAT32 partition that the installation media boots from so a direct image cannot be made.

Therefore, the image file needs to be split up into multiple split .wim files (SWMs). On macOS this can be done with `wimlib` as follows (for other systems there are undoubtably guides available and on Windows the Media Creation tool can presumably be used):

> _See below for an explanation._

```bash
open windows.iso    # Replace windows.iso with the name of the installation ISO.
cd /Volumes/CCCOMA_X64FRE_EN-US_DV9    # Replace with the name of the mounted volume from the ISO.
rsync -avh --progress --exclude=sources/install.wim /Volumes/CCCOMA_X64FRE_EN-US_DV9/ /Volumes/WINDOWS

# If you don't already have it installed, you will need to install wimlib with `brew install wimlib`
wimlib-imagex split /Volumes/CCCOMA_X64FRE_EN-US_DV9/sources/install.wim /Volumes/WINDOWS/sources/install.swm 3800

sudo diskutil unmountDisk /Volumes/WINDOWS
sudo diskutil unmountDisk /Volumes/CCCOMA_X64FRE_EN-US_DV9
```

1. Format your USB drive to have a FAT32 partition with GPT (GUID Partition Table) in Disk Utility. This guide assumes you named the drive `WINDOWS`.
2. Mount the Windows Installation ISO with `open windows.iso` in a Terminal window, where `windows.iso` is the Windows Installation ISO downloaded from Microsoft.
3. Using Terminal, switch to the mounted ISO, which will be something like `/Volumes/CCCOMA_X64FRE_EN-US_DV9` (`ls /Volumes` will allow you to check, but this guide will assume the aforementioned name).
4. Copy the contents of the Windows Installation ISO (excluding the `install.wim` file to the USB drive): `rsync -avh --progress --exclude=sources/install.wim /Volumes/CCCOMA_X64FRE_EN-US_DV9/ /Volumes/WINDOWS`
5. Install `wimlib` with [Homebrew](https://brew.sh/) - a tool used to split the WIM file: `brew install wimlib`
6. Split the image with `wimlib` (this should yield two files, named similarly to `install.wim` and `install1.wim` on the USB drive): `wimlib-imagex split /Volumes/CCCOMA_X64FRE_EN-US_DV9/sources/install.wim /Volumes/WINDOWS/sources/install.swm 3800`
7. Finally unmount both the USB drive and the ISO file: `sudo diskutil unmountDisk /Volumes/WINDOWS` and `sudo diskutil unmountDisk /Volumes/CCCOMA_X64FRE_EN-US_DV9`

...and with that you're ready to begin attempting to install Windows.

## Problem 2: Installing Windows from the USB drive
With this done, I encountered another issue - USB 3.0 flash drives seem to cause problems with the Windows Setup wizard's checks as to whether Windows can be installed despite selection of a valid partition. (Presumably because Windows is unable to tell if a partition/volume belongs to a removable drive or not without the necessary drivers.)

I eventually managed to workaround this issue by performing installation manually with the `DISM` (Deployment Image Servicing and Management) tool included in the Windows Installation media.


1. Boot your Windows Installation Media in UEFI mode, enter your language and region settings and click 'Install Windows'.
2. Remove all the partitions on the target drive and click 'New' to create a new partition to install Windows. (Or, alternatively, tweak as desired ensuring that there is a FAT32 EFI system partition of at least 128MiB and an NTFS Windows installation partition of at least 52 GiB.)
3. If you are able to select the Windows installation partition and click 'Next', do so and complete setup normally. Otherwise, continue following this section.


### 2.1: Mounting the target installation disk
1. Press <kbd>Shift</kbd> + <kbd>F10</kbd> to open a Command Prompt window and enter `diskpart`.
2. Identify the target disk to install Windows onto with `list disk`
3. Select the target disk with `sel disk 0` (where `0` is the disk number from `list disk`).
4. Identify the partition numbers on the target disk with `list part`.
5. Select the EFI boot partition (FAT32-formatted and 128MiB in size) with `sel part 1` (where `1` is the partition number from `list part`).
6. Assign the letter `S:` with `assign letter=s`.
7. Select the Windows installation partition (NTFS formatted and at least 52GiB in size) with `sel part 3` (where `3` is the partition number from `list part`).
8. Assign the letter `W:` with `assign letter=w`.
9. Exit `diskpart` with `exit`

### 2.2: Installing Windows with [DISM (Deployment Image Servicing and Management)](https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/what-is-dism?view=windows-11)
1. List the editions contained on the Windows Installation USB with `dism` and identify the index of the edition you wish to install:
    ```powershell
    dism /Get-WimInfo /WimFile:X:\sources\install.swm
    ```
2. Perform the Windows installation by applying the `install*.swm` image(s) with `dism` (where `X:\` is the Windows Installation USB and where the `/Index` - in this case `4` is the edition index identified from before):
    ```powershell
    dism /Apply-Image /ImageFile:X:\sources\install.swm /SWMFile:X:\sources\install*.swm /ApplyDir:W: /Index:4
    ```
3. Wait for the operation to finish. If this was successful you should see "The operation completed successfully." printed once the progress bar reaches 100%.
4. Add the boot files to the EFI boot partition and add a boot entry using `bcdboot`:
    ```powershell
    bcdboot W:\Windows /S S: /F ALL
    ```
5. Wait for the operation to finish. If this was successful you should see "Boot files successfully created."

...once you've completed the above you can close the Command Prompt window by typing `exit`, then click the close button on the installer and, again, click close (now on the Install/Repair screen) which should prompt you to say that continuing may cause the machine to reboot. Confirm this (and if the machine does not reboot, hold down the power button to shut down your machine and manually power it back on). As soon as the machine shuts down, remove the USB installation drive.

When the machine boots, you should be booted into your new Windows installation.

## Problem 3: Activation
Even after all of the above, in my case I ended up with an 'S version' of Windows and the Activation section of Settings was both failing to load and missing the option to exit S mode.

Pressing <kbd>Win</kbd> + <kbd>R</kbd> and entering `cmd` launched a dialog that then allowed me to exit S mode.

After which, launching `cmd` and using the `slmgr /ipk <product key>` command, where `<product key>` is your Windows product activation key to manually install the product key, followed by restarting the machine allowed me to activate the machine.

## Wrap up
It's unclear to me why exactly these complications have not been ironed out (perhaps with the exception of Problem 3) and hopefully they'll be fixed in future but I believe it's useful to have the steps noted down somewhere in case they're needed.

With the above, you should now have Windows 11 successfully installed and activated. If you notice any mistakes or oversights please be sure to leave a comment.

## Sources
- https://alexlubbock.com/bootable-windows-usb-on-mac
- https://gist.github.com/bmatcuk/fda5ab0fb127e9fd62eaf43e845a51c3
- https://www.trishtech.com/2021/10/how-to-clean-install-windows-11-using-dism-on-any-hdd-ssd/amp/

