Reformatting a USB drive

Jump to: navigation, search

When inserted into a USB slot, USB drives, should show up in the output of /mount or in /proc/mounts.
The filesystem type will show up also in this output. USB drives tend to be formatted for Windows (ntfs via fuseblk)

If you want to reformat a USB drive (reformatting involves deleting all pre-existing data on the drive), firstly you should become root then issue a umount command on the disk device (typically under /dev/sdb1) but leave the USB drive physically attached to the computer.

Create a new filesystem on the USB device with mkfs while specifying the filesystem type with option -t and the former mount point as an argument. Below is an example of mkfs with a filesystem type of ext4.

[root@band media]# mkfs -t ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
265056 inodes, 1058560 blocks
52928 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1086324736
33 block groups
32768 blocks per group, 32768 fragments per group
8032 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

After new filesystem has been created, remove the USB drive then plug it back in again. You should be able to view the new filesystem. Check output of mount and /proc/mounts again.

To create a bootable USB drive

For this example, we'll create a bootable CentOS USB drive.
Firstly, download the .iso file of the OS you want to download. Change directories to the folder that contains your desired OS .iso.

[root@band bwong1]# cd Downloads
[root@band Downloads]# ls

Secondly, plug in a reformatted USB drive. Use the mount command to see the device name of your USB drive.

[root@band Downloads]# mount
/dev/sdc on /media/9fff3ec2-8853-4c6a-a6f0-8a1b2491fb80 type ext4 (rw,nosuid,nodev,uhelper=udisks)

Unmount your usb drive prior to writing the ISO onto it.

[root@band Downloads]# umount /dev/sdc

Now, write the .ISO file into the USB drive with the dd command. if stands for input file and of stands for output file. Send your output file to the USB drive's location.

[root@band Downloads]# dd if=CentOS-6.8-x86_64-LiveCD.iso of=/dev/sdc bs=1M
702+0 records in
702+0 records out
736100352 bytes (736 MB) copied, 132.887 s, 5.5 MB/s