X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=programs%2Fmkwinpeimg.in;h=c74b9d42f6d24ad81cffed6a9493e7c46670d1c9;hp=5316efa8f79fa44ba31a047ca6c0c5b763588643;hb=d85424218ef1148204aac3289bbf4ba2c0da9255;hpb=9655f89082b186f7748485c6ee42c878274fdb25 diff --git a/programs/mkwinpeimg.in b/programs/mkwinpeimg.in index 5316efa8..c74b9d42 100755 --- a/programs/mkwinpeimg.in +++ b/programs/mkwinpeimg.in @@ -21,7 +21,6 @@ script_name="$(basename "$0")" PREFIX_REG="::" WIMLIB_VERSION=@VERSION@ -imagex=@IMAGEX_PROGNAME@ calc_columns () { STAT_COL=80 @@ -88,20 +87,23 @@ Usage: $script_name [OPTIONS] IMAGE -i, --iso Make an ISO image instead of a disk image. -o, --only-wim Make neither a disk image nor an ISO image; instead, only make a modified boot.wim file. - -W, --windows-dir=DIR Use DIR as the location of the mounted Windows 7 - or Windows 8 DVD. Default is /mnt/windows, - then /mnt/windows7, then /mnt/windows8. - -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. + -W, --windows-dir=DIR Use DIR as the location of the mounted Windows + installation ISO image. If not specified, then + the script tries the following locations: + /mnt/windows, /mnt/windows7, /mnt/windows8, + /mnt/windows10. + -A, --waik-dir=DIR Get the boot files and boot.wim from the ISO image + of the Windows Automated Installation Kit (WAIK) + mounted on DIR instead of from a Windows + installation ISO. This also works if the mounted + ISO is for the WAIK supplement rather than for 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. This defaults to the - appropriate WIM file from the Windows DVD, WAIK, - or WAIK supplement. + appropriate WIM file from the Windows or WAIK + directory. -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". @@ -116,7 +118,7 @@ EOF } version() { - echo "$script_name (wimlib $WIMLIB_VERSION)" + echo "$script_name (distributed with wimlib $WIMLIB_VERSION)" exit 0 } @@ -148,7 +150,7 @@ process_command_line() { windows_dir="$2" windows_dir_specified=yes if [ -n "$waik_dir" ]; then - echo "ERROR: Cannot specify both --windows-dir and --waik-dir!" + echo 1>&2 "ERROR: Cannot specify both --windows-dir and --waik-dir!" exit 1 fi shift @@ -156,7 +158,7 @@ process_command_line() { -A|--waik-dir) waik_dir="$2" if [ -n "$windows_dir" ]; then - echo "ERROR: Cannot specify both --windows-dir and --waik-dir!" + echo 1>&2 "ERROR: Cannot specify both --windows-dir and --waik-dir!" exit 1 fi shift @@ -192,7 +194,7 @@ process_command_line() { arch="AMD64" arch_id="3" else - echo "ERROR: $2 is not a valid arch (x86/amd64)" + echo 1>&2 "ERROR: $2 is not a valid arch (x86/amd64)" exit 1 fi shift @@ -209,7 +211,7 @@ process_command_line() { break ;; *) - echo "Invalid option \"$1\"" + echo 1>&2 "Invalid option \"$1\"" usage exit 1 ;; @@ -218,8 +220,8 @@ process_command_line() { done if [ $# -ne 1 ]; then - echo "You must specify the name of the image file to create!" - echo "Run \"$script_name -h\" to see usage information." + echo 1>&2 "You must specify the name of the image file to create!" + echo 1>&2 "Run \"$script_name -h\" to see usage information." exit 1 else image="$1" @@ -228,7 +230,9 @@ process_command_line() { find_windows_dir() { if [ -z "$windows_dir_specified" ]; then - for windows_dir in /mnt/windows /mnt/windows7 /mnt/windows8; do + for windows_dir in /mnt/windows /mnt/windows7 \ + /mnt/windows8 /mnt/windows10; \ + do if [ -d "$windows_dir"/sources ]; then break fi @@ -236,19 +240,20 @@ find_windows_dir() { fi if [ ! -d "$windows_dir" ]; then if [ -z "$windows_dir_specified" ]; then - cat << EOF -ERROR: Could not find the directory that the Windows 7 or 8 ISO image is mounted -on! Please specify this directory using the --windows-dir option. + cat 1>&2 << EOF +ERROR: Could not find the directory that the Windows (Vista or later) ISO image +is mounted on! Please specify this directory using the --windows-dir option. EOF else - echo "ERROR: Could not find the directory \"$windows_dir\"!" + echo 1>&2 "ERROR: Could not find the directory \"$windows_dir\"!" fi exit 1 fi if [ ! -d "$windows_dir/sources" ]; then - cat << EOF -ERROR: The directory "$windows_dir" exists, but it seems that the Windows 7 or 8 -ISO image is not mounted on it. Please mount the image to continue. + cat 1>&2 << EOF +ERROR: The directory "$windows_dir" exists, but it seems that a Windows +(Vista or later) installation ISO image is not mounted on it. Please mount +the image to continue. EOF exit 1 fi @@ -256,10 +261,10 @@ EOF check_needed_programs() { if [ -z "$waik_dir" -o -n "$modify_wim" ]; then - if ! type -P @IMAGEX_PROGNAME@ &> /dev/null ; then - cat << EOF -ERROR: To make a customized image of Windows PE, we need the "$imagex" program -from "wimlib" so that we can modify the boot.wim file. However, "$imagex" + if ! type -P wimlib-imagex &> /dev/null ; then + cat 1>&2 << EOF +ERROR: To make a customized image of Windows PE, we need the wimlib-imagex program +from "wimlib" so that we can modify the boot.wim file. However, wimlib-imagex doesn't seem to be installed. Please install "wimlib" to continue. EOF exit 1 @@ -268,7 +273,7 @@ EOF if [ $make = iso ]; then if ! type -P mkisofs &> /dev/null ; then - cat << EOF + cat 1>&2 << EOF ERROR: To make a bootable ISO image of Windows PE, we need the "mkisofs" program, but it doesn't seem to be installed. Please install the "cdrkit" package to continue, or try omitting the --iso option to make a disk image @@ -278,7 +283,7 @@ EOF fi elif [ $make = disk ] ; then if ! type -P syslinux &> /dev/null ; then - cat << EOF + cat 1>&2 << EOF ERROR: To make a bootable disk image of Windows PE, we need the "syslinux" program, but it doesn't seem to be installed. Please install the "syslinux" package to continue, or try using the --iso option to make an ISO image instead @@ -288,7 +293,7 @@ EOF fi if ! type -P mformat mcopy &> /dev/null; then - cat << EOF + cat 1>&2 << EOF ERROR: To make a bootable disk image of Windows PE, we need the "mformat" and "mcopy" programs from the "mtools" package. These programs allow us to format a FAT filesystem and copy files to it without needing root privileges. @@ -300,7 +305,7 @@ EOF if [ -n "$waik_dir" ] && [ -f "$waik_dir"/wAIK${arch}.msi ]; then if ! type -P cabextract &> /dev/null ; then - cat << EOF + cat 1>&2 << EOF ERROR: The boot files in the Windows Automated Installation Kit (WAIK) are inside cabinet archives. To extract these files, we need the "cabextract" program, but it doesn't seem to be installed. Please install "cabextract" to @@ -342,7 +347,7 @@ get_primary_boot_files() { else # Get boot files from the Windows ISO - stat_busy "Copying primary boot files from mounted Windows DVD ($windows_dir)" + stat_busy "Copying primary boot files from mounted Windows ISO ($windows_dir)" if [ $make = iso ]; then cp "$windows_dir"/boot/etfsboot.com "$tmp_dir" || stat_fail fi @@ -355,11 +360,11 @@ get_primary_boot_files() { get_boot_wim() { boot_wim="$1" # Copy the WIM over, or export the 2nd image in the WIM in the case of boot.wim - # from the Windows DVD. + # from the Windows ISO. remove_setup= if [ -z "$wim" ]; then - # WIM file unspecified- grab it from the WAIK or the Windows DVD + # WIM file unspecified- grab it from the WAIK or the Windows ISO if [ -n "$waik_dir" ]; then # WAIK if [ -f "$waik_dir/WinPE.cab" ]; then @@ -374,11 +379,11 @@ get_boot_wim() { fi stat_done else - # Windows DVD + # Windows ISO remove_setup=yes wim="$windows_dir/sources/boot.wim" stat_busy "Exporting image from \"$wim\"" - "$imagex" export "$windows_dir"/sources/boot.wim 2 \ + wimlib-imagex export "$windows_dir"/sources/boot.wim 2 \ --boot "$boot_wim" || stat_fail stat_done fi @@ -432,7 +437,7 @@ modify_boot_wim() { exec 3>&- stat_busy "Rebuilding WIM with changes made" - "$imagex" update "$boot_wim" --rebuild \ + wimlib-imagex update "$boot_wim" --rebuild \ < "$tmp_dir/__mkwinpeimg.update.cmds" > /dev/null || stat_fail stat_done } @@ -446,7 +451,7 @@ make_iso_img() { mkisofs -sysid "" -A "" -V "Microsoft Windows PE ($arch)" -d -N \ -b etfsboot.com -no-emul-boot -c boot.cat -hide etfsboot.com \ - -hide boot.cat -quiet -o "$image" "$tmp_dir" || stat_fail + -hide boot.cat -quiet -o "$image" "$tmp_dir" 1>&4 || stat_fail stat_done } @@ -473,11 +478,26 @@ make_disk_img() { export MTOOLSRC="$mtool_conf" - mformat -h 255 -s 63 -T $(( image_size / 512)) s: - mcopy -s "$tmp_dir"/* s: + mformat -h 255 -s 63 -T $(( image_size / 512)) s: || stat_fail + mcopy -s "$tmp_dir"/* s: || stat_fail syslinux --install "$image" - mcopy /usr/lib/syslinux/chain.c32 s: + + syslinuxdir="/usr/lib/syslinux" + + if [ -d "$syslinuxdir/bios" ]; then + biosdir="$syslinuxdir/bios" + else + biosdir="$syslinuxdir" + fi + + mcopy "$biosdir/chain.c32" s: || stat_fail + if [ -e "$biosdir/libcom32.c32" ]; then + mcopy "$biosdir/libcom32.c32" s: + fi + if [ -e "$biosdir/libutil.c32" ]; then + mcopy "$biosdir/libutil.c32" s: + fi mcopy - 's:syslinux.cfg' <<- EOF DEFAULT winpe LABEL winpe @@ -491,6 +511,22 @@ make_disk_img() { calc_columns tmp_dir="$(mktemp -d)" process_command_line "$@" + +if [ "$image" = "-" ] ; then + # Writing image to standard output + if [ "$make" != iso ]; then + echo 1>&2 "ERROR: Writing image to standard output is only supported in --iso mode!" + exit 1 + fi + # We can't print anything to standard output except the ISO image + # itself. Play with the file descriptors. + + exec 4>&1 # 4 is now the original standard output. + exec 1>&2 # Anything that goes to standard output now, by default, + # actually goes to standard error. +else + exec 4>&1 # 4 is now a copy of standard output +fi if [ -z "$waik_dir" ]; then find_windows_dir fi @@ -498,7 +534,7 @@ if [ -n "$start_script" -o -n "$overlay" -o -n "$remove_setup" ]; then modify_wim=yes fi check_needed_programs -trap cleanup exit +trap cleanup EXIT if [ $make != wim ]; then mkdir -p "$tmp_dir"/{boot,sources} @@ -523,4 +559,6 @@ elif [ $make = disk ]; then make_disk_img "$image" fi -echo "The image ($image) is $(stat -c %s "$image") bytes." +if [ "$image" != "-" ]; then + echo "The image ($image) is $(stat -c %s "$image") bytes." +fi