X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=programs%2Fmkwinpeimg.in;h=cb997fe128f39968a46d506bf23884ffecf8b067;hb=297e0855665e45708b114048e42befc4654cdbee;hp=19712ce719a2a11897e54f90f59e2b657c84cd2e;hpb=232c381f9f3ab814258aa8e2380f537498a50905;p=wimlib diff --git a/programs/mkwinpeimg.in b/programs/mkwinpeimg.in index 19712ce7..cb997fe1 100755 --- a/programs/mkwinpeimg.in +++ b/programs/mkwinpeimg.in @@ -78,9 +78,6 @@ stat_fail() { cleanup() { - if mountpoint -q "$mnt_dir" ; then - @IMAGEX_PROGNAME@ unmount "$mnt_dir" - fi rm -rf "$tmp_dir" } @@ -97,13 +94,14 @@ Usage: $script_name [OPTIONS] IMAGE -A, --waik-dir=DIR Get the boot files and boot.wim from the ISO of the Windows Automated Installation Kit mounted on DIR instead of from the Windows 7 or Windows 8 DVD. + This also works if the mounted ISO is for the + WAIK supplement rather than the WAIK itself. -s, --start-script=FILE Add FILE to the root directory of Windows PE image and adjust \Windows\System32\winpeshl.ini to execute FILE when Windows PE starts up. - -w, --wim=WIM Use WIM as the boot.wim file. Defaults to - sources/boot.wim in the Windows DVD directory, or - F1_WINPE.WIM from the WAIK if --waik-dir is - specified. + -w, --wim=WIM Use WIM as the boot.wim file. This defaults to the + appropriate WIM file from the Windows DVD, WAIK, + or WAIK supplement. -O, --overlay=DIR Adds all the files in DIR to the Windows PE image. -t, --tmp-dir=DIR Use DIR as the temporary base of the ISO filesystem. Defaults to making one using "mktemp -d". @@ -300,7 +298,7 @@ EOF fi fi - if [ -n "$waik_dir" ]; then + if [ -n "$waik_dir" ] && [ -f "$waik_dir"/wAIK${arch}.msi ]; then if ! type -P cabextract &> /dev/null ; then cat << EOF ERROR: The boot files in the Windows Automated Installation Kit (WAIK) are @@ -317,18 +315,29 @@ EOF get_primary_boot_files() { if [ -n "$waik_dir" ]; then # Get boot files from the WAIK. - stat_busy "Copying primary boot files from the Windows Automated Installation Kit ($waik_dir, $arch)" - if [ $make = iso ]; then - cabextract "$waik_dir"/wAIK${arch}.msi -F F_WINPE_${arch}_etfsboot.com -p \ - > "$tmp_dir"/etfsboot.com || stat_fail + + if [ -f "$waik_dir"/wAIK${arch}.msi ]; then + if [ $make = iso ]; then + cabextract "$waik_dir"/wAIK${arch}.msi -F F_WINPE_${arch}_etfsboot.com -p \ + > "$tmp_dir"/etfsboot.com || stat_fail + fi + cabextract "$waik_dir"/wAIK${arch}.msi -F F${arch_id}_BOOTMGR -p \ + > "$tmp_dir"/bootmgr || stat_fail + cabextract "$waik_dir"/wAIK${arch}.msi -F F_WINPE_${arch}_boot.sdi -p \ + > "$tmp_dir"/boot/boot.sdi || stat_fail + cabextract "$waik_dir"/wAIK${arch}.msi -F F_WINPE_${arch}_bcd -p \ + > "$tmp_dir"/boot/bcd || stat_fail + # The WAIK supplement disc has a different structure + else + # Note: fuseiso, mount default to map=normal i.e. lowercase + if [ $make = iso ]; then + cp "$waik_dir"/${arch,,}/boot/etfsboot.com $tmp_dir/etfsboot.com || stat_fail + fi + cp "$waik_dir"/${arch,,}/bootmgr $tmp_dir/bootmgr || stat_fail + cp "$waik_dir"/${arch,,}/boot/boot.sdi $tmp_dir/boot/boot.sdi || stat_fail + cp "$waik_dir"/${arch,,}/boot/bcd $tmp_dir/boot/bcd || stat_fail fi - cabextract "$waik_dir"/wAIK${arch}.msi -F F${arch_id}_BOOTMGR -p \ - > "$tmp_dir"/bootmgr || stat_fail - cabextract "$waik_dir"/wAIK${arch}.msi -F F_WINPE_${arch}_boot.sdi -p \ - > "$tmp_dir"/boot/boot.sdi || stat_fail - cabextract "$waik_dir"/wAIK${arch}.msi -F F_WINPE_${arch}_bcd -p \ - > "$tmp_dir"/boot/bcd || stat_fail stat_done else # Get boot files from the Windows ISO @@ -353,9 +362,16 @@ get_boot_wim() { # WIM file unspecified- grab it from the WAIK or the Windows DVD if [ -n "$waik_dir" ]; then # WAIK - stat_busy "Extracting boot.wim from \"$waik_dir/WinPE.cab\"" - cabextract "$waik_dir/WinPE.cab" -F F${arch_id}_WINPE.WIM -p \ - > "$boot_wim" 2>/dev/null || stat_fail + if [ -f "$waik_dir/WinPE.cab" ]; then + stat_busy "Extracting boot.wim from \"$waik_dir/WinPE.cab\"" + cabextract "$waik_dir/WinPE.cab" -F F${arch_id}_WINPE.WIM -p \ + > "$boot_wim" 2>/dev/null || stat_fail + # WAIK supplement has different layout + else + stat_busy "Copying boot.wim from \"${waik_dir}/${arch,,}/winpe.wim\"" + cp "$waik_dir"/${arch,,}/winpe.wim "$boot_wim" || stat_fail + chmod +w "$boot_wim" + fi stat_done else # Windows DVD @@ -374,47 +390,51 @@ get_boot_wim() { fi } +# Make modifications to the WIM. modify_boot_wim() { boot_wim="$1" - mnt_dir="$2" - - # Make modifications to the WIM. - stat_busy "Mounting "$1" read-write" + tmp_dir="$2" - mkdir -p "$mnt_dir" || stat_fail - "$imagex" mountrw "$boot_wim" "$mnt_dir"|| stat_fail - - stat_done + exec 3>"$tmp_dir/__mkwinpeimg.update.cmds" if [ -n "$remove_setup" ]; then stat_busy "Renaming setup.exe to prevent it from bothering us" - mv "$mnt_dir"/setup.exe{,.bkup} || stat_fail - mv "$mnt_dir"/sources/setup.exe{,.bkup} || stat_fail + cat 1>&3 <<- EOF + rename /setup.exe /setup.exe.orig + rename /sources/setup.exe /sources/setup.exe.orig + EOF stat_done fi if [ -n "$start_script" ]; then - stat_busy "Setting \"$start_script\" as the script to be executed"\ - "when Windows PE boots" - cp "$start_script" "$mnt_dir"|| stat_fail - cat > "$mnt_dir/Windows/System32/winpeshl.ini" << EOF -[LaunchApps] -%SYSTEMDRIVE%\\$start_script -EOF + stat_busy "Setting \"$start_script\" as the script to be executed when Windows PE boots" + cp "$start_script" "$tmp_dir/$start_script" + cat > "$tmp_dir/__mkwinpeimg.winpeshl.ini" <<- EOF + [LaunchApps] + %SYSTEMDRIVE%\\$start_script + EOF + cat 1>&3 <<- EOF + add '$tmp_dir/$start_script' '/$start_script' + delete --force /Windows/System32/winpeshl.ini + add '$tmp_dir/__mkwinpeimg.winpeshl.ini' /Windows/System32/winpeshl.ini + EOF stat_done fi if [ -n "$overlay" ]; then stat_busy "Overlaying \"$overlay\" on the Windows PE filesystem" - cp -r "$overlay"/* "$mnt_dir" || stat_fail + cat 1>&3 <<- EOF + add '$overlay' / + EOF stat_done fi + exec 3>&- + stat_busy "Rebuilding WIM with changes made" - "$imagex" unmount --commit "$mnt_dir" || stat_fail + "$imagex" update "$boot_wim" --rebuild \ + < "$tmp_dir/__mkwinpeimg.update.cmds" > /dev/null || stat_fail stat_done - - rmdir "$mnt_dir" } make_iso_img() { @@ -444,12 +464,12 @@ make_disk_img() { dd if=/dev/zero of="$image" count=$(( (image_size + 4095) / 4096)) \ bs=4096 &> /dev/null - cat > "$mtool_conf" << EOF -MTOOLS_SKIP_CHECK=1 -MTOOLS_FAT_COMPATIBILITY=1 -drive s: - file="$image" -EOF + cat > "$mtool_conf" <<- EOF + MTOOLS_SKIP_CHECK=1 + MTOOLS_FAT_COMPATIBILITY=1 + drive s: + file="$image" + EOF export MTOOLSRC="$mtool_conf" @@ -458,19 +478,18 @@ EOF syslinux --install "$image" mcopy /usr/lib/syslinux/chain.c32 s: - mcopy - 's:syslinux.cfg' << EOF - DEFAULT winpe - LABEL winpe - COM32 chain.c32 - APPEND ntldr=/bootmgr -EOF + mcopy - 's:syslinux.cfg' <<- EOF + DEFAULT winpe + LABEL winpe + COM32 chain.c32 + APPEND ntldr=/bootmgr + EOF rm -f "$mtool_conf" stat_done } calc_columns tmp_dir="$(mktemp -d)" -mnt_dir="$tmp_dir"/.boot.wim.mount process_command_line "$@" if [ -z "$waik_dir" ]; then find_windows_dir @@ -495,7 +514,7 @@ fi get_boot_wim "$boot_wim" if [ -n "$modify_wim" ]; then - modify_boot_wim "$boot_wim" "$mnt_dir" + modify_boot_wim "$boot_wim" "$tmp_dir" fi if [ $make = iso ]; then