Blog Tags: 

Creating a bootable USB drive from an ISO image

What's an ISO?

ISO, short for ISO9660 is the standard filesystem format for optical disc media. This is the default format created by the TurnKey GNU/Linux build system (AKA TKLDev)

Why would you want to write an ISO to a USB drive?

Typically one of two reasons:

  1. Compatibility: You want to boot the ISO on a physical computer that doesn't have a CD drive.

    Originally ISO files were intended to be burned to physical CDROM discs. Unfortunately while most virtualization software (e.g., KVM, VMWare, VirtualBox) has support for inserting ISO images into "virtual" CD readers, physical CD readers are a dying breed.
     
  2. Convenience: USB flash drives are smaller, faster, rewriteable and more robust than a clumsy, flat, scratchable CD.

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

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
Things to keep in mind:
  • 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.

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.

Comments

OnePressTech's picture

Thanks Alon. Much appreciated.

I've been providing clients with a dashboard based on portableapps.com with mixed satisfaction. The portableapps model requires the apps to be stripped down to work in the framework. Getting up-to-date apps and then having no decent support model when the apps don't work is less than ideal.

I like the idea of a mini LXC-based Turnkey linux to deploy dashboards & dev environments to my clients.

Should be good :-)

FYI - Minor typo...your script link label says usb2iso rather than iso2usb.

Cheers,

Tim (Managing Director - OnePressTech)

Alon Swartz's picture

Glad you'll find it useful! The idea of using TurnKey LXC with pre-cached images sounds very interesting indeed.

I personally use it as I've swapped out my laptops CD drive for a second harddrive to compliment my SSD, and I thought it would make sense to share what I've done, as well as pre-process all future ISO's for hybrid mode...

Jeremy Davis's picture

AFAIK Ubuntu have been producing hybrid ISOs for quite some time now. I would assume that Mint (as an Ubuntu derivative) has also been doing that. Debian OTOH haven't been doing it quite so long but at least since Wheezy. So I guess you've just been lucky! :)

Jeremy Davis's picture

Format it! :)
L. Arnold's picture

trying to build some 64 Bit systems both in Jessie and Wheezy.

Wheezy 64 TKLDEV Fails "can't find ISOLINUX" no matter what.  For some reason 386 / 32 Version of Wheezy TKLDEV does not.

Working forward on Jessie but so many other changes in terms of SSL/Apache that wanted to at least get a working system on that level for app tuning.

Seems it would be good that Wheezy TKLDEV works as most people are working with Wheezy still.  (Broken record I know... but working forward on Jessie too).

--------

References to IsoLinux

IN COMMON

plans/boot 

syslinux-common # Collection of bootloaders (common)

5

isolinux # Collection of bootloaders (ISO 9960 bootloader)

 

Quite a few in

turnkeylinux/tklpatch

Search

Shell

bin/tklpatch-prepare-cdroot 
Showing the top three matches. Last indexed on Jul 19, 2014.

38

[ -d $rootfs ] || fatal "no such directory: $rootfs"

39

 

40

echo "# preparing cdroot"

41

mkdir -p $cdroot/casper

42

mkdir -p $cdroot/isolinux

43

 

44

if [ ! -f $cdroot/isolinux/isolinux.cfg ]; then

45

cat>$cdroot/isolinux/isolinux.cfg<<'EOF'

46

DEFAULT /casper/vmlinuz boot=casper initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram rw showmounts debug toram=196 --

Shell

bin/tklpatch-geniso 
Showing the top three matches. Last indexed on Jul 19, 2014.

45

genisoimage -o $newimage -r -J -l \

46

-V $TKLPATCH_ISOLABEL \

47

-b isolinux/isolinux.bin \

48

-c isolinux/boot.cat \

Shell

bin/tklpatch-extract-iso 
Showing the top two matches. Last indexed on Jul 19, 2014.

47

echo "# extracting root filesystem and isolinux from ISO"

48

mkdir -p $cdroot

49

mkdir -p $name.mount

50

mount -o loop $isofile $name.mount

 

53

unsquashfs -d $rootfs $name.mount/casper/*root.squashfs

54

cp -a $name.mount/isolinux $cdroot/

docs/RelNotes-0.92.txt 
Showing the top match. Last indexed on Jul 19, 2014.

11

- if cdroot-dir is not provided, a minimal isolinux.cfg will be created

12

to automatically boot the image

13

 

14

 

15

* added support for configuration hooks (advanced usage)

 

then only One in

 

TKLDEV (APP)

found: docs/helloworld.rst 

66

cp build/root.sandbox/usr/lib/syslinux/isolinux.bin build/cdroot/isolinux

67

cp build/root.sandbox/boot/vmlinuz-3.2.0-4-amd64 build/cdroot/casper/vmlinuz

 

96

root (0)

97

genisoimage -o build/product.iso -r -J -l -V core -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table build/cdroot/

Jeremy Davis's picture

It only supports ISOs that use isolinux for booting and it sounds like that one might not...

Did you try the old version that Alon links to? Liraz quotes it in this post? Perhaps that will work...?

Pages

Add new comment