How to create bootable USB using CLI

How to create bootable USB using CLI

Hey! I was curious about if we can create a bootable USB drive from Command Line Interface alone. I always have my utmost trust in CLI but this task sought to be tricky. Therefore, I set myself relaxed and dived to search a solution on duckduckgo.

Surprisingly, I found the solution much sooner than my expectation. Following is a simple, efficient and fast way to create a bootable USB drive only from your command line.

Note: I am using my Ubuntu 16.04 LTS in this tutorial. You may continue with other GNU/Linux distros as well. Months back I wrote the post on How to make a Bootable pen drive using Rufus? feel free to have a look on it (in case you want to create bootable USB from windows.)

Requirements

  1. Any GNU/Linux distros.
  2. A formatted USB drive.
  3. ISO image of Operating System.

Step by step

1. Have a look at existing devices

1. Use the command lsblk to see the list of existing block devices in your system

$ lsblk
NAME  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda     8:0    0 298.1G  0 disk 
├─sda1  8:1    0  11.4G  0 part 
├─sda2  8:2    0   350M  0 part 
├─sda3  8:3    0 114.2G  0 part 
├─sda4  8:4    0     1K  0 part 
└─sda5  8:5    0 172.1G  0 part /
loop0   7:0    0  86.9M  1 loop /snap/core/4917
loop1   7:1    0  86.9M  1 loop /snap/core/4830

2. Identify your device

  1. Plug-in your USB device.
  2. Use lsblk again to identify your device. In my case it is sdb->sdb1
$ lsblk
NAME  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda     8:0    0 298.1G  0 disk 
├─sda1  8:1    0  11.4G  0 part 
├─sda2  8:2    0   350M  0 part 
├─sda3  8:3    0 114.2G  0 part 
├─sda4  8:4    0     1K  0 part 
└─sda5  8:5    0 172.1G  0 part /
sdb 8:16 1 7.5G 0 disk
└─sdb1  8:17   1   7.5G  0 part /media/shiva/myusbdrive 
loop0   7:0    0  86.9M  1 loop /snap/core/4917
loop1   7:1    0  86.9M  1 loop /snap/core/4830

3. Unmount your USB

To make your USB bootable, first, you need to unmount it.

$ umount /dev/sdb1

If the command above doesn’t work try it with sudo.

Note: Make sure you are selecting the correct device.

Make sure that the device is unmounted using lsblk command again, and notice that the MOUNTPOINT for your device has been removed.

$ lsblk
NAME  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda     8:0    0 298.1G  0 disk 
├─sda1  8:1    0  11.4G  0 part 
├─sda2  8:2    0   350M  0 part 
├─sda3  8:3    0 114.2G  0 part 
├─sda4  8:4    0     1K  0 part 
└─sda5  8:5    0 172.1G  0 part /
sdb 8:16 1 7.5G 0 disk
└─sdb1  8:17   1   7.5G  0 part 
loop0   7:0    0  86.9M  1 loop /snap/core/4917
loop1   7:1    0  86.9M  1 loop /snap/core/4830

4. Make it bootable

To make a bootable USB. In GNU/Linux we have a simple tool: dd command:

$ sudo dd bs=1M if=/path/to/os_image.iso of=/dev/<device> conv=fdatasync

Here:
<device> should be replaced with your device name. In my case it is sdb.

NOTE: <device> will be replaced with your device root name in my case it is “sdb” not “sdb1”. If you go with “sdb1” then your device might not be able to boot. So in my case, the command would be like:

$ sudo dd bs=1M if=~/Downloads/Fedora/Fedora-Workstation-Live-x86_64-28-1.1.iso of=/dev/sdb conv=fdatasync
[sudo] password for shiva: 
1705+0 records in
1705+0 records out
1787822080 bytes (1.8 GB, 1.7 GiB) copied, 309.198 s, 5.8 MB/s

It may take a while to complete. You may understand different attributes in this command from its help menu $ help dd.

5. Have fun!

Believe it or not but your USB is now bootable. I tried this method to make my bootable USB to install Fedora28. And my device is good to go. I tried to run Fedora in try mode first, and soon going to install it.

Thanks to Hayk Gevorgyan for his post: https://linoxide.com/linux-how-to/create-bootable-ubuntu-usb-flash-drive-terminal/

Thanks for reading!

Advertisements

3 thoughts on “How to create bootable USB using CLI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s