This Attune Blueprint extracts the essential WinPE files from a full 5GB Windows installation ISO, reducing the ISO file size to less than 500MB.
The steps in the Blueprint are performed on macOS or Linux.
Two WinPE ISOs are created, one for BIOS boot and another for UEFI boot.
Contents
WinPE Essentials Extraction on macOS or Linux
Step 1 - Cleanup temporary build files for WinPE plain ISO creation on macOS or Linux
Step 1.1 - Unmount WinPE UEFI Mount on macOS or Linux
Step 1.2 - Unmount Windows ISO on macOS or Linux
Step 1.3 - Set Write Permissions to winpe_uefi_staging on macOS or Linux
Step 1.4 - Delete the build directory on macOS or Linux
Step 2 - Deploy Windows DVD ISO to build-winpe-iso directory on macOS or Linux
Step 3 - Extract Windows boot.img from build-winpe-iso directory for BIOS build on macOS or Linux
Step 4 - Mount Win Server DVD ISO on macOS or Linux
Step 5 - Confirm mkwinpeimg is installed
Step 6 - Extract WinPE ISO from winimg Directory on macOS or Linux
Step 7 - Extract WinPE ISO to Staging Folder on build-winpe-iso on macOS or Linux
Step 8 - Copy Files for mkwinpeimg Compatibility to WinPE Staging on macOS or Linux
Step 9 - Copy boot.img to winpe_staging for BIOS build on macOS or Linux
Step 10 - Delete setup.exe from boot.wim on macOS or Linux
Step 11 - Optimize boot.wim on macOS or Linux
Step 12 - Copy Windows EFI Files to WinPE UEFI Staging on macOS or Linux
Step 13 - Create winpe_plain_bios.iso from winpe_staging on macOS or Linux
Step 14 - Change Ownership of winpe_staging Directory to attune on macOS or Linux
Step 15 - Create winpe_plain_uefi.iso from winpe_staging on macOS or Linux
Step 16 - Cleanup temporary build files for WinPE plain ISO creation on macOS or Linux
Step 16.1 - Unmount WinPE UEFI Mount on macOS or Linux
Step 16.2 - Unmount Windows ISO on macOS or Linux
Step 16.3 - Set Write Permissions to winpe_uefi_staging on macOS or Linux
Automate This
Use the Attune GUI for your Scripts
You've automated: WinPE Essentials Extraction on macOS or Linux
Get the most out of automation with our get started videos, product demonstrations, and more.
The following steps will guide you through the manual process.
Unmount any existing WinPE or Windows ISO mounts.
Set appropriate write permissions to enable modifications in the working directory.
Delete any remaining build files.
For a linux system, the umount command detaches the mentioned file system
from the file hierarchy.
For a macOS system, the hdiutil detach command detaches a disk image and
terminates any associated processes.
Connect via ssh:
ssh {automationworkerlinuxuserroot}@{automationworkerlinuxnode}
Execute the following script:
MOUNT_PATH="{automationWorkerLinuxBaseDirectory}/build-winpe-iso/uefi_mount"
if [[ -f /etc/redhat-release ]] || [[ -f /etc/lsb-release ]] || [[ -f /etc/debian_version ]]
then
if df -h | grep --ignore-case --quiet "$(echo ${MOUNT_PATH}/*)"
then
umount --verbose "$(echo ${MOUNT_PATH}/*)"
chmod -R a+w "${MOUNT_PATH}"
else
echo "${MOUNT_PATH} is not mounted. Skipping."
fi
elif [[ "Darwin" == "$(uname)" ]]
then
if [[ $(find ${MOUNT_PATH}/* 2> /dev/null | wc -l) -gt 10 ]]
then
hdiutil detach "$(echo ${MOUNT_PATH}/*)"
else
echo "${MOUNT_PATH} is not mounted. Skipping."
fi
else
echo "Unsupported operating system."
exit 1
fi
For a linux system, the umount command detaches the mentioned file system
from the file hierarchy.
For a macOS system, the hdiutil detach command detaches a disk image and
terminates any associated processes.
Execute the following script:
MOUNT_PATH="{automationWorkerLinuxBaseDirectory}/build-winpe-iso/winimg"
if [[ -f /etc/redhat-release ]] || [[ -f /etc/lsb-release ]] || [[ -f /etc/debian_version ]]
then
if df -h | grep --ignore-case --quiet "$(echo ${MOUNT_PATH}/*)"
then
umount --verbose "$(echo ${MOUNT_PATH}/*)"
chmod -R a+w "${MOUNT_PATH}"
else
echo "${MOUNT_PATH} is not mounted. Skipping."
fi
elif [[ "Darwin" == "$(uname)" ]]
then
if [[ $(find ${MOUNT_PATH}/* 2> /dev/null | wc -l) -gt 10 ]]
then
hdiutil detach $(echo ${MOUNT_PATH}/*)
else
echo "${MOUNT_PATH} is not mounted. Skipping."
fi
else
echo "Unsupported operating system."
exit 1
fi
The chmod -R a+w command modifies the permissions recursively for a directory
and its contents.
-R stands for recursive.
a stands for all.
+ adds permissions.
w stands for write.
This action is needed to delete the build directory.
Execute the following script:
DIR="{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
if [[ ! -d ${DIR} ]]
then
echo "Directory ${DIR} does not exist. Skipping."
else
cd "${DIR}"
UEFI_STAGING_DIR="winpe_uefi_staging"
if [[ ! -d ${UEFI_STAGING_DIR} ]]
then
echo "Directory does not exist. Skipping."
else
echo "Before"
ls -lh
chmod -R a+w "${UEFI_STAGING_DIR}"
echo "After"
ls -lh
fi
fi
Delete any remaining build files.
Connect via ssh:
ssh {automationworkerlinuxuser}@{automationworkerlinuxnode}
Execute the following script:
DIR="{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
if [ -d ${DIR} ]
then
rm -rf ${DIR}
echo "Removed ${DIR}"
else
echo "No directory to remove."
fi
You can extract necessary files from a Windows installation ISO to create a WinPE ISO. I've selected Win2019 to extract the WinPE ISO from.
Windows 10 Workstation ISO is not recommended as its WinPE has compatibility issues with the drvload-ing the vioscsi.inf oVirt driver.
The WinPE from Win2016 and Win2022 has not been tested for vioscsi.inf
compatibility.
Download from https://www.microsoft.com/en-us/evalcenter/download-windows-server-2019.
Copy the File(s) Win201_ISO.tar to the target node.
Deploy the File(s) here:
{automationWorkerLinuxBaseDirectory}/build-winpe-iso, relative to the home directory
Set the shell option nocaseglob so that filenames will be matched regardless
of their case.
Set the variable F to the list of filenames that end with
.iso in the current directory.
The isoinfo -d -i $F command displays the details of the ISO image specified
by $F.
grep Bootoff filters this output to only include the line containing
"Bootoff," which presumably contains information about the boot image offset.
cut -c21- extracts the characters starting from the 21st character of the
line, which is assumed to be the offset value.
The result is stored in the variable OFFSET.
The dd command is used for low-level copying of raw data.
if=$F specifies the input file, which is the ISO image.
of=boot.img sets the output file to boot.img.
bs=2048 sets the block size to 2048 bytes.
This is often the size of a sector in ISO9660 file systems.
count=8 means only read 8 blocks (based on the block size).
skip=$OFFSET skips a number of blocks at the beginning of the input file
before starting to copy, based on the calculated OFFSET.
Execute the following script:
cd {automationWorkerLinuxBaseDirectory}/build-winpe-iso
# Case insensitve globbing
shopt -s nocaseglob
# Set the filename of the ISO
F=$(ls *.iso)
# Get the Boot image offset
OFFSET=`isoinfo -d -i $F | grep Bootoff | cut -c21-`
# Extract the boot.img
dd if=$F of=boot.img bs=2048 count=8 skip=$OFFSET
For a linux system, the mount command attaches a file system found on a
device.
For a macOS system, the hdiutil attach command attaches a disk image as a
device. -mountroot mounts volumes on a subdirectory.
Connect via ssh:
ssh {automationworkerlinuxuserroot}@{automationworkerlinuxnode}
Execute the following script:
cd "{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
FOLDER="winimg"
mkdir -p "${FOLDER}"
# Case insensitve globbing
shopt -s nocaseglob
ISO=$(ls *SERVER*.iso)
if [[ -f /etc/redhat-release ]] || [[ -f /etc/lsb-release ]] || [[ -f /etc/debian_version ]]
then
mkdir -p "${FOLDER}/CD"
mount --options "uid={automationWorkerLinuxUser.user}" \
--options "gid={automationWorkerLinuxUser.user}" \
"${ISO}" "${FOLDER}/CD"
elif [[ "Darwin" == "$(uname)" ]]
then
hdiutil attach ${ISO} -mountroot ${FOLDER}
else
echo "Unsupported operating system."
exit 1
fi
Execute the following script:
if [[ -f /etc/redhat-release ]] || [[ -f /etc/lsb-release ]]
then
if which mkwinpeimg >/dev/null; then
echo "mkwinpeimg is installed."
else
echo "mkwinpeimg is not installed."
dnf -y install wimlib wimlib-utils fuse
fi
elif [[ -f /etc/debian_version ]]
then
if which mkwinpeimg >/dev/null; then
echo "mkwinpeimg is installed."
else
echo "mkwinpeimg is not installed."
apt-get -y install wimlib wimlib-utils fuse
fi
elif [[ "Darwin" == "$(uname)" ]]
then
if which mkwinpeimg >/dev/null; then
echo "mkwinpeimg is installed."
else
echo "mkwinpeimg is not installed."
brew -y install wimlib
fi
else
echo "Unsupported operating system."
exit 1
fi
Extracts the WinPE image from Windows Server 2019 boot.wim by default at index 2.
Writes this out to winpe.iso.
This is the exact copy of Windows Server 2019's WinPE image which by default will run setup.exe on the Windows Desktop ISO at a higher priority than running startnet.cmd.
Connect via ssh:
ssh {automationworkerlinuxuser}@{automationworkerlinuxnode}
Execute the following script:
cd "{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
if [[ "Darwin" == "$(uname)" ]]
then
sed 's/getopt -o.*/getopt iso,windows-dir -- $*); then /g' $(which mkwinpeimg) \
| sed '/-- "$@" /d' \
| sed '/,help,version/d' \
| sed 's/eval set -- "$options"/eval set "$options"/g' \
> mkwinpeimg
which sed
sed -i 's/while \[ $# -gt 0 \]; do/echo $*;while [ $# -gt 0 ]; do echo $1/g' mkwinpeimg
chmod +x mkwinpeimg
export PATH=".:$PATH"
fi
mkwinpeimg --iso --windows-dir $(echo winimg/*) -- winpe.iso
Extract winpe.iso to a winpe_staging folder on macOS or Linux Worker.
Execute the following script:
cd {automationWorkerLinuxBaseDirectory}/build-winpe-iso
BIOS=winpe_bios_staging
UEFI=winpe_uefi_staging
mkdir -p "${BIOS}"
mkdir -p "${UEFI}"
7z x winpe.iso -o"${BIOS}"
7z x winpe.iso -o"${UEFI}"
Copy the boot/etfsboot.com files from the Windows ISO to WinPE's BOOT
folder.
Connect via ssh:
ssh {automationworkerlinuxuserroot}@{automationworkerlinuxnode}
Execute the following script:
cd "{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
cp -v "$(find winimg -type f -name etfsboot.com)" "winpe_bios_staging/BOOT"
cp -v "$(find winimg -type f -name etfsboot.com)" "winpe_uefi_staging/BOOT"
Moves boot.img to the winpe_staging folder.
mkisofs requires boot.img to make a BIOS bootable ISO.
Execute the following script:
cd "{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
cp -v boot.img winpe_bios_staging
The winpe_staging directory will be used to recreate a WinPE BIOS ISO
designed to work with a Samba drive which contains the required setup.exe.
The wimupdate command modifies the specified image.
--command="delete /setup.exe" deletes setup.exe from the extracted
WinPE's boot.img.
Connect via ssh:
ssh {automationworkerlinuxuser}@{automationworkerlinuxnode}
Execute the following script:
cd {automationWorkerLinuxBaseDirectory}/build-winpe-iso
wimupdate winpe_bios_staging/SOURCES/BOOT.WIM --command="delete /setup.exe"
wimupdate winpe_uefi_staging/SOURCES/BOOT.WIM --command="delete /setup.exe"
Recompress all data in the WIM while optimizing it.
Execute the following script:
cd {automationWorkerLinuxBaseDirectory}/build-winpe-iso
wimoptimize winpe_bios_staging/SOURCES/BOOT.WIM --recompress
wimoptimize winpe_uefi_staging/SOURCES/BOOT.WIM --recompress
To boot WinPE on a UEFI-based system, the ISO needs to include a UEFI-compatible boot loader and related files. Without this UEFI support, the WinPE ISO might not be able to boot on modern UEFI-enabled hardware.
Execute the following script:
cd "{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
cp -rv "$(echo winimg/*/efi)" "winpe_uefi_staging"
The xorriso and mkisofs command is used to create a customised,
bootable ISO image from the contents of the winpe_staging directory.
The command includes various settings for bootability, file system types,
naming conventions, and compatibility options to ensure the ISO functions as
intended in various environments.
Let's break down the command and its options:
xorriso -as mkisofs runs xorriso in a mode that emulates mkisofs,
a linux command.
-b boot.img specifies boot.img as the boot image for a bootable ISO.
-no-emul-boot indicates that no disk emulation mode is used for the boot
image. This is typically used for bootable ISOs intended for systems that
can understand the ISO file system directly.
-c BOOT.CAT specifies the creation of a boot catalog (BOOT.CAT) in the
ISO image.
-iso-level 3 sets the compliance level for the ISO 9660 standard.
Level 3 allows for file names up to 207 characters in length and file
sizes larger than 2 GB.
-udf includes UDF (Universal Disk Format) file system in
addition to ISO 9660. UDF is often used for DVDs and newer
optical media formats and supports larger file sizes.
-joliet-long Enables the use of the Joliet file system extension
with support for longer file names.
-relaxed-filenames allows file names that do not strictly adhere to the
ISO 9660 standard, providing more flexibility.
-allow-limited-size permits the creation of ISO images that exceed the
size limitations of the ISO 9660 standard.
-J enables Joliet file system extensions for longer file names and
Unicode characters.
-full-iso9660-filenames allows using the full ISO 9660 file naming
rules without the usual length limitations.
-disable-deep-relocation disables the relocation of deep directory
trees, which can be necessary for certain boot scenarios.
-omit-version-number omits the version number from file names in the
ISO image.
-V sets the volume ID of the ISO image.
-o specifies the output path and filename for the created ISO image.
Execute the following script:
cd "{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
ISO_NAME="winpe_plain_bios.iso"
if [[ "Darwin" == "$(uname)" ]]
then
export PATH="${HOME}/Parallels/homebrew/bin:$PATH"
echo "Using $(which xorriso)"
xorriso -as mkisofs \
-b boot.img \
-no-emul-boot \
-c BOOT.CAT \
-iso-level 3 \
-joliet-long \
-relaxed-filenames \
-J \
-full-iso9660-filenames \
-disable-deep-relocation \
-omit-version-number \
-V "KS_WIN" \
-o "{automationWorkerLinuxBaseDirectory}/${ISO_NAME}" \
winpe_bios_staging
elif [[ -f /etc/redhat-release ]] || [[ -f /etc/lsb-release ]] || [[ -f /etc/debian_version ]]
then
mkisofs \
-b boot.img \
-no-emul-boot \
-c BOOT.CAT \
-iso-level 3 \
-udf \
-joliet-long \
-relaxed-filenames \
-allow-limited-size \
-J \
-full-iso9660-filenames \
-disable-deep-relocation \
-omit-version-number \
-V "KS_WIN" \
-o "{automationWorkerLinuxBaseDirectory}/${ISO_NAME}" \
winpe_bios_staging
else
echo "Unsupported operating system."
exit 1
fi
The id -gn command gets the primary group name of the specified user.
chown changes the ownership of the winpe_staging directory to the user
and group specified by the USER and GROUP variables.
-R makes the command recursive, applying to all files and subdirectories.
-v (verbose) means the command will display detailed output about what
it's doing.
Connect via ssh:
ssh {automationworkerlinuxuserroot}@{automationworkerlinuxnode}
Execute the following script:
cd "{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
USER="{automationWorkerLinuxUser.user}"
GROUP="$(id -gn {automationWorkerLinuxUser.user})"
echo "User: $USER, Group: $GROUP"
chown -R -v "$USER:$GROUP" "winpe_uefi_staging"
The xorriso and mkisofs command is used to create a customised,
bootable ISO image from the contents of the winpe_staging directory.
The command includes various settings for bootability, file system types,
naming conventions, and compatibility options to ensure the ISO functions as
intended in various environments.
Let's break down the command and its options:
xorriso -as mkisofs runs xorriso in a mode that emulates mkisofs,
a linux command.
-b boot.img specifies boot.img as the boot image for a bootable ISO.
-no-emul-boot indicates that no disk emulation mode is used for the boot
image. This is typically used for bootable ISOs intended for systems that
can understand the ISO file system directly.
-c BOOT.CAT specifies the creation of a boot catalog (BOOT.CAT) in the
ISO image.
-iso-level 3 sets the compliance level for the ISO 9660 standard.
Level 3 allows for file names up to 207 characters in length and file
sizes larger than 2 GB.
-udf includes UDF (Universal Disk Format) file system in
addition to ISO 9660. UDF is often used for DVDs and newer
optical media formats and supports larger file sizes.
-joliet-long Enables the use of the Joliet file system extension
with support for longer file names.
-relaxed-filenames allows file names that do not strictly adhere to the
ISO 9660 standard, providing more flexibility.
-allow-limited-size permits the creation of ISO images that exceed the
size limitations of the ISO 9660 standard.
-J enables Joliet file system extensions for longer file names and
Unicode characters.
-full-iso9660-filenames allows using the full ISO 9660 file naming
rules without the usual length limitations.
-disable-deep-relocation disables the relocation of deep directory
trees, which can be necessary for certain boot scenarios.
-omit-version-number omits the version number from file names in the
ISO image.
-V sets the volume ID of the ISO image.
-o specifies the output path and filename for the created ISO image.
Connect via ssh:
ssh {automationworkerlinuxuser}@{automationworkerlinuxnode}
Execute the following script:
cd "{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
ISO_NAME="winpe_plain_uefi.iso"
if [[ "Darwin" == "$(uname)" ]]
then
export PATH="${HOME}/Parallels/homebrew/bin:$PATH"
echo "Using $(which xorriso)"
xorriso -as mkisofs \
-iso-level 4 \
-full-iso9660-filenames \
-rock \
-b BOOT/etfsboot.com \
-no-emul-boot \
-boot-load-size 8 \
-hide boot.catalog \
-eltorito-alt-boot \
-no-emul-boot \
-b efi/microsoft/boot/efisys.bin \
-boot-load-size 1 \
-untranslated-filenames \
-disable-deep-relocation \
-V "KS_WIN" \
-o "{automationWorkerLinuxBaseDirectory}/${ISO_NAME}" \
winpe_uefi_staging
elif [[ -f /etc/redhat-release ]] || [[ -f /etc/lsb-release ]] || [[ -f /etc/debian_version ]]
then
mkisofs \
-allow-limited-size \
-iso-level 4 \
-full-iso9660-filenames \
-rock \
-b BOOT/etfsboot.com \
-no-emul-boot \
-boot-load-seg 0 \
-boot-load-size 8 \
-hide boot.catalog \
-eltorito-alt-boot \
-no-emul-boot \
-b efi/microsoft/boot/efisys.bin \
-boot-load-size 1 \
-udf \
-untranslated-filenames \
-disable-deep-relocation \
-V "KS_WIN" \
-o "{automationWorkerLinuxBaseDirectory}/${ISO_NAME}" \
winpe_uefi_staging
else
echo "Unsupported operating system."
exit 1
fi
Unmount any existing WinPE or Windows ISO mounts.
Set appropriate write permissions to enable modifications in the working directory.
Delete any remaining build files.
For a linux system, the umount command detaches the mentioned file system
from the file hierarchy.
For a macOS system, the hdiutil detach command detaches a disk image and
terminates any associated processes.
Connect via ssh:
ssh {automationworkerlinuxuserroot}@{automationworkerlinuxnode}
Execute the following script:
MOUNT_PATH="{automationWorkerLinuxBaseDirectory}/build-winpe-iso/uefi_mount"
if [[ -f /etc/redhat-release ]] || [[ -f /etc/lsb-release ]] || [[ -f /etc/debian_version ]]
then
if df -h | grep --ignore-case --quiet "$(echo ${MOUNT_PATH}/*)"
then
umount --verbose "$(echo ${MOUNT_PATH}/*)"
chmod -R a+w "${MOUNT_PATH}"
else
echo "${MOUNT_PATH} is not mounted. Skipping."
fi
elif [[ "Darwin" == "$(uname)" ]]
then
if [[ $(find ${MOUNT_PATH}/* 2> /dev/null | wc -l) -gt 10 ]]
then
hdiutil detach "$(echo ${MOUNT_PATH}/*)"
else
echo "${MOUNT_PATH} is not mounted. Skipping."
fi
else
echo "Unsupported operating system."
exit 1
fi
For a linux system, the umount command detaches the mentioned file system
from the file hierarchy.
For a macOS system, the hdiutil detach command detaches a disk image and
terminates any associated processes.
Execute the following script:
MOUNT_PATH="{automationWorkerLinuxBaseDirectory}/build-winpe-iso/winimg"
if [[ -f /etc/redhat-release ]] || [[ -f /etc/lsb-release ]] || [[ -f /etc/debian_version ]]
then
if df -h | grep --ignore-case --quiet "$(echo ${MOUNT_PATH}/*)"
then
umount --verbose "$(echo ${MOUNT_PATH}/*)"
chmod -R a+w "${MOUNT_PATH}"
else
echo "${MOUNT_PATH} is not mounted. Skipping."
fi
elif [[ "Darwin" == "$(uname)" ]]
then
if [[ $(find ${MOUNT_PATH}/* 2> /dev/null | wc -l) -gt 10 ]]
then
hdiutil detach $(echo ${MOUNT_PATH}/*)
else
echo "${MOUNT_PATH} is not mounted. Skipping."
fi
else
echo "Unsupported operating system."
exit 1
fi
The chmod -R a+w command modifies the permissions recursively for a directory
and its contents.
-R stands for recursive.
a stands for all.
+ adds permissions.
w stands for write.
This action is needed to delete the build directory.
Execute the following script:
DIR="{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
if [[ ! -d ${DIR} ]]
then
echo "Directory ${DIR} does not exist. Skipping."
else
cd "${DIR}"
UEFI_STAGING_DIR="winpe_uefi_staging"
if [[ ! -d ${UEFI_STAGING_DIR} ]]
then
echo "Directory does not exist. Skipping."
else
echo "Before"
ls -lh
chmod -R a+w "${UEFI_STAGING_DIR}"
echo "After"
ls -lh
fi
fi
Delete any remaining build files.
Connect via ssh:
ssh {automationworkerlinuxuser}@{automationworkerlinuxnode}
Execute the following script:
DIR="{automationWorkerLinuxBaseDirectory}/build-winpe-iso"
if [ -d ${DIR} ]
then
rm -rf ${DIR}
echo "Removed ${DIR}"
else
echo "No directory to remove."
fi
You have completed this instruction.
Join our Discord channel and connect with like-minded individuals who share your passion. Engage in lively discussions, gain valuable insights, and stay updated on the latest trends in our industry. Don't miss out on this opportunity to network, learn, and grow together.
Click the link below and become a part of our vibrant community on Discord today!