How to tune Linux extended (ext) filesystems using dumpe2fs and tune2fs

The ext2, ext3 and ext4 filesystems are some of the most known and used filesystems specifically designed for Linux. The first one, ext2 (second extended filesystems) is, as its name suggests, the older of the three. It has no journal feature, which is the biggest advantage of its successor over him: ext3. Released in 2008, ext4 is the more recent, and currently the default filesystem on many Linux distributions.

A common set of utilities made to work with these filesystems are part of the e2fsprogs package. In this tutorial we see how to use two of them: dumpe2fs and tune2fs, respectively to retrieve information and tune its parameters.

In this tutorial you will learn:

  • How to retrieve ext filesystems information using dumpe2fs
  • How to change the filesystem label
  • How to change the amount of the filesystem reserved blocks
  • How to change the filesystem UUID
  • How to enable or disable filesystem features
  • How to set the filesystem default mount options
How to get information and adjust ext filesystems parameters using dumpe2fs and tune2fs
How to get information and adjust ext filesystems parameters using dumpe2fs and tune2fs

Software requirements and conventions used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Distribution-independent
Software dumpe2fs, tune2fs
Other Root privileges
Conventions # – requires given linux-commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux-commands to be executed as a regular non-privileged user

Getting ext filesystems information with dumpe2fs

The dumpe2fs utility let us retrieve information about ext2/3/4 filesystems. All we need to do is to invoke the utility and provide the path of the device containing the filesystem as argument. Let’s see an example of how to do it, and analyze the output returned by the command:

$ sudo dumpe2fs -h /dev/sda1

As you can notice, we invoked the program with the -h option, what is it for? When it is used, the behavior of dumpe2fs is altered so that only superblock information are included in the output:

dumpe2fs 1.45.6 (20-Mar-2020)
Filesystem volume name:   
Last mounted on:          /home
Filesystem UUID:          e69e2748-b575-4f3d-90a0-ab162ef18319
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              983040
Block count:              3932160
Reserved block count:     196608
Free blocks:              3732039
Free inodes:              976679
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      1024
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Thu Sep  9 15:49:37 2021
Last mount time:          Fri Sep 17 10:11:10 2021
Last write time:          Fri Sep 17 10:11:10 2021
Mount count:              3
Maximum mount count:      -1
Last checked:             Thu Sep  9 15:49:37 2021
Check interval:           0 ()
Lifetime writes:          12 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:           256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
First orphan inode:       528161
Default directory hash:   half_md4
Directory Hash Seed:      7cdeb137-67ce-41df-b1ba-b12f188a15c8
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x6ff4ea99
Journal features:         journal_incompat_revoke journal_64bit journal_checksum_v3
Journal size:             64M
Journal length:           16384
Journal sequence:         0x00026ef3
Journal start:            2857
Journal checksum type:    crc32c
Journal checksum:         0x7864c03d

As you can see very important information about filesystem are displayed, such as the UUID, features and the default mount options. We can also observe the reserved block count, percentage (5% by default). Those blocks are reserved for the super-user: this is useful to avoid fragmentation and make sure that privileged processes continue to function, since non-privileged processes are forbidden to use them.

An output which includes almost all the information observed above can be obtained by invoking the tune2fs utility with the -l option. The main use of the latter, however, is to tune filesystem parameters. We will see some examples of its usage in the next section.

Tune ext filesystem parameters with tune2fs

In order to tune ext filesystems features we have to use the tune2fs utility. There are several parameters we can tweak to change the filesystem behavior. Let’s see some examples of how to use the utility.

Changing the filesystem label

To change the label of an ext filesystem, we have to invoke tune2fs with the -L option, and provide the name we want to use as argument. Setting a label could be handy to reference the filesystem in a human-friendly way (although we can’t rely on it for uniqueness). As we can observe in the information we retrieved before, the filesystem on /dev/sda1 has currently no label. To set one (let’s suppose we want to use ‘home’) we should run:

$ sudo tune2fs -L home /dev/sda1

To verify the change has been applied, instead, we could use the following command:

$ sudo tune2fs -l /dev/sda1 | grep "volume name"
Filesystem volume name:   home

Once the label is applied, a new symbolic link to the device should appear inside the /dev/disk/by-label directory.

Changing the percentage of reserved blocks

As we already mentioned before, on every ext filesystem there is a percentage of block devices reserved for the root user, to reduce defragmentation and be sure that processes that run with the superuser privileges have a reserved space to write to, where unprivileged ones aren’t allowed to. The default percentage of reserved blocks is 5%. In some cases, for example on very large filesystems, we may want to decrease this percentage, to avoid allocating too much space. To perform such an action we can run tune2fs with the -m option and provide the percentage to use as argument. In the following example we reduce it to 3%:

sudo tune2fs -m 3 /dev/sda1
[sudo] password for egdoc:
tune2fs 1.45.6 (20-Mar-2020)
Setting reserved blocks percentage to 3% (117964 blocks)

The output of the command confirm us that the change has been applied correctly and the count of reserved blocks is now 117964 (before was 196608), which corresponds to the 3% of the total. As an alternative, we can specify the number of reserved blocks directly, as argument to the -r option:

$ sudo tune2fs -r 117964 /dev/sda1
tune2fs 1.45.6 (20-Mar-2020)
Setting reserved blocks count to 117964

Changing the filesystem UUID

The UUID is the universally unique identifier: it is composed by a series of hex digits separated by hyphens and represents the most reliable way to reference a filesystem. The current UUID of the /dev/sda1 filesystem is e69e2748-b575-4f3d-90a0-ab162ef18319; to change it we must invoke tune2fs with the -U option. When we use this option we can:

  • Provide a new UUID manually
  • use clear as argument to clear the current UUID
  • use random as argument to generate the use a new randomly-generated UUID
  • use time as argument to generate a time-based UUID

Changing the UUID of a filesystem requires a checked to be performed on it. To do that, we must first unmount the filesystem, in this case we would run:

$ sudo umount /dev/sda1

To actually check the filesystem status, we can use the e2fsck utility:

$ sudo e2fsck /dev/sda1

Providing an UUID manually can be useful in certain situations. Imagine, for example, we want to re-format a device by creating a new filesystem, but, in order to avoid having to change all references to the old one, we want to keep its UUID . To set the filesystem UUID manually, we would run:

$ sudo tune2fs -U e69e2748-b575-4f3d-90a0-ab162ef18319 /dev/sda1

If we use clear as the -U option argument, the current filesystem UUID will be cleared:

$ sudo tune2fs -U clear /dev/sda1

If we use random as the option argument, instead, a new, random, UUID is generated for us:

$ sudo tune2fs -U random /dev/sda1

Finally, if we use time as argument to the option, a new UUID based on the current time is generated:

$ sudo tune2fs -U time /dev/sda1

Enabling or disabling a filesystem feature

From the output of dumpe2fs or tune2fs -l we can take obtain the list of filesystem features enabled, which in this case are:

  • has_journal
  • ext_attr
  • resize_inode
  • dir_index
  • filetype
  • needs_recovery
  • extent
  • 64bit
  • flex_bg
  • sparse_super
  • large_file
  • huge_file
  • dir_nlink
  • extra_isize
  • metadata_csum

By using the tune2fs utility we can change the status of those features. How can we do that? All we have to do is to invoke the utility with the -O option. To disable a feature, we must prefix it with a ^ (caret). Let’s see an example.

As we know, the ext3 and ext4 filesystems have the journal feature. How the journal works depends on the data mode which is set as mount option. The available modes are:

  1. data=ordered
  2. data=journal
  3. data=writeback

The data=ordered mode is the default. When in this mode, as per the filesystem documentation:

ext4 only officially journals metadata, but it logically groups metadata information related to data changes with the data blocks into a single unit called a transaction. When it’s time to write the new metadata out to disk, the associated data blocks are written first. In general, this mode performs slightly slower than writeback but significantly faster than journal mode.

When in data=writeback mode, instead:

ext4 does not journal data at all. This mode provides a similar level of journaling as that of XFS, JFS, and ReiserFS in its default mode – metadata journaling. A crash+recovery can cause incorrect data to appear in files which were written shortly before the crash. This mode will typically provide the best ext4 performance.

Finally, there is the data=journal mode, which is the safest one, since it provides both data and metadata journaling, but slows down the filesystem significantly:

provides full data and metadata journaling. All new data is written to the journal first, and then to its final location. In the event of a crash, the journal can be replayed, bringing both data and metadata into a consistent state. This mode is the slowest except when data needs to be read from and written to disk at the same time where it outperforms all others modes. Enabling this mode will disable delayed allocation and O_DIRECT support.

In certain situations, for example when using the ext4 filesystem on a usb pendrive, we may want to disable the journal feature altogether. To do so, we can invoke tune2fs with the -O option and prefix the has_journal feature with a caret symbol:

$ sudo tune2fs -O ^has_journal /dev/sda1

Notice that the has_journal feature can be disabled only when the filesystem is unmounted or mounted in read only mode. To re-enable the feature, instead, we would run:

$ sudo tune2fs -O has_journal /dev/sda1

Setting the filesystem default mount options

The filesystem mount options can be specified in /etc/fstab: options specified this way override the default ones, but how the latter are set? To set the default options for an ext filesystem we must invoke the tune2fs utility with the -o (lowercase) option. As we saw in the case of filesystem features, a mount option can be set by providing its name as argument to the option, or cleared by prefixing it with a caret. In the previous section we briefly discussed the ext4 filesystem journaling mode. As we saw the default mode is data=ordered. Suppose we want to change this, and set the data=journal mode. Here is the command we would run:

$ sudo tune2fs -o journal_data /dev/sda1

If the command is executed without errors, we can see the changes reflected in the filesystem information:

$ sudo tune2fs -l /dev/sda1 | grep "Default mount options"
Default mount options:    journal_data user_xattr acl


In this article we saw how to use two utilities which are part of the e2fsprogs package: dumpe2fs and tune2fs. The former is used to retrieve information about the filesystem superblocks and block groups, the latter to tune ext filesystems parameters such as the amount of reserved blocks, the default mount options and the filesystem UUID. We saw how to perform such operations and what options are the most commonly used. For the complete list of them and for a more in-depth knowledge of the utilities we used, please consult their manuals!

Comments and Discussions
Linux Forum