Select Page

To see all the connected storages in the Linux system use the command


Format a drive completely with a brand new partition table

In this tutorial, I am using ‘parted’ as it’s easy to use and can handle both MBR and GPT partitioning tables, but feel free to use your favorite partitioning tool. The procedure can be used on any storage device, external or internal.

sudo parted /dev/sdb

Doublecheck to make sure to add the block device you want to format; otherwise, parted will run on ‘sda’ or the drive where your OS is installed and you may end up with a broken system. The tool is extremely powerful and choosing the wrong device may lead to valuable data loss, so please use caution while formatting your drives.

After entering the password, you will notice (parted) added, which means you are now inside the parted utility.

Now we have to create a new partition table. There is a good old MBR (master boot record) and a newer GPT (GUID partition table).
A comparison between the two is beyond the scope of this story. In this example, we will use MBR.

(parted) mklabel msdos

Here ‘mklabel’ creates the partition table and ‘msdos’ will use MBR. Now we can create partitions. This is the basic format of the command:

(parted) mkpart ‘type of partition’ ‘file system’ start end

If I want to use all the space and create one big partition I will run this command:

(parted) mkpart primary ext4 1MiB 100%

Here 100% means it will use all the available space. But if I want to create more than one partition, I will run this command:

(parted) mkpart primary ext4 1MiB 2GB

Here it will create a partition with 2GB storage. Next, we’ll create another partition, but because we already have one partition, the endpoint of the previous partition is now the starting point of the next partition.

(parted) mkpart primary ext4 2GB 5GB

This command will create a second partition of 3GB. If you want to create one more partition for the remaining space, you know the endpoint and the start point:

(parted) mkpart primary ext4 5GB 100%

You can replace ‘ext4’ with the desired file type: ntfs, vfat, btrfs…

To see how the partitioning has worked, run the print command:

(parted) print

It will display the partitions you created. If everything looks as expected, you can exit the partitioning tool by typing ‘quit’:

(parted) quit

Running the lsblk command will show the newly created partitions. We need to now format these partitions before we mount and use them. In my machine, there are now three partitions on sdb: sdb1, sdb2, sdb3. We will format each with ext4.

sudo mkfs.ext4 /dev/sdb1

Repeat the same step for each drive — just change the block device name and number.

Now, your drives are formatted. If it’s an external drive like a USB drive, just unplug and plug it to mount it.