The Ext4 or extended filesystem is a popular filesystem in Linux. It is an upgrade over Ext3 filesystem that offers more features and overcomes many shortcomings of Ext3. Also, it offers better performance, reliability and speed. It can be used on removable disks as well as hard disks. In this article, we will look at how to create Ext4 filesystem in Linux.
How to Create Ext4 Filesystem in Linux
Here are the steps to create Ext4 filesystem in Linux. You need to be logged in as root or user with sudo privileges to be able to perform the next steps.
1. List Partitions
Open terminal and run the following command to list all the disks available on your system.
# fdisk -l OR # parted -l
You will see the following kind of output.
Device Boot Start End Sectors Size Id Type /dev/xvda1 * 2048 16777182 16775135 8G 83 Linux /dev/xvda2 * 16777182 33552317 16775135 8G 84 Linux
2. Create partition
In the above output we have 2 disks that can be formatted. We will use parted utility tool to format /dev/xvda2.
# parted /dev/xvda2
We will use mklabel utility tool to add new disk label.
# (parted) mklabel new_disk
Next, we use mkpart tool to create a new partition. You will see couple of prompts asking if it is a primary/secondary partition, and which file system to use. Enter primary/secondary for the 1st prompt as per your requirement, and enter ext4 for the second prompt. Also set the start and end sector of partition to create it.
(parted) mkpart Partition type? primary/extended? primary File system type? [ext2]? ext4 Start? 1 End? 20290
Once the partition is created, you can print its details using print command.
# (parted) print
3. Format New Partition
Next, you need to format the newly created partition using mkfs.ext4 or mkefs command as shown.
# mkfs.ext4 /dev/xvda2 OR # mke4fs -t ext4 /dev/xvda2
You can then label the partition using e4label command.
# e4label /dev/xvda2 disk2-part1 OR # e2label /dev/xvda2 disk2-part1
4. Mount New Partition
Finally, we create mount points for new partitions and mount them.
# sudo mkdir /mnt/disk2-part1 # sudo mount /dev/sdb1 //mnt/disk2-part1
Now using df -h command you can list all file systems on your disk.
# df -hT
Please note, this filesystem will be unmounted on reboot. In order to automatically mount it during reboot, you need to add it to /etc/fstab file. Open it in a terminal.
$ sudo vi /etc/fstab
Add the following entry.
/dev/xvda2 /mnt/disk2-part1 ext4 defaults 0 0
That’s it. Now we have created new Ext4 partition in Linux, formatted and mounted it. Ext4 filesystem is better than Ext3 as it offers better performance, reduced load time, and increased number of supported devices. It also supports bigger files.