Copy a .iso to a USB stick

Every time I have to burn a Linux image to a USB stick, I always have to look it up. Every single time, without fail. I decided to write a post about it so I wouldn’t have to Google it every time.

Since I primarily use Linux, these steps outline how to copy the image to a USB stick using Linux. Sorry Mac or Windows users, you’re on your own.

Step 1: Find the device path to your memory stick

Run the lsblk command:

$ lsblk
NAME                       MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda                          8:0    0 298.1G  0 disk  
├─sda1                       8:1    0   243M  0 part  /boot
├─sda2                       8:2    0     1K  0 part  
└─sda5                       8:5    0 297.9G  0 part  
  └─sda5_crypt             254:0    0 297.9G  0 crypt
    ├─englewood--vg-root   254:1    0   8.4G  0 lvm   /
    ├─englewood--vg-var    254:2    0   2.8G  0 lvm   /var
    ├─englewood--vg-swap_1 254:3    0   7.4G  0 lvm   [SWAP]
    ├─englewood--vg-tmp    254:4    0   380M  0 lvm   /tmp
    └─englewood--vg-home   254:5    0   279G  0 lvm   /home
sdb                          8:16   1   7.5G  0 disk  
├─sdb1                       8:17   1   1.5G  0 part  /media/ryan/ANTERGOS
└─sdb2                       8:18   1    31M  0 part  
sr0                         11:0    1  1024M  0 rom   

This output may seem a bit confusing, but it’s pretty simple. The first part under NAME, at the top of each tree, is the device. This corresponds to an actual physical device, like your hard drive or your USB stick. The three listed above are sda, sdb, and sr0. (I’m not sure what sr0 is.)

The next level of the tree is the partitions. Your hard drive may have been partitioned when you installed your OS, like mine. You can see three partitions for sda, numbered sda1, sda2, and sda5. (I think I messed up installing, which is why it skips 3 and 4.) sda5 has several subpartitions related to encryption. Additionally, there are two partitions on my USB stick, since it already had a Linux image on it. I can tell it’s my USB stick because one of its partitions is mounted under /media.

If you’re ever unsure of which one is your USB stick, look at the sizes. You should recognize the size of your hard drive and the size of your USB stick. Be extra careful to make sure you have the right device! It could make the difference between success, and trashing your computer.

These device and partition names are listed under /dev. So, the device for my USB stick is /dev/sdb, and its partitions are /dev/sdb1 and /dev/sdb2. These are important.

Step 2: Unmount any mounted partitions

I can see that I have two partitions. I know only one of them is mounted, but for the sake of demonstration I’ll try to unmount both.

Make sure that you’re unmounting partitions, not devices.

$ sudo umount /dev/sdb1
[sudo] password for ryan:
$ sudo umount /dev/sdb2
umount: /dev/sdb2: not mounted

It worked the first time, but failed the second. No worries; it’s all unmouted now and ready to write to.

Step 3: Burn the image

Funny how we still use the word “burn”, even though CDs are falling out of use.

Make sure that your destination (”of”) is a device, not a partition.

sudo dd if=/path/to/image.iso of=/dev/sdb bs=4M

This will run for a while with no output. You can monitor the progress by running this in another window:

sudo kill -USR1 $(pgrep ^dd)

Or, if you want regular updates:

watch -n5 'sudo kill -USR1 $(pgrep ^dd)'

Step 4: Flush the writes and remove the stick

Finally, it’s a good idea to make sure the machine is done writing:

sudo sync

After you’ve run this, congratulations! You’ve burned a shiny new Linux distro onto your USB stick.