Reformatting a USB drive

From DISI
Revision as of 17:06, 24 August 2016 by Benrwong (talk | contribs) (reference for reformatting USB drives)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to 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 (either vfat or msdos)

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.