bootable-win2usb.sh 630 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. set -euxo pipefail
  4. display_help(){
  5. # echo "Usage: ${0##*/} [flag/s] [file/s]"
  6. echo "Usage : win2usb.sh VMs/Win10_1803_English_x64.iso /dev/sdX"
  7. exit 2
  8. }
  9. [[ $# -lt 2 ]] && display_help
  10. # https://www.microsoft.com/software-download/windows10ISO
  11. ISO=$1
  12. USB=$2
  13. FAT="$USB"1
  14. MNT=/mnt/USB
  15. TMP=/mnt/Image
  16. mkdir -p $MNT
  17. mkdir -p $TMP
  18. echo "Creating FAT32 bootable UEFI partition..."
  19. echo -e 'o\nn\np\n1\n\n\nt\nc\na\nw' | fdisk $USB
  20. mkfs.fat $FAT
  21. echo "Copying files..."
  22. mount $FAT $MNT
  23. mount $ISO $TMP
  24. cp -r $TMP/* $MNT
  25. sync
  26. umount $MNT
  27. umount $TMP
  28. echo "Done"