Wednesday, March 4, 2015

Format USB and write image from terminal command

1. Insert your USB drive into your system.
2. Open the terminal. (CTRL + ALT + T)
3. Look for the USB drive you want to format, by running:

 df
 
The command above will display the directory path of your various drives. Take note of the drive you wish to format.

df-command-unixmen

In this tutorial, the name of the drive am going to format is Seth and its path under the filesystem is /dev/sdc1.

3. Unmount drive using the syntax below:

 sudo umount /dev/sdc1
 
umount

4. Now run this command to format drive to fat32:

 sudo mkfs.vfat -n 'Ubuntu' -I /dev/sdc1
 
mkfs.vfat-unixmen

Understanding the above command

mkfs

mkfs is used to build a Linux filesystem on a device, usually a hard disk partition. The device argument is either the device name (e.g. /dev/hda1, /dev/sdb2), or a regular file that shall contain the filesystem. The size argument is the number of blocks to be used for the filesystem.

vfat

Formats the drive to FAT32, other formats available are mkfs.bfs, mkfs.ext2, mkfs.ext3, mkfs.ext4, mkfs.minix, mkfs.msdos, mkfs.vfat, mkfs.xfs, mkfs.xiafs etc.

-n

Volume-name sets the volume name (label) of the file system. The volume name can be up to 11 characters long. The default is no label. In this tutorial my volume-name is Ubuntu.

-I

It is typical for fixed disk devices to be partitioned so by default, you are not permitted to create a filesystem across the entire device.

format-complete

Running $ df after formatting displays this.

df-after-format-unixmen

You are done and your pen drive has successfully been formatted.


In order to create a bootable USB flash drive, you will need coreutils (which provides dd). Most GNU distributions have coreutils already installed.
To use dd, open a terminal and write (substitute the correct path):

sudo dd if=/path/to/the/downloaded/iso of=/path/to/the/USB/device


to see the progress of this, open a separate terminal window and do
watch -n5 'sudo kill -USR1 `pgrep ^dd`

which every 5 secs reports the progress in the initial terminal window (source)


To check if the creation of the bootable USB stick was successful, use fdisk as root to check it. You should see an asterisk (*) like this in your USB line:

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 697 713728 17 Hidden HPFS/NTFS



(Sources here and here.)

---


As this may not always lead to success, here is a second solution:

get the script from here and make it executable(as root, with chmod +x /usr/bin/live-fat-stick) after copying it to /usr/bin/, make sure you have syslinux and gpart installed before running it.
Run the following as root (with su -, not using sudo) in terminal:
# live-fat-stick -l
to get the USB device path.

# live-fat-stick --suse /path/to/openSUSE-filename.iso /dev/sdXY
to copy iso to USB device and make it bootable.

# live-fat-stick -h
it shows help.

Multiple iso images from multiple distributions can be added to the USB device, boot menu will offer a choice of distribution to boot from. Scripts does not format or remove data from the device.
 

No comments:

Post a Comment