How to format a drive via terminal on Linux

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will lean how to format a drive by using the terminal on your Linux machine.

Formatting a drive can be done easily when it comes to using GUI. However, when your server doesn't have a GUI, then the only way to format your drives is by using the terminal.

mkfs command allows you to format your drives easily directly from your Linux terminal.

mkfs command also allows you to choose the filesystem you want to create before formatting, choosing the filesystem is necessary when you are formatting a drive on Linux and preparing it to use on a system like Windows.

In this tutorial, we'll be formatting a usb drive by using the mkfs command.

Step 1 - Select your drive

Plugin the usb drive that you want to format, and run the command below to verify that your drive is plugged in and it can be formatted.

To check all devices that are plugged in on your system, you can do so by using the lsblk command.

lsblk

If you are not sure which of the devices listed is the usb drive that you want to format, then you can check the size of drives.

For example, if your usb drive has 32GB storage, then the size of the usb drive that is showing on your terminal should be something like 28-32GB depending on the usb drive type.

Step 2 - Prepare your drive

Once you have identified your drive, you need to unmount it from your system before formatting it.

To unmount your usb drive, you can do so by using the umount command.

sudo umount /dev/sdc1

Once unmounted, proceed to next step to format your drive.

Step 3 - Format your USB drive

Your usb drive should be unmounted now, and you can proceed to format it.

Before formatting your usb drive, make sure you've chosen the right fileystem for your usb device.

With mkfs you can format your usb drive using any of the supported filesystems, such as : FAT, ext2,ext3,ext4,NTFS or HFS.

Format USB drive using NTFS Filesystem

If you want to be able to use your USB drive on multiple operating systems such as Linux, Windows and MacOS, then you should format your drive using the NTFS filesystem.

sudo mkfs -t ntfs /dev/sdc1

Format USB drive using ext4 Filesystem

If you will be using this usb drive only for Linux, then you can go with ext filesystem.

To format a USB drive using the ext4 filesystem, you can do so by running the command below.

sudo mkfs -t ext4 /dev/sdc1

Format USB drive using FAT filesystem

To format a USB drive by using the FAT filesystem, simply set FAT as the filesystem.

sudo mkfs -t FAT /dev/sdc1

Step 4 - Verify

Your usb drive should be formatted depending the filesystem you chose.

To verify that your drive was formatted correctly, you can use the lsblk command with -f option to show the filesystems of the drives.

lsblk -f

As you can see, our usb drive that we formatted, is now showing the filesystem we formatted it with.

Conclusion

In this tutorial, you learned how to format a drive on Linux using ext4, FAT and NTFS filesystems via the mkfs command.