Page 1 of 1

Burning a bootable ISO to a Flash Drive Rate Topic: -----

#1 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 37
  • View blog
  • Posts: 606
  • Joined: 31-December 08

Posted 09 November 2014 - 11:29 AM

Introduction
In this tutorial I am going to demonstrate how to quickly create a bootable USB from an ISO file by simply running a few commands in Linux Terminal. If you are reading this tutorial you probably already know why you would want to do this but the most common reason is to install an operating system on a flash drive. Be very careful when typing in the commands (and do not copy + paste directly as that usually includes formatting from the post). Since you will be replacing the contents of whatever drive you enter (should be the flash drive) it is very easy to specify the wrong drive and overwrite your main hard drive. It should be noted that this tutorial also works for writing IMG (.img) files to sd cards.


PLEASE NOTE: If you follow this tutorial the ISO file will completely replace the contents of the flash drive.
This means you should back up any files on the flash drive that you do not want to lose before you continue this tutorial.


Getting the drive designation
In order to burn the ISO file to a flash drive first we have to determine what the computer calls the flash drive. We can use the df -h command to view all currently mounted drives. So make sure you don't currently have the Flash Drive you want to write to in your computer and then run that command. This should show all currently monted drives. Now plug-in the Flash Drive (most desktop environments of linux will automount it for you) and execute the command again. You should see a new drive appear, (it should look similar to /dev/sdb1, although yours may not have a "b" after the "sd" and may be another letter instead) this is the designation of your Flash Drive.

Unmounting the drive
Now that you know the designation of the Flash Drive we are going to want to unmount it. Unmounting a drive from your computer is different than ejecting. Ejecting completely removes it while unmounting simply means its not in use so another process can use it, in our case write to it. In order to unmount it we need to run the following command:
sudo umount (put drive designation here for example /dev/sdb1)
Simply put the drive designation in their and remove the parentheses. (should look like this sudo umount /dev/sdb1) You will probably be prompted to enter your password as well.

Writing the ISO to the drive
Now we can finally write our file to it. In order to do that we need to execute this command:
sudo dd bs=4M if=/path/to/file.iso of=/dev/sdb
This will install your iso file to the drive. Notice we removed the 1 part of the drive designation. This is because the one was referencing a specific partition (or region) of the drive and we want to write the ISO file to the whole drive. Also you will need to replace the "/path/to/file.iso" with the actual path. If you do not know the path to the ISO file, simply right click it, click properties and and get it from there. The "bs=4M" part makes the file transfer much faster but may cause issues on few computers if you have problems with it use "bs=1M" instead. Now after you execute this command you may again be asked to enter your password if you are just enter it again. Then the terminal should just seem to hang, this is because there is no progress bar. It can take anywhere from a few minutes to 20 or 30 minutes to complete depending on the size of the ISO file and your computer so just be patient. After it completes you should see a few lines output and be back a prompt.

Hopefully this tutorial helped you, thanks for reading and if you have any problems please post them below! :)

Is This A Good Question/Topic? 0
  • +

Replies To: Burning a bootable ISO to a Flash Drive

#2 JWHSmith  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 9
  • Joined: 13-November 14

Posted 14 November 2014 - 10:47 AM

I'd like to add a little warning regarding the final dd call that you are making here. As you can see, this call writes /path/to/file.iso straight into the drive, /dev/sdb. This transforms your drive into a bootable storage device (by writing into the Master Boot Record), which is exactly what you need when you're trying to burn an operating system's live distribution.

However, you must keep in mind that dd is quite a straightforward tool, and as the author said...

Quote

If you follow this tutorial the ISO file will completely replace the contents of the flash drive.

Actually, to be more accurate: it will alter everything that's on your drive, and that is not only your files, but also your partition table and filesystems. No matter how your key is organised, everything's is going to be wiped out (or partially wiped out) when you burn the ISO.

Here is an example I just had with one of my keys. There is the partition's table before burning the ISO:

# fdisk -l /dev/sdb

Device           Start       End        Blocks    Id  System
/dev/sdb1        2048        3944447    1971200   83  Linux

In my case, /dev/sdb1 is the unique partition of my key (it takes all the available space). It is an ext4 filesystem on which I have stored a simple text file. Now, since I'm an Arch Linux lover, I decide to burn one of my Arch ISOs on the drive...

# dd if=/my/archlinux/file.iso of=/dev/sdb
1103872+0 records in
1103872+0 records out

And now, have a look at my partition table...

# fdisk -l /dev/sdb

Device      Boot      Start       End          Blocks    Id   System
/dev/sdb1    *        0           1103871      551936    0    Empty
/dev/sdb2             248         63735        31744     ef   EFI (FAT-12/16/32)

As you can see, dd copied absolutely everything from the ISO, and this include a new partition table. Besides, as you can see, these partitions only need 551936+31744 = 583680 blocks, while my drive provides 1971200 (+70%). This means that once you're done installing your OS, and want your key back, formatting these partitions won't be enough: you'll have to rebuild the partition table first.

For this reason, I would recommend rebuilding the partition table of your key every time you're done with an burnt ISO (when you want your key back, or when you want to burn another ISO on it). This can be done quite easily with fdisk but GParted will do just fine if you're more at ease with a GUI. Here is a little example of how you can rebuild a simple, one-partition table, and format it:

# fdisk /dev/sdb
Command (m for help): d
Partition number (1-4): 1        # there, I am deleting /dev/sdb1

Command (m for help): d          # now, /dev/sdb2, which is the only one left
Selected partition 2

Command (m for help): n          # creating a new primary partition with default values
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended

Select (default p): p
Partition number (1-4, default 1): 1
First sector (n-m, default n):
Using default value n
Last sector (n-m, default m):
Using default value m

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Now that you've recreated a clean /dev/sdb1, you may format it (here, as an ext4 filesystem) :

# mkfs.ext4 /dev/sdb1

And there you go, your key is ready to be used again!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1