Add make-ubuntu-usb.sh: write Ubuntu desktop ISO to USB (macOS)

Made-with: Cursor
This commit is contained in:
DannyDannyDanny 2026-02-28 16:27:48 +01:00
parent ed0a052a7c
commit 1fdce52239

View file

@ -0,0 +1,40 @@
#!/usr/bin/env bash
# Writes Ubuntu desktop ISO to a USB stick (whole-disk, bootable).
# Usage: make-ubuntu-usb.sh <disk_number> [iso_path]
# Example: make-ubuntu-usb.sh 4
# make-ubuntu-usb.sh 4 /tmp/ubuntu-24.04.4-desktop-amd64.iso
# Plug in the USB, run 'diskutil list' to find the disk (e.g. disk4 = use 4).
# Use -y to skip the confirmation prompt.
set -e
SKIP_CONFIRM=
[[ "${1:-}" == "-y" ]] && { SKIP_CONFIRM=1; shift; }
DISK_NUM="${1:?Usage: $0 [-y] <disk_number> [iso_path]}"
ISO="${2:-/tmp/ubuntu-24.04.4-desktop-amd64.iso}"
if [[ ! -f "$ISO" ]]; then
echo "ISO not found: $ISO"
echo "Download from: https://releases.ubuntu.com/24.04/ubuntu-24.04.4-desktop-amd64.iso"
exit 1
fi
DISK="disk${DISK_NUM}"
RDISK="rdisk${DISK_NUM}"
if ! diskutil info "$DISK" &>/dev/null; then
echo "Disk $DISK not found. Run 'diskutil list' and use the number of your USB (e.g. 4 for disk4)."
exit 1
fi
echo "Target: $DISK ($RDISK)"
echo "ISO: $ISO"
if [[ -z "$SKIP_CONFIRM" ]]; then
echo "This will ERASE all data on $DISK. Press Enter to continue, Ctrl+C to abort."
read -r
fi
diskutil unmountDisk "$DISK"
# macOS dd uses bs in bytes; 4m is invalid, use 4MiB. status=progress is GNU-only.
sudo dd if="$ISO" of="/dev/$RDISK" bs=4194304
diskutil eject "$DISK"
echo "Done. USB is now a bootable Ubuntu installer."