This comprehensive Linux guide expects that you run the following commands as root user but if you decide to run the commands as a different user then ensure that the user has sudo access and that you precede each of the privileged commands with sudo

The ext4 is the fourth extended filesystem for Linux which has significant advantages such as improved design, better performance, reliability, and new features. Here we will show you how to create a new ext4 file system (partition) in Linux. 

To create a ext4 partition we need to undergo a series of steps. This tutorial will help you to understand all the steps in detail.

Create A New Partition

To create a new ext4 filesystem we first need to create a partition. This tutorial is created considering that you have unallocated space for creating a new partition. You can check your unallocated space by fdisk -l command. 

The following command is used to create a new partition

sudo fdisk /dev/sda

This will take you to the fdisk menu as following

Command action
   a   toggle a bootable flagL
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

By pressing n we are going to create a new partition.

Command (m for help): n
Command action
    e    extended
    p    primary (1-4)

The primary or extended is selected based on the requirement and here we will be selecting the primary one.

P
Partition Number(1-4) : 2

The system will prompt for the sector details and to make things simple we will be having those fields defaults and we need to specify the amount of storage to be allocated, Here we will be allocating 10Gb so we will specify as follow

+10G

We can check that the changes by hitting P to print the partition table.

If everything is as per our expectations, write the new partition table to the disk (W) and exit (Q).

Converting The Partition As EXT4 File System

Now we have our new, empty partition and we can create its filesystem. So, we will be running the following command to convert into ext4 file system.

mkfs.ext4 /dev/sda2

To lable our partition you can use the following command and choose the desired lable.

e4label /dev/sda2 ext4part

Mounting The Partition

A directory is created to mount the free partition by the following command.

mkdir /mnt/ext4part

The created directory is mounted with the new partition created as follow

mount /dev/sda2 //mnt/ext4part

Lastly, we must add this entry in your /etc/fstab to enable persistent mounting of the file system, even after a reboot.

/dev/sda2   /mnt/ext4part  ext4   defaults    0   0

Now our new ext4 partition is created and ready to use.

Deleting A EXT4 Partition

To delete a ext4 file system we must first unmount it from the file system. We can do that by the following command

umount /dev/sda2

Then we can delete the partition from the partition table by the following commands 

fdisk /dev/sda2

Select the option d to delete the partition

Choose the partition number and click enter.

Write the changes to the partition table by selecting w and click enter .

Now our new ext4 partition is deleted.