bootable-usb-for-linux.sh 666 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. SCRIPT_NAME="${0##*/}"
  4. display_help() {
  5. echo "Usage: ${SCRIPT_NAME} <iso-file> </dev/sdX>"
  6. echo "Dependencies: dd"
  7. echo "Examples:"
  8. echo "- ${SCRIPT_NAME} ~/Downloads/ubuntu.iso /dev/sde"
  9. exit 2
  10. }
  11. require_sudo() {
  12. if [[ $EUID -ne 0 ]]; then
  13. echo "Please run as superuser! Try running:"
  14. echo "sudo ${0}"
  15. exit 2
  16. fi
  17. }
  18. require_sudo
  19. [[ $# -ne 2 || -f $2 || ! -f $1 ]] && display_help
  20. IMAGE="$1"
  21. LABEL="$(basename "${IMAGE%.*}")"
  22. DEVICE="$2"
  23. set -x # enable debugging
  24. mkfs.ext4 -L "$LABEL" "$DEVICE"
  25. dd if="$IMAGE" of="$DEVICE" bs=1M status=progress
  26. sync