tune2fs command in Linux with examples

Tune2fs Command In Linux

tune2fs command in Linux is used to manipulate the filesystem parameters of a ext 2/3/4 type file system. tune2fs command is part of e2fsprogs package.

Synopsis of the tune2fs command

The syntax for the tune2fs command:

tune2fs [ -l ] [ -c max-mount-counts ] [ -e errors-behavior ] [ -f ] [ -i interval-between-checks ] [ -j ] [ -J journal-options ] [ -m reserved-blocks-percentage ] [ -o [^]mount-options[,...] ] [ -r reserved-blocks-count ] [ -s sparse-super-flag ] [ -u user ] [ -g group ] [ -C mount-count ] [ -E extended-options ] [ -L volume-name ] [ -M last-mounted-directory ] [ -O [^]feature[,...] ] [ -T time-last-checked ] [ -U UUID ] device

The tune2fs command requires administrator privileges (root or sudo user) to operate.

Usage – tune2fs command

The usage of the tune2fs command has been described below with examples.

How to list file system parameters using tune2fs?

The -l option is used with the tune2fs command to list the current file system parameters.

Example:

sudo tune2fs -l /dev/sda2
Listing Filesystem Parameters Using Tune2fs Command
Listing the filesystem parameters using the tune2fs command

How to set the volume label using tune2fs ?

The -L option is used with the tune2fs command to set the volume label.

Example:

sudo tune2fs -L Label_Name /dev/sda2

You can verify the new volume label by using the -l option with the tune2fs command.

sudo tune2fs -l /dev/sda2 | grep -i name
Setting Volume Label With Tune2fs Command
Setting volume label using the tune2fs command

How to set maximum mount count using tune2fs?

The maximum mount count is the number of mounts after which the filesystem should be checked by the e2fsck utility. By default it is set to -1, if the maximum mount count is 0 or -1 then it will be disregarded by the e2fsck.

To find out maximum mount count and mount count, execute:

sudo tune2fs -l /dev/sda2 | grep -i mount
Mount Count And Maximum Mount Count
Mount Count And Maximum Mount Count

The -c option is used with tune2fs to set the maximum mount count, after which the filesystem should be checked by the e2fsck utility.

Example:

sudo tune2fs -c 40 /dev/sda2
Setting Maximum Mount Count
Setting Maximum Mount Count

How to set time intervals between two filesystem checks ?

The -i option with tune2fs is used to set the time interval between two filesystem checks.

Example:

sudo tune2fs -i 3m /dev/sda2

The above command will check the filesystem every three months (m for months, w for weeks, & d for days) on /dev/sda2

You can use both the maximum mount count and the time intervals between two filesystem checks.

Example:

sudo tune2fs -i 3m -c 150 /dev/sda2

How to disable filesystem check on reboot?

To disable filesystem check by e2fsck utility on reboot, set the maximum mount count to -1 or 0.

Execute the following command to disable filesystem check on reboot:

sudo tune2fs -c 0 /dev/sda2
sudo tune2fs -i 0 /dev/sda2

How to set mount counts using the tune2fs command ?

The -C option is used with the tune2fs command to set the number of times the filesystem has been mounted.

Example:

sudo tune2fs -C 37 /dev/sda2
Setting Mount Count
Setting Mount Count

If the mount count is set greater than the maximum mount count, then the filesystem will be checked by the e2fsck utility at the next reboot.

How to set filesystem features using the tune2fs command ?

The -O option is used with tune2fs to set filesystem features (features separated by a comma) in the indicated filesystem.
Note: Back up your data before using this option as it might corrupt your file system, and you may lose data.

Example:

sudo tune2fs -O uninit_bg,dir_index /dev/sda2

Conclusion

tune2fs is a great system utility for Linux System Administrators to adjust various ext 2/3/4 filesystems parameters. For a more detailed overview of the tune2fs command, you can find its man page here.

Thank you for reading!