Skip to content

Instantly share code, notes, and snippets.

@ldelelis
Created August 13, 2017 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldelelis/ffa55639054e86942652d23efb5e2fe7 to your computer and use it in GitHub Desktop.
Save ldelelis/ffa55639054e86942652d23efb5e2fe7 to your computer and use it in GitHub Desktop.
#!bin/sh
##################################
# Winboot flash drive automation #
# Author: Lucio Delelis #
##################################
# CREDIT TO USER Cornelius in askubuntu for the procedure
if [ "$#" -ne 2 ] || ! [ -d $2 ]; then
echo "Usage: $0 <Windows ISO> <target directory>" >&2
exit 1
fi
if ! which 7z; then
echo "ERROR: 7zip not found. It must be installed to continue" >&2
exit 1
fi
7z x $1 -o $2
echo "[B]IOS or [U]EFI?"
read $PARTTABLE
echo "Letter of the flash drive device? (Just the final one)"
read $DEVLETTER
if [ ! -f /dev/${DEVLETTER}1 ]; then
echo "ERROR: flash drive must be partitioned to continue" >&2
exit 1
fi
case $PARTTABLE in
B)
echo "You will be asked for password because the next command runs sudo"
echo "Fetching partition UUID"
UUID=$(sudo blkid -s UUID -o value /dev/sd${DEVLETTER}1)
cd $2
rename -f 'y/A-Z/a-z/' boot
sleep 3
sudo grub-install --target=i386-pc --boot-directory="./boot" \
/dev/sd$DEVLETTER
touch boot/grub.cfg
cat <<EOF >> boot/grub.cfg
echo "If you see this, you have successfully booted from USB :)"
insmod ntfs
insmod search_fs_uuid
search --no-floppy --fs-uuid $UUID --set root
ntldr /bootmgr
boot
EOF
;;
U)
if [! -f $2/efi/boot/bootx64.efi ] || [ ! -f $2/efi/boot/bootia32.efi ]
then
echo "EFI boot file not found." >&2
echo "You will manually have to follow extra steps detailed in the
following link: " >&2
echo 'https://askubuntu.com/questions/289559/how-can-i-create-a-windows-bootable-usb-stick-using-ubuntu' >&2
exit 1
fi
;;
esac
echo "Installation complete."
echo 'Make sure to unmount the drive before removing it :)'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment