Creating a bootable USB drive from an ISO image

Using isohybrid + dd

The isohybrid tool in the syslinux package will convert ISO images into a USB flash drive compatible format:

# apt-get install syslinux
# isohybrid path/to/image.iso

Use lsblk to identify the device path (e.g., /dev/sdX) of your USB drive:

# lsblk
sde                                     8:64   1   7.4G  0 disk  
└─sde1                                  8:65   1   7.4G  0 part  /media/usbdrive

Use too:

# fdisk-l

If it’s been automounted, as is the case above, unmount it first:

# umount /media/usbdrive

Use dd to write the ISO image to the disk path. That’s /dev/sde NOT /dev/sde1:

dd if=path/to/image.iso of=/dev/sde status=progress bs=4M
Things to keep in mind:
  • bs=dimensioni(bytes)
    Legge e scrive dati in blocchi delle dimensioni specificate
  • Root access is required: You will need to perform the above commands as root. On Ubuntu prepend the commands with sudo (e.g., sudo apt-get install syslinux)
  • dd will completely overwrite your USB drive: Any data on it will be lost so if you use this method you’ll want to use it with a dedicated USB device.
  • dd needs to write to the disk path, not the partition path: in the above example /dev/sde is the disk path device, /dev/sde1 is the partition path (e.g., sde1 is the first partition on sde). You need to write to the disk path because isohybrid prepends a partition structure to the ISO.
  • status=progress (like the sentence itself say) show the progress of copy

How isohybrid works

Starting in version 3.72, ISOLINUX supports a “hybrid mode” which can be booted from either CD-ROM or from a device which BIOS considers a hard disk or ZIP disk, e.g. a USB key or similar.  These isohybrid images contain in addition to the normal CD-based ISO9660 filesystem, a valid-looking DOS-style partition table. So if you simply “raw” copy an isohybrid processed image to a USB flash drive, the BIOS will boot the image directly.

iso2usb.py helper script

The ‘dd’ command has always scared me. One wrong keystroke and you can overwrite the wrong hard disk. To make things a little less scary and safer, I wrote iso2usb:
Syntax: iso2usb.py iso_path usb_device
iso2usb: Create a bootable USB flash drive containing ISO image

Arguments:
    iso_path        Path to ISO (e.g., product.iso)
    usb_device      USB device path (e.g., /dev/sdc)

Options:
    --force         Not implemented, interactive confirmation required
iso2usb will do its best to verify that the usb_device is actually a USB device, and prompt for confirmation with device information before doing anything dangerous:
# iso2usb.py turnkey-core-13.0-wheezy-amd64.iso /dev/sdc
****************************************************************************
iso: turnkey-core-13.0-wheezy-amd64.iso (hybrid: False)
usb: disk/by-id/usb-SanDisk_Cruzer_Blade_200601650311ADD19323-0:0 (/dev/sdc)
****************************************************************************
Is the above correct? (y/N):

Additionally, iso2usb will check whether the ISO image has been pre-processed with isohybrid, and if not it will process the image before writing it.

Once completed, the USB flash drive should now boot directly, showing exactly the same bootup screen as if you’d written the image directly to a CD.

The old pre-isohybrid version of iso2usb

If for some reason your ISO isn’t using ISOLINUX as the bootloader you might want to try the old pre-isohybrid version of the iso2usb.py script which I wrote a few years ago. It extracts the ISO to the USB drive together and then installs syslinux. Recently I tried using it but hit issues related to changes in isolinux, which has since introduced the new isohybrid method.

The future

All future TurnKey ISO’s will be pre-processed with isohybrid, making it that little bit more TurnKey for installing ISO’s to USB flash disks.