Search

Formatting pen drive in command prompt

In older versions of linux distros the option to format pen drive or any hard disk is not available in the GUI. Or in case you are stuck in the text mode and want to format a disk , here is a way out.

The command "mkfs" and its variants are meant to create a  filesystem on a disk. There are various "mkfs" commands depending on what file system you want to create on the disk. The most commonly used are
mkfs.ext2, mkfs.ext3, mkfs.vfat  where they are used to create ext2,ext3 and FAT file system on the disk respectively.

If you want to use your disk with windows too then it is recommended to use "mkfs.vfat" as windows can not recognize ext filesystem.
To format the disk, plug it into the system.
Open a terminal and run the command
$ df -h
Example output
/dev/sda1              46G   10G   34G  23% /
/dev/sdb1             1.9G  694M  1.2G  37% /media/NS

External disks are listed under /media, hence from the above output we can figure out that the partition to be formatted  is "/dev/sdb1" which is listed in the first column of the corresponding disk.

Now run the following to format the disk 
NOTE: All data in the disk be lost and can not be recovered.

$ umount /dev/sdb1
$ sudo mkfs.vfat /dev/sdb1


That is it, your disk should be formatted and clean now.

Follow by Email