Easy way to format USB drive from Linux Command Line

Formatting USB drive in Linux command line is very easy but most of the Linux desktop users are scared to do that and they will go for GUI based application instead of CLI.

 

It’s very simple compared with GUI but you should understand few things before proceeding

First insert your USB into your system and verify whether your USB disk drive is auto mounted or not on your system.

The below output is clearly showing that my USB is already mounted in my system successfully.

Make a note: Make sure you have to identify the correct USB device because you may format other disks wrongly, if you are not choosing the correct one.

Run the following df -h command to list all mounted devices in your system.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
dev             7.8G     0  7.8G   0% /dev
run             7.8G  1.7M  7.8G   1% /run
/dev/nvme0n1p1  217G   83G  124G  41% /
tmpfs           7.8G  674M  7.1G   9% /dev/shm
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
tmpfs           7.8G   38M  7.8G   1% /tmp
tmpfs           1.6G   12K  1.6G   1% /run/user/120
tmpfs           1.6G   32K  1.6G   1% /run/user/1000
/dev/sda2       932G  546G  387G  59% /run/media/daygeek/DATA
/dev/sdb        7.5G  1.5G  6.1G  20% /mnt/usb

If it’s mounted successfully, run the following command to view the data that is available on your USB disk.

$ ls -lh /mnt/usb
total 1.5G
-rwxr-xr-x 1 root root 1.5G Dec  9 07:26 'www.TamilRockers.ci - Ye Mantram Vesave (2018) Telugu Proper 720p HDRip AC3 5.1 x264 1.4GB ESubs.mkv'

Run the following command to view the mount options for your USB disk.

$ mount | grep sdb
/dev/sdb on /mnt/usb type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro)

If you successfully identified the USB disk, just run the following command to unmount the disk.

$ sudo umount /dev/sdb

Once you unmounted the device, run the “df -h” command once again to double confirm whether the device is unmounted or not.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
dev             7.8G     0  7.8G   0% /dev
run             7.8G  1.7M  7.8G   1% /run
/dev/nvme0n1p1  217G   83G  124G  41% /
tmpfs           7.8G  364M  7.4G   5% /dev/shm
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
tmpfs           7.8G   38M  7.8G   1% /tmp
tmpfs           1.6G   12K  1.6G   1% /run/user/120
tmpfs           1.6G   48K  1.6G   1% /run/user/1000
/dev/sda2       932G  546G  387G  59% /run/media/daygeek/DATA

Format the USB drive with FAT filesystem to use the USB in all kind of systems like Windows, Linux, etc,.

$ sudo mkfs.vfat /dev/sdb
mkfs.fat 4.1 (2017-01-24)

Format the USB drive with NTFS filesystem to use the USB device only in Windows system.

$ sudo mkfs.ntfs /dev/sdb

Format the USB drive with Ext4 filesystem to use the USB device only in Linux system.

$ sudo mkfs.ext4 /dev/sdb

Format the USB drive with XFS filesystem to use the USB device only in Linux system.

$ sudo mkfs.xfs /dev/sdb

Once you format your USB, again mount your USB disk back to verify whether all the data got erased or not.

$ sudo mount /dev/sdb /mnt/usb

Yes, it’s got erased as i can see only 1% utilization on the disk.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
dev             7.8G     0  7.8G   0% /dev
run             7.8G  1.7M  7.8G   1% /run
/dev/nvme0n1p1  217G   83G  124G  41% /
tmpfs           7.8G  431M  7.4G   6% /dev/shm
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
tmpfs           7.8G   49M  7.8G   1% /tmp
tmpfs           1.6G   12K  1.6G   1% /run/user/120
tmpfs           1.6G   44K  1.6G   1% /run/user/1000
/dev/sda2       932G  546G  387G  59% /run/media/daygeek/DATA
/dev/sdb        7.5G  4.0K  7.5G   1% /mnt/usb

Vinoth Kumar

Vinoth Kumar has 3.5+ years of experience in Linux server administration & RHEL certified professional. He is currently working as a Senior L2 Linux Server administrator.

You may also like...