Creating a bootable USB flash drive using dd
July 9th 2020 on Dušan's blog
In this article we'll go through the process of creating a bootable USB flash drive using the dd command. As stated previously on this blog, you must be careful when using dd because if used incorrectly you may end up overwriting the wrong drive. You have been warned.
- An already working GNU/Linux installation.
- An 8GB or more USB flash drive.
- An ISO image of the operating system you want to boot.
To begin, plug in your USB drive into one of the available USB ports on your computer.
We need to find out the device name, the quickest way to do so is to run the lsblk command
The output of this command contains valuable information about the block devices installed on your system:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 223.6G 0 disk ├─sda1 8:1 0 499M 0 part ├─sda2 8:2 0 99M 0 part ├─sda3 8:3 0 16M 0 part ├─sda4 8:4 0 143G 0 part ├─sda5 8:5 0 512M 0 part /boot └─sda6 8:6 0 79.5G 0 part / sdb 8:16 0 931.5G 0 disk ├─sdb1 8:17 0 1M 0 part ├─sdb2 8:18 0 127M 0 part └─sdb3 8:19 0 931.4G 0 part sdc 8:32 1 7.3G 0 disk /run/media/dusan/A727-A6A5 sr0 11:0 1 1024M 0 rom
Based on the SIZE property we can conclude that the USB drive is in fact the device named sdc.
It's also important to ensure that the device isn't already mounted in the file system. If we refer to the MOUNTPOINT property, we can see that the USB drive is mounted in this location:
To unmount it we'll use the umount command, referencing the drive name like this:
The "x" in the USB drive name is a placeholder value, replace it with your actual device name, for example "sdc".
To proceed, the USB drive must be blank, the way to ensure this is to reformat the file system. This will obviously result in the loss of all data on the USB drive so you should back up all the data beforehand.
To reformat the drive we can use the mkfs command like this:
sudo mkfs.vfat /dev/sdx -I
This will reformat the entire drive to FAT32. The -I option tells the system to use the entire drive for the filesystem instead of using partitions.
Finally, we're ready to start making the USB drive bootable. As stated we'll utilize the dd command to do so:
sudo dd bs=4M if=/path/to/ISO/file of=/dev/sdx status=progress && sync
The bs=4M option tells to system to write the data to the USB drive in chunks of 4MB each.
The if=/path/to/ISO/file option specifies the absolute (or relative) path to the ISO file you want to boot.
The of=/dev/sdx option specifies which drive to write to. It is very important to choose the correct drive letter, failure to do so will result in the loss of data on the wrongly specified drive.
If this process is successful your drive will be ready to boot your favorite operating system. Once you no longer need the bootable drive, to restore it to normal, simply repeat the reformatting process described above.