Great advice given in this thead. I’m being the “community secretary” and collecting it to one post, for a step-by-step guide, in case someone else is wondering how to create a bootable USB stick from an ISO file using command dd in terminal.
Mandatory warnings:
- When using dd always TRIPLE CHECK the if (input file, the source) and of (output file, the target) assingments. Do it wrong and you just borked your hard disk!
- Always check the drive assignment with dmesg or fdisk -l. Do not trust “it’s always been /dev/sdc”.
CREATING A BOOTABLE USB STICK FROM AN ISO FILE USING dd IN TERMINAL
Plug the USB stick in. Check dmesg output to find out the device assignment (or check with sudo fdisk -l).
$ dmesg
Look for line “Attached … removable disk” close to the end of the listing. In this example output you can see [sdc] which means it’s /dev/sdc. We will use that in the following steps.
[1234.1234] sd 7:0:0:0: [sdc] Attached SCSI removable disk
Make sure the USB stick is unmounted (ignore the possible error messages for individual partitions):
$ umount /dev/sdc*
Issue the needed commands (dd and its friends)all in one go, individual commands separated by a semicolon:
$ sudo dd if=/home/username/Downloads/example.iso of=/dev/sdc bs=1M status=progress conv=fdatasync;sudo eject /dev/sdc
Commands explained:
sudo dd - will copy “bit-by-bit”
if - input file; name of the ISO file with full path
of - output file; target device (figured out in step 1).
bs - bytes to read and write at a time (10M was suggested, I use 1M, default is 512, I believe)
status=progress - shows a progress bar so you know something is happening (I’ve noticed it’s not always working)
conv=fdatasync - flush buffers to disk, making sure everything is written to the USB disk (does same as a separate “sudo sync” command would do, as pointed out by @ouroumov in this post further down this thread)
sudo eject - unmounts the partitions (if mounted) and detaches the drive. You can now unplug the stick.
WANT YOUR USB STICK BACK FOR DATA USE?
dd stands for Disk Dump, which describes it perfectly. It “dumps” the source disk to your target disk as is, bit-by-bit. In other words: makes a clone. So if you are using a 4 GB stick for a 1.2 GB ISO, you won’t have 2.8 GB at the ready for storing your holiday snaps.
When you want to return the stick to regular data saving use, you need to reformat it. If you prefer using GUI tools, you can do this in GParted or Disks. There are also apps made just for this purpose.
I like the command line, so here are instructions for working in the terminal.
REPARTITION AND FORMAT USB STICK FOR DATA USE
Plug the stick in. Check drive assignment with dmesg (right after plugging the stick in) or with sudo fdisk -l. We use /dev/sdc in this example.
Make sure drive is not mounted:
$ sudo umount /dev/sdc*
Wipe off file system and/or partition table signatures from the device (to ensure fdisk in next step works without issues):
$ sudo wipefs --all /dev/sdc
Create a fresh, new partition table, one new partition (primary) and write the changes to disk. All in one go, again in order to avoid navigating the fdisk menus:
$ echo -e "o\nn\np\n1\n\n\nw" | sudo fdisk /dev/sdc
The “o\nn\np\n1\n\n\nw” stanza explained (\n after each individual option stands for line feed):
echo o # Create a new empty DOS partition table
echo n # Add a new partition
echo p # Primary partition
echo 1 # Partition number
echo # First sector (Accept default: 1)
echo # Last sector (Accept default: varies)
echo w # Write changes
Format stick as VFAT (32-bit fat) and give it label WINDISK:
$ sudo mkfs.fat -F32 -v -I -n "WINSTICK " /dev/sdc1
Remove the disk safely:
$ sudo eject -v /dev/sdc