Before writing an ISO to USB, you need to correctly identify your USB device path. Run:
lsblk -f
This will list all block devices. Your USB typically appears as /dev/sdX
where X is a letter (like sdb or sdc). Be absolutely certain of the device name - writing to the wrong device can destroy data.
The most direct way uses the dd
command:
sudo dd if=your-image.iso of=/dev/sdX bs=4M status=progress oflag=sync
Breaking this down:
if=
specifies input file (your ISO)of=
specifies output device (your USB)bs=4M
sets block size for better performancestatus=progress
shows transfer progressoflag=sync
ensures proper syncing
If your dd lacks status=progress, pipe through pv:
pv your-image.iso | sudo dd of=/dev/sdX bs=4M oflag=sync
For systems without dd, use cat:
cat your-image.iso | sudo tee /dev/sdX >/dev/null
After writing, verify the checksum:
sha256sum your-image.iso
sudo dd if=/dev/sdX bs=1M count=$(stat -c%s your-image.iso)/1048576 | sha256sum
The SHA256 hashes should match.
While you mentioned preferring CLI, these GUI tools have CLI options:
# For USB Creator
sudo usb-creator-cli --install=y --volume=/dev/sdX --image=your-image.iso
# For UNetbootin in CLI mode
sudo unetbootin installtype=USB targetdrive=/dev/sdX method=diskimage isofile=your-image.iso
For scripting purposes, here's a complete bash function:
function write_iso_to_usb() {
local iso_path=$1
local usb_device=$2
if [ ! -f "$iso_path" ]; then
echo "Error: ISO file not found"
return 1
fi
if [ ! -b "$usb_device" ]; then
echo "Error: USB device not found"
return 1
fi
echo "Writing $iso_path to $usb_device..."
sudo dd if="$iso_path" of="$usb_device" bs=4M status=progress oflag=sync
echo "Verifying checksum..."
local original_hash=$(sha256sum "$iso_path" | awk '{print $1}')
local written_hash=$(sudo dd if="$usb_device" bs=1M count=$(stat -c%s "$iso_path")/1048576 | sha256sum | awk '{print $1}')
if [ "$original_hash" = "$written_hash" ]; then
echo "Verification successful"
else
echo "Verification failed!"
return 1
fi
}
For creating persistent live USBs from CLI:
sudo mkdir /mnt/{iso,usb}
sudo mount -o loop your-image.iso /mnt/iso
sudo mkfs.ext4 -L liveusb /dev/sdX1
sudo mount /dev/sdX1 /mnt/usb
sudo rsync -a /mnt/iso/ /mnt/usb/
sudo dd if=/dev/zero of=/mnt/usb/casper-rw bs=1M count=2048
sudo mkfs.ext4 -L casper-rw /mnt/usb/casper-rw
- If USB isn't bootable: Try
sudo parted /dev/sdX set 1 boot on
- For larger ISOs: Format USB as NTFS first with
sudo mkfs.ntfs -f /dev/sdX1
- If write seems stuck: The sync operation might take time with large ISOs
Before writing an ISO, you need to identify your USB device path:
lsblk
sudo fdisk -l
Look for your USB device (typically /dev/sdX where X is a letter). Be extremely careful - selecting the wrong device can wipe your system.
The most straightforward method uses dd:
sudo dd if=your_image.iso of=/dev/sdX bs=4M status=progress oflag=sync
Key parameters: After writing, verify the checksum: Problem: USB not bootable after write Problem: Slow write speeds For Ubuntu/Debian ISOs, use mkusb: For scripting persistent storage, consider using tools like cubic or manual partitioning with persistence.conf.
- bs=4M
: Sets block size for faster transfer
- status=progressoflag=syncUsing pv for Progress Monitoring
pv your_image.iso | sudo dd of=/dev/sdX bs=4M oflag=sync
cat Method
cat your_image.iso | sudo tee /dev/sdX >/dev/null
Using cp
sudo cp your_image.iso /dev/sdX
sync
sha256sum your_image.iso
sudo head -c $(stat -c%s your_image.iso) /dev/sdX | sha256sum
gnome-disks
Solution: Ensure ISO is hybrid (most modern ones are). For non-hybrid ISOs:sudo isohybrid your_image.iso
Solution: Try different block sizes (1M, 4M, 8M) and USB ports (USB 3.0 preferred)sudo add-apt-repository ppa:mkusb/ppa
sudo apt update
sudo apt install mkusb
sudo mkusb /path/to/iso
sudo umount /dev/sdX*