Skip to content

Instantly share code, notes, and snippets.

@robertkirkman
Last active November 9, 2022 04:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertkirkman/d7c70fae2d5c6aa6ebb090387043687c to your computer and use it in GitHub Desktop.
Save robertkirkman/d7c70fae2d5c6aa6ebb090387043687c to your computer and use it in GitHub Desktop.
How to install Windows 11 on any PC without TPM
#!/bin/bash
# forked from https://unix.stackexchange.com/a/635839/361859
# dependencies:
# GNU/Linux build environment with sudo access and the following packages or equivalent:
# apt-get install build-essential wget dumpet
# a Windows 10 installation image
# a Windows 11 installation image
# usage: edit paths to match your situation, then execute
# paths (no closing '/')
ISO_IMAGE_W10="Win10_21H2_English_x64.iso"
ISO_IMAGE_W11="Win11_English_x64v1.iso"
ISO_IMAGE_OUT="Win11_noTPM.iso"
MOUNTPOINT_DIR="mountdir"
WORKING_DIR="workdir"
CDRTOOLS_DIR="cdrtools"
STARTING_DIR=$(pwd)
# remove and recreate directories
rm -rf $WORKING_DIR
rm -rf $MOUNTPOINT_DIR
rm -rf $CDRTOOLS_DIR
mkdir $WORKING_DIR
mkdir $MOUNTPOINT_DIR
mkdir $CDRTOOLS_DIR
# cdrtools is in licensing hell.
# you don't care because you are installing Windows, which is licensing Satan.
cd $CDRTOOLS_DIR
CDRTOOLS_TAR=cdrtools-3.02a09.tar.bz2
wget "https://downloads.sourceforge.net/cdrtools/${CDRTOOLS_TAR}"
tar -xf $CDRTOOLS_TAR
rm $CDRTOOLS_TAR
cd cdrtools*
export GMAKE_NOWARN=true
make
MKISOFS=$(pwd)/$(find mkisofs/OBJ -name mkisofs)
cd $STARTING_DIR
# mount the Win10 ISO and copy the Win10 ISO image contents to the working directory
sudo mount -r -t udf $ISO_IMAGE_W10 $MOUNTPOINT_DIR
cp -r "${MOUNTPOINT_DIR}/"* $WORKING_DIR
chmod -R 755 $WORKING_DIR
# unmount the Win10 ISO image and mount the Win11 image in its place
sudo umount $MOUNTPOINT_DIR
sudo mount -r -t udf $ISO_IMAGE_W11 $MOUNTPOINT_DIR
# replace the install.wim archive in the working directory with the one from the Win11 ISO
cp "${MOUNTPOINT_DIR}/sources/install.wim" "${WORKING_DIR}/sources"
sudo umount $MOUNTPOINT_DIR
# get the boot image LBA from the Win10 ISO
# should be an integer number following the second 'Load LBA'
LOAD_LBA=$(dumpet -i $ISO_IMAGE_W10 | tail -n1 | sed 's@^[^0-9]*\([0-9]\+\).*@\1@')
dd if=$ISO_IMAGE_W10 bs=2048 skip=$LOAD_LBA count=1 > "${WORKING_DIR}/efi/win_efi_boot.img"
# get the boot.img and check the right file size
# the below should detect a 'DOS/MBR boot sector' and sectors size should be 2880
# which would mean 2880 * 512 / 2048 = 720
SECTORS=$(file "${WORKING_DIR}/efi/win_efi_boot.img" | grep -Eo 'sectors *[0-9]+' | grep -o '[0-9]*')
LOAD_COUNT=$(( $SECTORS * 512 / 2048 ))
dd if=$ISO_IMAGE_W10 bs=2048 skip=$LOAD_LBA count=$LOAD_COUNT > "${WORKING_DIR}/efi/win_efi_boot.img"
# build the image using schilly cdrtools mkisofs
$MKISOFS \
-no-emul-boot \
-b boot/etfsboot.com \
-boot-load-seg 0 \
-boot-load-size 8 \
-eltorito-alt-boot \
-no-emul-boot \
-b efi/win_efi_boot.img \
-boot-load-size 1 \
-iso-level 4 \
-UDF \
-o $ISO_IMAGE_OUT \
$WORKING_DIR/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment