How to format pendrive in Ubuntu using terminal? Commands to format pendrive in Linux Ubuntu command prompt. Unmount the USB drive before you begin to format it.
Find Device ID of USB Drive
Before you start formating the USB drive, you will need to know the device id of the USB drive. This drive id is used to format USB disk using terminal commands. To know the device id of the USB drive, run the command:
As you can see in the screenshot. The sdb3 is the device id of the USB drive.
mkfs is a command used to format a block storage device with a specific filesystem. 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.
mkfs’s syntax is:
mkfs [ -V ] [ -t fstype ] [ fs-options ] filesys [ blocks ]
The items in square brackets are optional, and the only mandatory argument (i.e., input) is filesys. filesys is the name of a device file (i.e., a file that the system uses to implement access to a physical device), such as /dev/hda3.
Format USB Drive
Now unmount the USB device. Whenever any USB drive is attached to Ubuntu Linux system, it’s automatically mounted. While the USB device is mounted you cannot format it. So to format the USB drive, first unmount it using the following command:
sudo umount /dev/sdb3
Now format the USB drive. There are three filesystems options to format the USB drive.
Format USB with Extended File System (Ext) FileSystem
This is the most preferred filesystem from Linux Ubuntu Systems.
$ sudo mkfs.ext4 /dev/sdb3
Format USB with FAT (File Allocation Table) FileSystem
$ sudo mkfs.vfat /dev/sdb3
Format USB Format with NTFS (New Technology File System)
$ sudo mkfs.ntfs /dev/sdb3
Please note to change the USB device id in the above commands. I have used sdb3 which is device id of my USB drive.