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.

You can get future posts delivered by email or good old-fashioned RSS.
TurnKey also has a presence on Google+, Twitter and Facebook.

Comments

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...

BulkUSB's picture

Great post Alan!  Flash drives aren't just faster and re-usable (compared to CD drives) they’re also smaller. Occupy less space. One can also send the data on flash drives with the busines logo etc on it. 

bulldozer2003's picture

This is interesting because I've always gotten away with dd'ing the ISO to the USB drive directly, without converting the ISO first.

 

Although, could it simply be that Ubuntu, Debian, and Mint release their ISOs as hybrids to begin with?

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! :)

tony mancill's picture

In case this helps anyone, you'll need to install syslinux-utils instead of syslinux starting with Debian jessie (a.ka. "testing" at the time of writing, soon to be stable).  See: https://packages.debian.org/search?suite=jessie&arch=any&mode=exactfilename&searchon=contents&keywords=isohybrid

 

Martin's picture

Thank you very much for this very useful guide and for the script as well!

Cheers,

Martin

Vishal's picture

Hi,

I have created a USB bootable as per the above mentioned the method.

But now, the USB disk is not usable for data storage.

How can I make it a FAT32 system again?

 

Thanks

 

Jeremy Davis's picture

Format it! :)
Aaron's picture

After the umount step, I try to use dd like you say and it gives me the error: 

 

dd: opening `/dev/sde': No medium found

Joshua Grigonis's picture

Did you do the lsblk command to see your devices?

On my computer, it was sdb not sde.

I'm guessing your device is something other than e.

 

Otherwise, perhaps the udb drive is not being recognized at all.

Landis 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/

WBuilder's picture

Thank you very much!

Burn iso to usb's picture

Nice post,thanks for sharing!There also is a post that would show you how to burn an ISO to USB drive or/and copy ISO to USB flash drive for data storage only, rather than creating ISO to bootable USB flash drive.

Pete's picture

I'm using LMDE Cinnamon Edition and wish to convert the Kaspersky rescue disk (to repair a windows box) from their downloaded .iso to boot the box off a USB flash drive.

 

following the instruction gives rise to this:

root: isohybrid kav_rescue_10.iso
isohybrid: kav_rescue_10.iso: boot loader does not have an isolinux.bin hybrid signature. Note that isolinux-debug.bin does not support hybrid booting

So it would appear that there are cases that isohybrid can't handle. This is not made clear in the article.

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...?

Will's picture

Man, I've always just played it lazy, and burned my .iso images to a dvd, but a relative's godawful netbook with no optical drive went belly up, and I wound up being unfortunate enough to try to repair it.

I just spent the last hour looking at stackoverflow posts saying things like "reboot into Windows and download this program to write the image", "burn Ubuntu to a dvd, then boot up, then use their 'install-to-usb' utility", or "use UNetbootin" (which never produced a bootable USB stick) and I KNEW it was simpler than all that nonsense.

Thanks.  I didn't know about isohybrid, and that was the step I was missing.

linus's picture

got this message after running the live cd

early console in setup code

this kernel requires an x86-64 cpu,but only detected an i686 cpu.

unable to boot - pls use a kernel appropriate for your cpu.

 

where can I get to choose the proper iso's to burn?

thanks

stivv's picture

Can u tell me how manualy make some program to boot in usb? because in some case in building linux from the scratch.. we can't use that way to do it

sorry for my english, i'm an indonesian hehe

edcompsci's picture

Is there some kind of tree structure iso that will let youchoose between several ISOs on a usb drive? Actually I know of one but sometimes it has not worked when I wanted to, probably from me forgetting exactly the right way to implement its use, called Multisystem.  the isohybrid command knowledge above I wonder if that was actually already applied to the multisystem iso, and if I dd it to the usb device it just works, then I drag and drop isos into the right folder and wala, multiple OS's.   Will have to try this.

isohybrid path/to/image.iso
SteveKawamoto's picture

DD is ok but cp'ing an ISO is faster and less unlikely to fail, whereas unetbootin fails too often especaily with Fedora packages.   I mean really, the only way to upgrade a Fedora PC is to saving your stash of data in a cloud server via Google Drive.  Then wipe the flash rive. But if you hack the Russians, you're a hero.
MartinB's picture

Your post is still of great value. I'm installing Linux 7.7 as I write after running into a forest of trouble spanning days. Thanks for your assistance!

Pages

Post new comment