How To Write An ISO File To A USB Flash Drive By Command Line In Linux

These days, CDs and DVDs are becoming more and more obsolete every day. Being able to write a Linux distro ISO to a USB drive is usually both faster and better than using a Linux CD or DVD. While there are many Graphical User Interface (GUI) tools to write an ISO to a flash drive, this article will discuss how to write an ISO file to a USB flash drive by command line in Linux.

Maybe it is because people prefer to use GUI’s, and some are scared of using the command line, but, interestingly, writing an ISO to a USB flash drive is extremely easy once you understand the commands.

This article is a tutorial, and I will give you step-by-step information about how to write an ISO file to a USB flash drive by command line.

Step 1: Insert Your USB Drive And Find Out Where The USB Drive Is Put By The OS

First, insert your USB drive. And, next, we need to find out exactly exactly where the USB drive is placed by the OS. Do this command to find out where the flash drive is place:
sudo fdisk -l
Once you do the aforementioned command you should get output like:

 Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 4096 bytes
 I/O size (minimum/optimal): 4096 bytes / 4096 bytes
 Disklabel type: dos
 Disk identifier: 0x8a4d7dba

Device Boot Start End Sectors Size Id Type
 /dev/sda1 * 2048 1903480831 1903478784 907.7G 83 Linux
 /dev/sda2 1903482878 1953523711 50040834 23.9G 5 Extended
 /dev/sda5 1903482880 1953523711 50040832 23.9G 82 Linux swap / Solaris

Partition 3 does not start on physical sector boundary.

Disk /dev/sdb: 14.9 GiB, 15938355200 bytes, 31129600 sectors
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disklabel type: dos
 Disk identifier: 0x48dc49bf

Device Boot Start End Sectors Size Id Type
 /dev/sdb1 2048 31129599 31127552 14.9G 7 HPFS/NTFS/exFAT

Since I know that my USB drive is 16GB in size, the one I am looking for is the last /dev/sdb1.

Step 2: Unmount Our USB Flash Drive

Next, before we do anything more, we should unmount our USB flash drive for peace of mind to make sure there are no data loss problems, but don’t remove it from your computer. Since my drive is located at /dev/sdb1 I will do:

sudo umount /dev/sdb1

Step 3: Download the Linux ISO And Then CD Into That Directory

I downloaded the latest version of Linux Mint 32 bit edition and am using it in this example. We need to go into the folder into wherever your iso file is. I am going to assume my file is located at ~/Downloads/

Do:
cd ~/Downloads/

Step 4: Actually Write The ISO To Your USB Drive

Here is the command that will ultimately write the ISO to your USB drive (Don’t actually do it yet, because I need to explain a few things to make sure you do it correctly)

#sudo dd if=linuxmint-18.1-mate-32bit.iso of=/dev/sdb

While this command may seem cryptic, actually, it is easy to understand. dd is a command we can use to write an iso to a usb flash drive in Linux by command line. Nearly every modern Linux distro should have dd installed by default.

From the manual for dd, here are the various options we use in the dd command:

if=FILE means read from FILE instead of stdin
of=FILE mean write to FILE instead of stdout

So in our case for the command:
#sudo dd if=linuxmint-18.1-mate-32bit.iso of=/dev/sdb
linuxmint-18.1-mate-32bit.iso is the file we are reading from (i.e. the iso file we are reading from), and of is where we are writing to, which in our case is /dev/sdb

And as a side note, we need to write to the entire device, /dev/sdb/ instead of /dev/sdb1. As Qubes describes, “Make sure to write to the entire device (e.g., /dev/sda) rather than just a single partition (e.g., /dev/sda1).” So, even though when I did sudo fdisk -l, and found out that my usb drive is located at /dev/sdb1, I still need to use the dd command at /dev/sdb1

OK. Now that you have that background information, we will actually do the command to write the ISO file to your USB flash drive. (make sure to remove the # in the following command once you are ready. I put the # there to prevent accidental problems if you didn’t intend to do the command or didn’t understand the command.)

#sudo dd if=linuxmint-18.1-mate-32bit.iso of=/dev/sdb

After this, the program will “hang” for a little bit. Maybe it will take more than 2 minutes. But eventually, you will see some output such as:

3416064+0 records in
3416064+0 records out
1749024768 bytes (1.7 GB) copied, 958.275 s, 1.8 MB/s

And then you will see a command prompt when the computer has finished writing the ISO to the USB flash drive. Those things tell you that the ISO was successfully written to your USB flash drive.

Final Steps And Comments

Lastly, turn off your computer. Now your USB flash drive should have a Linux distro on it and you can install your new Linux distro from your USB drive. ☺

You may need to configure your motherboard to have USB drives boot first before your hard drive.

There shouldn’t be a need to format your USB drive before writing the ISO to your flash drive(if you are just writing a Linux ISO) before all of these steps in the tutorial it since dd will write over everything on the USB drive. But, just to be safe, you can format it to NTFS or FAT32 with gparted if you want.

What did you think of this article? Did you learn anything interesting? Do you have anything to add? Let’s discuss it in the comments below.

Posted on Categories Linux

5 thoughts on “How To Write An ISO File To A USB Flash Drive By Command Line In Linux”

  1. Thank you. It’s so nice to finally find someone that lays things out in plain English without all the techno babble. Great job.

Leave a Reply

Your email address will not be published. Required fields are marked *