Securely Formatting a Drive All Data: A Comprehensive Guide Using the Linux Terminal

Chinmay Roy
2 min readJul 29, 2023

--

To format a drive using the Linux terminal, you can use the mkfs command to create a new file system on the drive. However, please note that formatting a drive will erase all data on it, so make sure you have a backup of any important data before proceeding. Also, be absolutely sure you are selecting the correct drive to format to avoid data loss.

The steps to format a drive using the Linux terminal are as follows:

  1. Identify the Drive: First, you need to identify the drive you want to format. You can use the lsblk or fdisk -l command to list all the available drives and their partitions.
lsblk

The output will display a list of drives and partitions, such as /dev/sda, /dev/sdb, etc.

  1. Unmount the Drive: Before formatting the drive, ensure that it is unmounted. If it’s currently mounted, you need to unmount it first. Assuming the drive you want to format is /dev/sdb, you can unmount it with the following command:
sudo umount /dev/sdb
  1. Format the Drive: Now that the drive is unmounted, you can proceed with the formatting using the appropriate file system type. Below are some examples of how to format the drive with different file systems:

a. Format as Ext4 (commonly used on Linux systems):

sudo mkfs.ext4 /dev/sdb

b. Format as NTFS (commonly used on Windows systems, but can also be used on Linux with ntfs-3g installed):

sudo mkfs.ntfs /dev/sdb

c. Format as FAT32 (compatible with both Linux and Windows systems):

sudo mkfs.fat -F32 /dev/sdb
  1. Verify the Format: After the formatting process is complete, you can verify the new file system on the drive using the file -s command:
sudo file -s /dev/sdb

The output should indicate the file system type (e.g., “ext4”, “ntfs”, “vfat” for FAT32).

Please ensure you have the correct drive name, as formatting the wrong drive can result in data loss. Double-check the drive name before executing the format command.

Remember to exercise caution when using terminal commands that modify drives, as incorrect usage can lead to data loss. Always back up important data before performing any disk operations.

--

--

Chinmay Roy
Chinmay Roy

No responses yet