How to format a storage drive using Linux Terminal

Storage devices Used to store processed data, storage devices come in many different forms. Some of the most common types include external or internal hard drives, flash drives (USB), CDs, etc. This tutorial will show you how to format a storage device right from the Linux Terminal.

When you format a storage device, you are essentially erasing all data or information stored on that device, much like restoring a device to its default factory settings. Some reasons you might want to do this include: Remove malware, improve performance, or remove sensitive data before handing over the storage device to someone else.

Note: Always use caution when formatting the drive to avoid losing important information.

If you want to follow along, the best way is to use USB. Note that these steps are the same as for other storage devices. Just make sure you back up your data before formatting the device.

Plug the USB into the PC. Most Linux desktops will automatically mount a storage device after you connect it to your computer. If for some reason the device is not automatically mounted, here is how you can mount the drive in Linux.

The USB will be listed in the file menu or on the desktop depending on your desktop environment. Most Debian-based distributions like Ubuntu will list the drive on the file menu.

How to format a storage drive using Linux Terminal Picture 1

View the properties of the storage device

Before you can proceed to format your storage device, it is important that you are able to list and get the properties of the connected devices on your PC so that you format the storage device correctly.

Open Terminal from the Applications menu or via the keyboard shortcut Ctrl + Alt + T. In Terminal, run the following df command:

df -h

The command lists all available storage devices on the system. The -h option lists storage devices in human readable format.

How to format a storage drive using Linux Terminal Picture 2

Most Linux distributions automatically mount external storage devices such as USB drives in the /media/ directory.

Here, the storage device that we want to format is mounted in the /media/ mwiza/CORSAIR directory, where CORSAIR is the label of the storage device.

Some other important attributes include:

  1. The physical mount address of the storage device, /dev/sda1 in this case.
  2. The size of the drive includes available and used free space, in percent and gigabytes.
  3. Last but not least, the folder containing the USB flash drive; /media/mwiza in this case.

Format the storage device

When a storage device is mounted on your system, Linux assumes that the drive has a fixed size and a specific format. For optimal effect when formatting, it is important that you disconnect your storage device first.

To unmount a storage device, you can use the umount command as shown below.

sudo umount /dev/sda1

Note: In this case, /dev/sda1 is the actual address the storage device wants to format mounted on. Make sure to get the correct mount point of the device on the system.

To format the storage device, use the mkfs (Make filesystem) command. The mkfs command builds the file system on the storage device according to the options specified.

sudo mkfs.vfat -n 'MUO' -I /dev/sda1

The above command formats the specified drive using the FAT32 file format. Alternatively, you can specify a new name or label for the USB. In this case, it will be the MUO and the physical mount point /dev/sda1. The FAT32 file system is compatible with all major operating systems.

In addition to the FAT32 file system, other file system formats that you can use to format your storage device include ext, Minix, MS-DOS, etc.

When the format is complete, unplug the storage device from the computer and then plug it back in. The system will mount the newly formatted drive with the name specified in the command.

You can also check the name of the storage device by running the command df -h.

This tutorial looked at how to format an external storage device on Linux using the mkfs command. As with all things on Linux, there are many other command line tools to format storage devices, you can even use the GUI if you want.

If you're using another operating system, such as Windows, you'll have the option to format your internal or external storage device graphically.

4.5 ★ | 2 Vote

May be interested

  • How to Install Notepad++ on LinuxPhoto of How to Install Notepad++ on Linux
    notepad++ is a popular source code editor among windows users. it supports nearly 78 different programming language syntaxes and includes a lot of features to improve the editing experience.
  • How to change hostname in LinuxPhoto of How to change hostname in Linux
    there are many reasons why you might want to change the hostname of your linux system. unfortunately, changing hostname is not an intuitive process.
  • How to Install CyberPanel on Ubuntu 20.04Photo of How to Install CyberPanel on Ubuntu 20.04
    cyberpanel is a control panel designed to be user-friendly for non-technical users. cyberpanel is easy to learn as it uses a simple layout that most hosting companies are familiar with.
  • What's New in Ubuntu 21.10?Photo of What's New in Ubuntu 21.10?
    version 21.10 is the latest release of ubuntu and although canonical is turning more attention to the cloud and developers, ubuntu 'impish indri' still comes with some notable changes for those users use the ubuntu desktop every day.
  • Canonical releases Ubuntu 21.10 with kernel 5.13 and GNOME 40Photo of Canonical releases Ubuntu 21.10 with kernel 5.13 and GNOME 40
    after a long period of internal testing, canonical has officially announced the release of ubuntu 21.10 'impish indri' with many major changes, such as linux kernel 5.13 and gnome 40.
  • Microsoft brings Sysmon tools to LinuxPhoto of Microsoft brings Sysmon tools to Linux
    microsoft has just released the linux version of the very popular sysmon system monitoring tool on windows. sysmon will allow linux admins to monitor devices to detect dangerous and unusual activities.