Tuesday, 22 July 2014

How to create a bootable usb drive from an .iso in the command line on Linux

Mr. Borgstrom has an excellent article for creating a bootable usb key from an iso in the Terminal on Mac. Now that's great and all, and i have used his method for many installation setups on Mac,
but I am constantly looking for ways of doing things on Linux. After some experimentation I created a bootable usb drive of Kali Linux with only a few commands.

Linux is VERY good for working with disks and that sort of thing once you get the hang of it.
You'd be surprised at the power you can muster at a good old command line.
In fact, i have found myself using more and more of the Terminal on Mac for just regular everyday stuff, like moving files rather than dragging and dropping in Finder.

Objective:

In this article i show you how you can create a bootable usb drive from an .iso image which you can then you to run your live Linux system from or proceed however you see fit.

This should only take a few minute for you to accomplish (the bulk of the time is copy the image to disk).

What you will need:

  1. A GNU/Linux system
  2. and USB thumb drive with enough room to fit your iso
  3. sudo or root access
  4. An ISO image of the Linux distro you want to boot

What I will be using:

  1. Linux Mint 17 64bit (not primarily for the desktop, but for the stability and versatility.)
  2. 8GB USB Flash Drive
  3. kali-linux-1.0.7-amd64.iso (2.96G) Kali Linux Hackers Distro

Procedure:

Step 1: Plug in your USB flash drive and find its identifying path

Before you plug in the flash drive, enter:

~$ fdisk -l

See which disks there are.

Plug the drive into the computer, find its identifying path with:

~$ fdisk -l

The drive is there that wasn't before in the previous fdisk -l, is the one you wan't to use.
Confirm that the disk sizes are that of the flash drive. Should be something like /dev/sdb or
/dev/sdc

I identified it by its size. Mine is 8GB
The root identifier (not a certain partition) is /dec/sdc


Step 2: Delete all partitions on /dev/sdc and make free space

Now we want to make the flash drive into purely free space.
We will use cfdisk to accomplish this from the command line.
Double check that you know which device your flash drive is. If the next command is performed on
the main hard drive, there could be irrecoverable data loss and system damage. You have been warned.

~$ cfdisk /dev/[your device]
e.g
~$ cfdisk /dev/sdc


Now what you see here is the Textual User Interface of cfdisk. Also since i used this particular flash drive for a previous usb installation, you will see that "Kali Live" of the iso9660 type is the boot partition.

We want to delete all partitions to its just free space.

For each partition, unless its already free space, use the arrows keys to navigate over it, the delete it like this:

 Hit enter.

You should now have this:

Write the changes to disk by pressing enter when the [ Write ] button is activated. Confirm by entering :yes

Quit cfdisk.

Step 3: Copy the image to the flash drive

The rest of the process is really is waiting on one command to complete.
We now want to copy the .iso to /dev/sdc or whatever device is yours.

Make sure the iso you want to boot is in your working directory (~ or something)

Do the copying:

~$ dd if=./kali-linux-1.0.7-amd64.iso of=/dev/sdc ibs=4M obs=4M

You have to wait for this to complete. DON'T STOP IT if you get impatient.
For me this command took about 15 mins.
The time it takes depends on a few factors.

  1. The size of the image you wish to copy
  2. The write speed of of you flash drive
  3. The block size (We used block of 4M to speed it up. Don't use ibs, bs, or obs over 20M)

Once dd is done, you should see something like this:


Hey, we discovered the write speed of our flash drive by accident! Mine is 9.5 MB/s

You should now be able to boot into the flash drive normally.

If you wish to thank me you can comment or even consider subscribing.
Otherwise, i hope this was helpful.

Cheers,
Rudker


1 comment: