booting Linux from a USB stick

Most of the Linux distributions are downloadable as a ISO image which can be burned to a CD or DVD.  This is pretty convenient, download the distribution and create your own disks.

In the beginning floppy disks were used by everyone to transport data or install software.  Once the software was too big to fit, the floppy disks started to disappear and everyone moved to CD’s and DVD’s.  The same thing is now happening to the once so familiar CD and DVD drives.

They haven’t really been replaced by the much larger blue ray discs but have instead been replaced by fast network connections and USB sticks as USB sticks are small, fast, have no moving parts, and fit into your pocket.

In order to retain all of the same functionality, it became important to be able to use the USB sticks in the same way as the DVD.  USB sticks exceed the size of the disc’s without breaking a sweat.  The only missing piece was bootable USB sticks.

This was solved with the introduction of the isohybrid feature.  This is a reasonably small modification to the boot record, that allows USB sticks to be booted from BIOS just like a CD or DVD.   A few years ago if you wanted to get a Linux distribution to boot from the USB stick you had to run programs to make the conversion to your distribution and then copy it to the USB stick.

Now it is pretty common that a lot of Linux distributions when they create their ISO images already have this isohybrid format, especially the live discs.

There is virtually no effort involved to take one of these images and get it to boot off of a USB stick.  A single command will transfer the image.

dd if=myimage.iso of=/dev/sdX bs=1mb

This command will copy the image byte for byte over to the device /dev/sdX.

It is really important to make sure you give the proper device otherwise, you may be overwriting your main hard disk with the ISO image.  There are probably a lot of methods to determine what the device is, I either look at the logs with the dmesg command or the devices connected with the lsblk.

Log messages

> dmesg
 [ 5624.106378] usb 3-2: new high-speed USB device number 3 using xhci_hcd
 [ 5624.234666] usb 3-2: New USB device found, idVendor=05dc, idProduct=0300
 [ 5624.234672] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
 [ 5624.234675] usb 3-2: Product: JUMPDRIVE GEYSR
 [ 5624.234678] usb 3-2: Manufacturer: LEXAR MEDIA
 [ 5624.234680] usb 3-2: SerialNumber: 0A4EEC090022451
 [ 5625.037188] usb-storage 3-2:1.0: USB Mass Storage device detected
 [ 5625.037382] scsi6 : usb-storage 3-2:1.0
 [ 5625.037549] usbcore: registered new interface driver usb-storage
 [ 5626.033751] scsi 6:0:0:0: Direct-Access     LEXAR    GEYSER JUMPDRIVE 1.00 PQ: 0 ANSI: 1 CCS
 [ 5626.034308] sd 6:0:0:0: Attached scsi generic sg3 type 0
 [ 5626.034387] sd 6:0:0:0: [sdc] 2014992 512-byte logical blocks: (1.03 GB/983 MiB)
 [ 5626.034935] sd 6:0:0:0: [sdc] Write Protect is off
 [ 5626.034952] sd 6:0:0:0: [sdc] Mode Sense: 23 00 00 00
 [ 5626.035486] sd 6:0:0:0: [sdc] No Caching mode page found
 [ 5626.035491] sd 6:0:0:0: [sdc] Assuming drive cache: write through
 [ 5626.038184]  sdc: sdc1
 [ 5626.039933] sd 6:0:0:0: [sdc] Attached SCSI removable disk
 [ 5629.732887] FAT-fs (sdc1): utf8 is not a recommended IO charset for FAT filesystems, filesystem will be case sensitive!
 [ 5629.743731] FAT-fs (sdc1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.

Simply run the dmesg command and then do it again after plugging in the USB stick.

List of block devices

> lsblk
 NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
 sda      8:0    0 698.7G  0 disk
 ├─sda1   8:1    0   200M  0 part /boot/efi
 ├─sda2   8:2    0   128M  0 part
 ├─sda3   8:3    0 279.5G  0 part
 ├─sda4   8:4    0 393.9G  0 part /
 └─sda5   8:5    0    25G  0 part
 sdb      8:16   0 698.7G  0 disk
 ├─sdb1   8:17   0   9.5G  0 part [SWAP]
 ├─sdb2   8:18   0  46.6G  0 part
 ├─sdb3   8:19   0  50.2G  0 part
 ├─sdb4   8:20   0 451.8G  0 part
 ├─sdb5   8:21   0  47.5G  0 part
 └─sdb6   8:22   0  93.1G  0 part /home
 sdc      8:32   1 983.9M  0 disk
 └─sdc1   8:33   1 983.4M  0 part /media/dock/LEXAR MEDIA
 sr0     11:0    1  1024M  0 rom

Both of these methods let us know that there is a device /dev/sdc and that device has a single partition.

In my latest case, I used the following command.

> dd if=debian-8.2.0-i386-netinst.iso of=/dev/sdc bs=1m
> sync

The command sync has nothing to do with the copy but simply ensures that all I/O buffers are flushed.  This guarantees that the data is written out to the device.  This shouldn’t be necessary but it is a good practice to get into.

Don’t make the mistake of writing the ISO image to the device’s partition.  The boot record is at the beginning of the ISO image and must in the same location of the USB device otherwise the computer will not recognize the operating system and will hang.

This entry was posted in Command line, Setup From Scratch and tagged , . Bookmark the permalink.

1 Response to booting Linux from a USB stick

  1. Alba says:

    Thatt is very fascinating, You are a very skilled blogger.
    I have joined your feed and look forward to seeking extra oof your wonderful post.
    Also, I’ve shared your site in my social networks

Comments are closed.