- How To Write An ISO File To A USB Flash Drive By Command Line In Linux
- Step 1: Insert Your USB Drive And Find Out Where The USB Drive Is Put By The OS
- Step 2: Unmount Our USB Flash Drive
- Step 3: Download the Linux ISO And Then CD Into That Directory
- Step 4: Actually Write The ISO To Your USB Drive
- Final Steps And Comments
- How to Make Bootable USB from ISO using Linux Terminal
- Make Bootable USB from ISO using Linux Terminal
- Step1: Check USB Drive
- Step 2: Download Linux ISO File
- Step 3: Create Bootable Drive from Terminal
- Conclusion
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:
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/
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.
How to Make Bootable USB from ISO using Linux Terminal
There are many USB creator software available to create a bootable Linux USB Drive. Here I will show you how to create a bootable USB flash from ISO file using the Linux terminal.
Before we start make sure you have downloaded the .ISO file and have a USB flash drive with not less than 4GB capacity.
Make Bootable USB from ISO using Linux Terminal
Follow the steps to make a bootable USB from iso file using the terminal.
Step1: Check USB Drive
Connect the USB flash drive to your machine and check if it’s connected successfully. Use lsblk command to list all information about the attached block devices.
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 10G 0 disk └─sdb1 8:17 0 10G 0 part sr0 11:0 1 1024M 0 rom sdc 8:32 1 14.9G 0 disk ├─sdc2 8:34 1 2.3M 0 part └─sdc1 8:33 1 1.7G 0 part /media/linoxide/SANDISK sda 8:0 0 20G 0 disk ├─sda2 8:2 0 1K 0 part ├─sda5 8:5 0 1022M 0 part [SWAP] ├─sda3 8:3 0 7.9G 0 part └─sda1 8:1 0 9G 0 part /
From the list find your USB drive’s mounted partition. In our case it’s /dev/sdc1. It is mounted by default.
Next, we must unmount the USB flash drive by the following command:
Make sure to change according to your USB drive and check if it has been unmounted again with lsblk command.
You must see the output without mount point in front of sdc1:
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 10G 0 disk └─sdb1 8:17 0 10G 0 part sr0 11:0 1 1024M 0 rom sdc 8:32 1 14.9G 0 disk ├─sdc2 8:34 1 2.3M 0 part └─sdc1 8:33 1 1.7G 0 part sda 8:0 0 20G 0 disk ├─sda2 8:2 0 1K 0 part ├─sda5 8:5 0 1022M 0 part [SWAP] ├─sda3 8:3 0 7.9G 0 part └─sda1 8:1 0 9G 0 part /
Step 2: Download Linux ISO File
Here we will create a Ubuntu bootable flash drive, first go to ubuntu website and download the iso file to your Linux computer. Or you can download iso file from the command line using wget or curl command.
This will download iso file to the current directory.
$ wget http://cdimage.ubuntu.com/focal/daily-live/current/focal-desktop-amd64.iso
$ curl -O http://cdimage.ubuntu.com/focal/daily-live/current/focal-desktop-amd64.iso
Step 3: Create Bootable Drive from Terminal
We are going to use dd command to create a bootable USB flash drive.
Be cautious using the dd command of overwriting or deleting your data. Make sure you have backup
$ dd bs=4M if=/path/to/input.iso of=/dev/sd conv=fdatasync
Where /path/to/input.iso is the path where .iso image downloaded. Make sure to change with your USB disk letter accordingly. The point here is to write the disk name itself (e.g. /dev/sdc) and not the partition (e.g. /dev/sdc1). Sets the block size to 4 megabytes, which can improve the speed of the data transfer.
$ dd bs=4M if=/tmp/ubuntu-20.04.1-desktop-amd64.iso of=/dev/sdc conv=fdatasync
Where bs is read and write BYTES bytes at a time, if is the input file, of is the output file. The conv=fdatasync bit is important as dd can return before the write operation finishes.
By default the progress of the command will not be displayed, to view the progress you can use pv command:
$ dd if=/tmp/ubuntu-18.04-desktop-amd64.iso | pv | sudo dd of=/dev/sdc bs=4M conv=fdatasync
Note: From the 8.24 version of GNU Coreutils, dd command has the option to show the progress (status=progress). Not all Linux distributions may have pv installed by default. If it is not installed on your system, you can usually install it using your distribution package manager.
After the process is finished you can use USB as a bootable drive for Ubuntu installation or repair.
Conclusion
Using the terminal to create a bootable USB drive is much easier and way faster than with GUI tools. Also, it is very useful to know how to do it in a terminal, because there isn’t always a GUI available. The main disadvantage, in this case, is that there is no double-check option for dd . GUI tools help you to identify and select the target drive, and provide a final checkpoint, where you can double-check, that you will be writing to the correct drive.
If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks