15 tune2fs command examples in Linux [Cheat Sheet]

Introduction to tune2fs command

tune2fs command allows you to view and change various filesystem parameters on Linux ext2, ext3, or ext4 filesystems. Some parameters you can modify are filesystem volume name, maximum mount count, mount count, interval time between two filesystem checks, last checked time, etc.

tune2fs can also convert an ext2 filesystem to an ext3 filesystem and an ext3 filesystem to an ext4 filesystem.

Advertisement

 

How to use tune2fs command

The syntax for using the tune2fs command is as follows:

$ sudo tune2fs option device

You will need the sudo privileges to run the tune2fs command in Linux.

 

Different examples to use tune2fs command

1. List the contents of the filesystem

The tune2fs command with -l option displays the current filesystem parameters.

$ sudo tune2fs -l device

Sample Output:

tune2fs command to list filesystem parameters

 

2. Display filesystem volume label

You can use the tune2fs command with grep command to get only the volume name of a filesystem.

$ sudo tune2fs -l device | grep volume

Sample Output:

Advertisement
golinux@ubuntu-PC:~$ sudo tune2fs -l /dev/sda5 | grep volume
Filesystem volume name:   <none>

As you can see, there is no volume label for /dev/sda5.

 

3. Set the filesystem volume name

The -L option sets the volume label of the filesystem.

$ sudo tune2fs -L volume_name device

Sample Output:

The following example sets the volume label golinux for /dev/sda5.

tune2fs command to set the filesystem volume label

 

4. View mount count and maximum mount count

You can view the filesystem's mount count and maximum count by grepping the pattern "mount count".

$ sudo tune2fs -l /dev/sda5 | grep -i "mount count"

Sample Output:

Advertisement
golinux@ubuntu-PC:~$ sudo tune2fs -l /dev/sda5 | grep -i "mount count"
Mount count:              79
Maximum mount count:      -1

 

5. Change the maximum mount count of a filesystem

The -c option sets the maximum number of mounts, after which e2fsck should check the filesystem.

The following example changes the maximum count of /dev/sda5 to 30.

$ sudo tune2fs -c 30 /dev/sda5

Sample Output:

tune2fs command to change the maximum mount count of a filesystem

 

6. Change the mount count of a filesystem

You can change the mount count of a filesystem using the -C option. It indicates the number of times the filesystem has been mounted.

This command sets the mount count of /dev/sda5 to 100.

$ sudo tune2fs -C 100 /dev/sda5

Sample Output:

Advertisement

tune2fs command to change the mount count of a filesystem

 

7. Display Check Interval of a filesystem

You can view the Check Interval value of a filesystem by searching the pattern "interval" with the grep command.

$ sudo tune2fs -l /dev/sda5 | grep interval

Output:

golinux@ubuntu-PC:~$ sudo tune2fs -l /dev/sda5 | grep interval
Check interval:           0 (<none>)

The value is zero as of now.

 

8. Set the intervals between two filesystem checks

The -i option allows you to set the maximal time between two filesystem checks.

$ sudo tune2fs -i interval [d|m|w]
  • d=days
  • w=weeks
  • m=months

The following command enables filesystem checks every 2 weeks on /dev/sda5.

$ sudo tune2fs -i 2w /dev/sda5

Sample Output:

Advertisement

set the maximal time between two filesystem checks

 

9. Disable filesystem check on boot

You can set the Maximum mount count and Check interval value to -1 to disable filesystem check on boot in Linux.

The following commands disable filesystem checks on boot for /dev/sda5.

$ sudo tune2fs -c -1 /dev/sda5
$ sudo tune2fs -i -1 /dev/sda5

Sample Output:

tune2fs command to disable filesystem checks on boot

 

10. Set the last-mounted directory

To set the last-mounted directory for the filesystem, use the tune2fs command with -M option.

$ sudo tune2fs -M mount_dir /dev/sda5

Sample Output:

tune2fs command to change the last mounted directory of a filesystem

 

11. Set the last time checked of a filesystem

You can set the last checked time of a filesystem using the -T option. The time format should be the international date format, i.e. YYYYMMDD[HH[MM[SS]]].

Advertisement

The keyword now can be used to set the current time.

$ sudo tune2fs -T now /dev/sda5

Sample Output:

golinux@ubuntu-PC:~$ sudo tune2fs -T now /dev/sda5
tune2fs 1.45.5 (07-Jan-2020)
Setting time filesystem last checked to Sat Aug 13 23:36:54 2022

 

12. Change the error behavior of a filesystem

You can use the -e option to change the behavior of the kernel code when errors are detected. The accepted values are:

  • continue: continue normal execution
  • remount-ro: remount filesystem to read-only
  • panic: cause a kernel panic

The following command sets the error behavior of /dev/sda5 to continue.

$ sudo tune2fs -e continue /dev/sda5

Sample Output:

golinux@ubuntu-PC:~$ sudo tune2fs -e continue /dev/sda5
tune2fs 1.45.5 (07-Jan-2020)
Setting error behavior to 1

 

13. Converting ext File System to an ext3

The -j option can add an ext3 journal to an ext2 filesystem without altering the data on the partition.

Advertisement

The following command converts the filesystem /dev/sda2 from ext2 to an ext3.

$ sudo tune2fs -j /dev/sda5

Note: Back up your data before running this command as it might cause corruption of the filesystem and data loss.

 

14. Change the UUID of the filesystem

The UUID of the filesystem is a series of hexadecimal digits separated by hyphens that looks like this: 5b146274-db93-4c42-86ab-80c1580585c7.

You can set the universally unique identifier (UUID) of the filesystem using the -U option.

$ sudo tune2fs -U UUID /dev/sda5

Other accepted parameters are:

  • clear: clear the UUID of the filesystem
  • random: generate a new random UUID
  • time: generate a time-based UUID

The following command sets a new randomly-generated UUID for the filesystem /dev/sda5.

$ sudo tune2fs -U random /dev/sda5

The UUID can only be changed when the filesystem is unmounted.

 

15. Set the filesystem feature in the filesystem

You can set or clear the feature in the filesystem using the -O option. Multiple features can be specified by separating them with commas.

The following command adds the indicated features to an ext3 filesystem /dev/sda5 and converts it to an ext4 filesystem.

$ sudo tune2fs -O extents,uninit_bg,dir_index /dev/sda5
NOTE:

Back up your data before running this command as it might cause corruption of the filesystem and data loss.

To clear the features, you need to specify filesystem features with a caret character ^ at the beginning.

$ sudo tune2fs -O ^extents,^uninit_bg,^dir_index /dev/sda5

 

Conclusion

Now you know how to view and change filesystem parameters using the tune2fs command. tune2fs is a handy tool in Linux for adjusting various filesystem parameters on ext2, ext3, or ext4 filesystems. If you have any confusion, let us know in the comment section.

 

What’s Next

How to create filesystem on a Linux partition or logical volume
Steps to repair filesystem in rescue mode in RHEL/CentOS 7/8 Linux

 

Further Reading

man page for tune2fs command

 

Related Keywords: tune2fs command examples, tune2fs uuid, tune2fs example, tune2fs xfs, tune2fs reserved space, man tune2fs, tune2fs command allows to mcq, tune2fs has journal 

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment

X