Creating ext4 partitions using parted and mkfs

Last update: 12/15/2022

Tools ​

Install the following tools using your package manager. For Debian and Ubuntu, run this command if you are using a minimal installation:

bash
sudo apt install parted e2fsprogs
  • parted: "is a program to manipulate disk partitions. It supports multiple partition table formats, including MS-DOS and GPT. It is useful for creating space for new operating systems, reorganising disk usage, and copying data to new hard disks." (from man parted)

  • mkfs.ext4: Allows creation of Ext4 partitions (like a formatting tool)

  • df: Report disk space usage

Figuring out what devices are available ​

bash
sudo parted -l

The output will be similar to:

Model: Micon_2450_M123132
Disk /dev/sda: 1024GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name                          Flags
 1      1049kB  316MB   315MB   fat32        EFI system partition          boot, esp
 2      316MB   450MB   134MB                Microsoft reserved partition  msftres
 3      450MB   999GB   999GB   ntfs         Basic data partition          msftdata
 4      999GB   1000GB  944MB   ntfs         Basic data partition          hidden, diag
 5      1000GB  1024GB  24.1GB  ntfs         Basic data partition          hidden, diag


Model: SSD 970 EVO Plus 1TB
Disk /dev/sdb: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End    Size   File system  Name  Flags
 6      1049kB  886GB  886GB  ext4
 1      886GB   887GB  524MB  fat32              boot, esp

Note the disk names. They might be /dev/nvme0n1 or something like /dev/sda. Read more about devices at

Creating a partition using parted ​

Open parted pointing to the disk you will edit.

bash
sudo parted /dev/sdb

Warning Make sure you are pointing to the correct device, otherwise you might lose data forever.

(parted) mkpart

(parted) Partition type? primary/extended? primary
(parted) File system type? [ext2]? ext4
(parted) Start? 0
(parted) End? 100%

(parted) print

You can use % values for start and end.

Format your new partition using ext4 ​

The command is quite simple, not much to change around:

bash
sudo mkfs.ext4 /dev/sdb1

Mounting disk manually ​

You should be able to mount the partition at any empty directory. In this example, we will mount it at /mnt/sdb1:

bash
sudo mkdir /mnt/sdb1
sudo mount /dev/sdb1  /mnt/sdb1

Using fstab to mount it every time you boot ​

Add the mount to your fstab file, make sure to point to the proper mount folder:

bash
sudo echo /dev/sdb1 /mnt/sdb1 ext4 defaults 0 0 >>/etc/fstab

You can restart your computer, and the disk should remain available.

bash
df -h

What to do if you prefer GUI ​

There is also a graphical version of parted: gparted.