Ask Sawal

Discussion Forum
Notification Icon1
Write Answer Icon
Add Question Icon

What is mkfs.ext4 in linux?

4 Answer(s) Available
Answer # 1 #
  • $ ls -1 /sbin/mkfs*
  • $ sudo fdisk -l [sudo] password for ubuntu:
  • $ sudo fdisk /dev/sda Command (m for help): l.
  • sudo mkfs. ext4 /dev/sda5.
[5]
Edit
Query
Report
mtcobi Kamel
TANK CLEANER
Answer # 2 #

Now that the drive is partitioned and formatted, you need to choose a mount point. This will be the location from which you will access the drive in the future. I would recommend using a mount point with "/media", as it is the default used by Ubuntu. For this example, we'll use the path "/media/mynewdrive"

[4]
Edit
Query
Report
Laksh ieuu
ELEVATOR OPERATOR FREIGHT
Answer # 3 #

The mkfs utility is used to create filesystem (ext2, ext3, ext4, etc) on your Linux system. You should specify the device name to mkfs on which the filesystem is to be created. WARNING: Executing these commands will destroy all the data on your filesystem.

[3]
Edit
Query
Report
Farida Mulye
CATERER HELPER
Answer # 4 #

From Ext4 - Linux Kernel Newbies:

Install e2fsprogs.

To format a partition do:

From mke2fs(8):

Creating a new file, directory, symlink etc. requires at least one free inode. If the inode count is too low, no file can be created on the filesystem even though there is still space left on it.

Because it is not possible to change either the bytes-per-inode ratio or the inode count after the filesystem is created, mkfs.ext4 uses by default a rather low ratio of one inode every 16384 bytes (16 KiB) to avoid this situation.

However, for partitions with size in the hundreds or thousands of GB and average file size in the megabyte range, this usually results in a much too large inode number because the number of files created never reaches the number of inodes.

This results in a waste of disk space, because all those unused inodes each take up 256 bytes on the filesystem (this is also set in /etc/mke2fs.conf but should not be changed). 256 * several millions = quite a few gigabytes wasted in unused inodes.

This situation can be evaluated by comparing the Use% and IUse% figures provided by df and df -i:

To specify a different bytes-per-inode ratio, you can use the -T usage-type option which hints at the expected usage of the filesystem using types defined in /etc/mke2fs.conf. Among those types are the bigger largefile and largefile4 which offer more relevant ratios of one inode every 1 MiB and 4 MiB respectively. It can be used as such:

The bytes-per-inode ratio can also be set directly via the -i option: e.g. use -i 2097152 for a 2 MiB ratio and -i 6291456 for a 6 MiB ratio.

By default, 5% of the filesystem blocks will be reserved for the super-user, to avoid fragmentation and "allow root-owned daemons to continue to function correctly after non-privileged processes are prevented from writing to the filesystem" (from mke2fs(8)).

For modern high-capacity disks, this is higher than necessary if the partition is used as a long-term archive or not crucial to system operations (like /home). See this email for the opinion of ext4 developer Ted Ts'o on reserved blocks and this superuser answer for general background on this topic.

It is generally safe to reduce the percentage of reserved blocks to free up disk space when the partition is either:

The -m option of ext4-related utilities allows to specify the percentage of reserved blocks.

To totally prevent reserving blocks upon filesystem creation, use:

To change it to 1% afterwards, use:

To set the number of reserved block space to an absolute size in gigabytes, use -r:

blocksize is the block size of the filesystem in bytes. This is almost always 4096, but you can check to be sure:

The $(()) syntax is for math expansion. This syntax works in bash and zsh, but it will not work in fish. For fish, this is the syntax:

These commands can be applied to currently-mounted filesystems, the changes taking effect immediately. You can use findmnt(8) to find the device name:

To query the current number of reserved blocks:

This is the number of blocks, so this has to be multiplied by the filesystem's block size to get the number of bytes or gigabytes: 2975334 * 4096 / 1024**3 = 11.34 GiB.

A compromise between fully converting to ext4 and simply remaining with ext2/ext3 is to mount the partitions as ext4.

Pros:

Cons:

To experience the benefits of ext4, an irreversible conversion process must be completed.

Pros:

Cons:

These instructions were adapted from Kernel documentation and an BBS thread.

In the following steps /dev/sdxX denotes the path to the partition to be converted, such as /dev/sda1.

E4rat is a preload application designed for the ext4 filesystem. It monitors files opened during boot, optimizes their placement on the partition to improve access time, and preloads them at the very beginning of the boot process. E4rat does not offer improvements with SSDs, whose access time is negligible compared to hard disks.

The ext4 file system records information about when a file was last accessed and there is a cost associated with recording it. With the noatime option, the access timestamps on the filesystem are not updated.

Doing so breaks applications that rely on access time, see fstab#atime options for possible solutions.

The sync interval for data and metadata can be increased by providing a higher time delay to the commit option.

The default 5 sec means that if the power is lost, one will lose as much as the latest 5 seconds of work. It forces a full sync of all data/journal to physical media every 5 seconds. The filesystem will not be damaged though, thanks to the journaling. The following fstab illustrates the use of commit:

Ext4 enables write barriers by default. It ensures that file system metadata is correctly written and ordered on disk, even when write caches lose power. This goes with a performance cost especially for applications that use fsync heavily or create and delete many small files. For disks that have a write cache that is battery-backed in one way or another, disabling barriers may safely improve performance.

To turn barriers off, add the option barrier=0 to the desired filesystem. For example:

Disabling the journal with ext4 can be done with the following command on an unmounted disk:

Journaling can be significantly sped up with the journal_async_commit mount option.

You can format a dedicated device to journal to with:

To assign journal_device as the journal of ext4_device, use:

You can replace tune2fs with mkfs.ext4 if you also want to make a new filesystem on ext4_device.

Since Linux 4.1, ext4 natively supports file encryption, see the fscrypt article. Encryption is applied at the directory level, and different directories can use different encryption keys. This is different from both dm-crypt, which is block-device level encryption, and from eCryptfs, which is a stacked cryptographic filesystem.

When a filesystem has been created with e2fsprogs 1.43 (2016) or later, metadata checksums are enabled by default. Existing filesystems may be converted to enable metadata checksum support.

If the CPU supports SSE 4.2, make sure the crc32c_intel kernel module is loaded in order to enable the hardware accelerated CRC32C algorithm [5]. If not, load the crc32c_generic module instead.

To read more about metadata checksums, see the ext4 wiki.

First the partition needs to be checked and optimized using e2fsck:

Convert the filesystem to 64-bit:

Finally enable checksums support:

To verify:

Starting from the 5.10 kernel, ext4 may have a performance boost by enabling the fast_commit option:

[0]
Edit
Query
Report
Norma Baillargeon
Media Designer