Skip to content

Instantly share code, notes, and snippets.

@MiguelMJ
Created March 21, 2022 08:57
Show Gist options
  • Select an option

  • Save MiguelMJ/7ca0f291bd67a88cda48fcb29090840f to your computer and use it in GitHub Desktop.

Select an option

Save MiguelMJ/7ca0f291bd67a88cda48fcb29090840f to your computer and use it in GitHub Desktop.
#!/usr/bin/bash
#
# Create a bootable USB from a local or remote ISO image
#
# Based on the tutorial from https://www.pragmaticlinux.com/2021/03/create-a-bootable-usb-drive-from-a-linux-iso-image/
#
# IMPORTANT: This script does not sanitize any input, make sure to introduce it well or modify it to make it safer
# Select external disk
echo "List of detected disks"
lsblk -p | grep "disk"
read -e -p "Introduce disk path>" device
# Get path to the ISO image
# If an URL is given, download the ISO before using it
read -e -p "Introduce ISO path or URL>" location
if [ ! -f "$location" ]; then
tmpfile=$(mktemp)
wget "$location" -O $tmpfile
location=$tmpfile
fi
# Write the ISO to the USB
echo "Writing USB..."
sudo dd if="$location" of="$device" bs=4M conv=datasync status=progress
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment