15 tune2fs command examples in Linux [Cheat Sheet]


CheatSheet

Reviewer: Deepak Prasad

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.

 

How to use tune2fs command

The syntax for using the tune2fs command is as follows:

tune2fs [options] device

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

Common Options:

  • -c max-mount-counts: Adjust the number of mounts after which the filesystem will be checked by e2fsck.
  • -e error-behavior: Change the behavior of the kernel code when errors are detected (continue, remount-ro, or panic).
  • -g group: Change the group of the filesystem.
  • -i interval-between-checks[d|m|w]: Adjust the maximum time between filesystem checks.
  • -j: Add an ext3 journal to the filesystem.
  • -l: List the contents of the superblock.
  • -L volume-label: Set the volume label of the filesystem.
  • -m reserved-blocks-percentage: Set the percentage of the filesystem that will be reserved for the super-user.
  • -M last-mounted-directory: Set the last-mounted directory for the filesystem.
  • -o [^]mount-option[,...]: Adjust the default mount options.
  • -r reserved-blocks-count: Set the number of reserved blocks.
  • -s sparse_super: Set or clear the sparse super feature flag.
  • -U UUID: Set the universally unique identifier (UUID) of the filesystem.
  • -C mount-count: Set the number of times the filesystem has been mounted.
  • -E extended-option[,...]: Set extended options for the filesystem.
  • -f: Force the tune2fs operation.
  • -T time-last-checked: Set the time when the filesystem was last checked.

 

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:

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:

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:

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:

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]]].

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.

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

 

Views: 1,039
Rohan Timalsina

Rohan Timalsina

He is proficient in a wide range of skills, including Page Builder Plugins such as Elementor, Beaver Builder, Visual Composer, and Divi Builder. His expertise extends to Front End Development with HTML5/CSS3, JavaScript, Bootstrap, and React.js. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

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 send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment