Skip to content

Instantly share code, notes, and snippets.

@juanpmarin
Last active May 1, 2024 17:42
Show Gist options
  • Save juanpmarin/c3e766378987572fa3442e597894aab2 to your computer and use it in GitHub Desktop.
Save juanpmarin/c3e766378987572fa3442e597894aab2 to your computer and use it in GitHub Desktop.
Windows 11 booteable usb from linux
#!/bin/sh
set -ex
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Please use sudo or run it as a superuser."
exit 1
fi
usb_device="/dev/sda"
boot_partition="${usb_device}1"
install_partition="${usb_device}2"
iso_file="Win11_23H2_English_x64v2.iso"
iso_mnt_path="./mnt/iso"
boot_mnt_path="./mnt/boot"
install_mnt_path="./mnt/install"
parted -s $usb_device mklabel gpt
parted -s $usb_device mkpart BOOT fat32 0% 1GiB
parted -s $usb_device mkpart INSTALL ntfs 1GiB 100%
mkfs.vfat -n BOOT $boot_partition
mkfs.ntfs --quick -L INSTALL $install_partition
mkdir -p "$iso_mnt_path"
mkdir -p "$boot_mnt_path"
mkdir -p "$install_mnt_path"
mount -o loop $iso_file $iso_mnt_path
mount $boot_partition $boot_mnt_path
rsync -r --info=progress2 --exclude sources --delete-before "$iso_mnt_path/" "$boot_mnt_path/"
mkdir "$boot_mnt_path/sources"
cp "$iso_mnt_path/sources/boot.wim" "$boot_mnt_path/sources/"
umount $boot_mnt_path
mount -t ntfs-3g -o big_writes $install_partition $install_mnt_path
rsync -r --info=progress2 --delete-before "$iso_mnt_path/" "$install_mnt_path/"
echo -e "[Channel]\n_Default\n[VL]\n0\n" > "$install_mnt_path/sources/ei.cfg"
umount $install_mnt_path
umount $iso_mnt_path
rm -rf ./mnt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment