keyboard-shortcut
d

how to flash a USB drive with an ISO from the command line

3min read

an image

How to flash a USB drive with an ISO from the command line

dd can copy a bootable ISO directly to a USB drive on Linux or macOS.

Warning: this erases the entire target drive. Check its name and size immediately before running dd; it will overwrite the wrong disk without asking. Use the whole disk (/dev/sdX), not a partition (/dev/sdX1).

Most Linux installer ISOs support direct USB writing. Before starting, you can compare the downloaded ISO's SHA-256 checksum with its distributor's value:

# Linux
sha256sum ~/Downloads/example.iso

# macOS
shasum -a 256 ~/Downloads/example.iso

Linux

Run this before and after inserting the USB, then identify the new device by its size, model, and usb transport:

lsblk -p -o NAME,SIZE,MODEL,TRAN,MOUNTPOINTS

Replace /dev/sdX with the whole USB device. Unmount each of its mounted partitions, write the ISO, and eject it:

sudo umount /dev/sdX1
sudo dd if="$HOME/Downloads/example.iso" of=/dev/sdX bs=4M status=progress conv=fsync
sudo eject /dev/sdX

Repeat umount for any other partitions. status=progress shows the copy's progress; conv=fsync flushes the completed write before dd exits. If eject is unavailable, run sync, wait for it to finish, then remove the drive.

macOS

Connect the USB and identify it by its description and size:

diskutil list external physical

Replace /dev/diskN with the whole USB disk, such as /dev/disk4, not a partition such as /dev/disk4s1:

diskutil unmountDisk /dev/diskN
sudo dd if="$HOME/Downloads/example.iso" of=/dev/rdiskN bs=4m
sync
diskutil eject /dev/diskN

The raw /dev/rdiskN path writes faster. macOS dd has no status=progress; press Control+T for an update. If macOS later calls the drive unreadable, choose Eject, not Initializeβ€”the ISO may use a filesystem macOS does not recognise.

Restart the target computer, open its boot menu, and select the USB drive.

Restore the USB for file storage

This erases the USB so you can use it as a "normal" file storage device.

macOS

Replace diskN with its whole-disk identifier:

diskutil eraseDisk ExFAT FILES GPT /dev/diskN
# Or, for Mac-only use:
diskutil eraseDisk APFS FILES GPT /dev/diskN

linux

Replace /dev/sdX with the whole USB device:

sudo parted --script /dev/sdX mklabel gpt mkpart primary 0% 100%
sudo mkfs.exfat -n FILES /dev/sdX1