tune2fs command is helpful to manipulate the filesystem parameters of a ext2, or ext3, or ext4 type file system.
There are several options available with tune2fs command that you can use to either view the current parameters, or change some of the parameters value.
This tutorial explains some of the most frequently used tune2fs command parameters.
1. View Filesystem Parameters
Before we do anything with the file system parameters, we should first view the existing parameters and its values.
Use -l option as shown below, which will list all the parameters and its values.
You should pas a device name as parameters. The following examples displays all the filesystem parameters of /dev/sda1 partition.
# tune2fs -l /dev/sda1 tune2fs 1.41.12 (17-May-2010) Filesystem volume name: Last mounted on: / Filesystem UUID: 2871717f-c9b8-43ec-b0bb-77c736ca22e0 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize Filesystem flags: signed_directory_hash Default mount options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 8396800 Block count: 33586944 Reserved block count: 1679347 Free blocks: 31874103 Free inodes: 8374186 First block: 0 Block size: 4096 Fragment size: 4096 Reserved GDT blocks: 1015 Blocks per group: 32768 Fragments per group: 32768 Inodes per group: 8192 Inode blocks per group: 512 Flex block group size: 16 Filesystem created: Tue Jan 8 20:33:05 2013 Last mount time: Mon Mar 11 11:54:04 2013 Last write time: Tue Jan 8 20:41:21 2013 Mount count: 10 Maximum mount count: -1 Last checked: Tue Jan 8 20:33:05 2013 Check interval: 0 () Lifetime writes: 2967 MB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 28 Desired extra isize: 28 Journal inode: 8 First orphan inode: 7734872 Default directory hash: half_md4 Directory Hash Seed: a3d3d5fb-5720-472a-bc19-91bb4da2fa19 Journal backup: inode blocks
2. Change Maximum Mount and Mount Count
By default, the maximum mount count will be set to -1, which indicates that the number of times a filesystem is mounted will not be consisdered by the e2fsck
# tune2fs -l /dev/sda1| grep -i mount Last mount time: Mon Mar 11 11:54:04 2013 Maximum mount count: -1
But, you can change this value as shown below. The following will indicate that after 20 mounts, the filesystem will be checked by e2fsck command.
# tune2fs -c 20 /dev/sda1 tune2fs 1.41.12 (17-May-2010) Setting maximal mount count to 20
The following indicates how many times the filesystem has been mounted so far. This indicates that it has been mounted 10 times so far.
# tune2fs -l /dev/sda1| grep mount Last mount time: Mon Mar 11 11:54:04 2013 Maximum mount count: 20 Mount count: 10
You can change the current mount count as shown below. The following will change the current mount count to 5.
# tune2fs -C 5 /dev/sda1 tune2fs 1.41.12 (17-May-2010) Setting current mount count to 5
3. Convert Filesystem Type using -j
You can use -j option to convert ext2 to ext3 file system as shown below.
tune2fs -j /dev/sdb1
Note: Execute the above command only on a test system for testing purpose. You might corrupt your filesystem, if you don’t know what you are doing.
4. Set Filesystem Features
You can use -O option to convert ext3 to ext4 file system as shown below.
tune2fs -O extents,uninit_bg,dir_index /dev/sda2
Note: Execute the above command only on a test system for testing purpose. You might corrupt your filesystem, if you don’t know what you are doing.
The following are some of the features that you can set on a filesystem using -O option
- debug
- bsdgroups
- user_xattr
- acl
- uid16
- journal_data
- journal_data_ordered
- journal_data_writeback
- nobarrier
- block_validity
- discard
- nodelalloc
5. Set Volume Label
The following indicates that /dev/sda1 doesn’t have any volume name.
# tune2fs -l /dev/sda1 | grep -i name Filesystem volume name:
For accessibility purpose, you can set a volume name for your partitions. The following will set the name /home to /dev/sda1 partition.
# tune2fs -L /home /dev/sda1 tune2fs 1.41.12 (17-May-2010)
Now, when you do -l option, you’ll see the name as shown below.
# tune2fs -l /dev/sda1 | grep -i name Filesystem volume name: /home
6. Last Mounted Directory and Last Time Check
You can use -M option to set the last mounted directory for your file system.
You can also use -T option to indicate the time when the last filesystem check was performed. Under normal circumstances, you don’t need to set this. But, when you are playing around with LVM, you may have to do this to take some consistent snapshots.
The following indicates when the filesystem was checked last.
# tune2fs -l /dev/sda1 | grep -i check Last checked: Sat Dec 7 11:01:38 2013 Check interval: 0 ()
The following will set the last time check to the current timestamp. Do this only when you know the filesystem is clean.
# tune2fs -T now /dev/sda1 tune2fs 1.41.12 (17-May-2010) Setting time filesystem last checked to Sat Mar 1 11:01:38 2014
You can also use YYYYMMDD [HH[MM[SS]]] format to specify a specific time stamp.
7. Time Dependent Checking
Just like mount dependent checking. i.e Check the filesystem after x number of mounts, you can also specificy time dependent checking.
i.e Check the filesystem after x number of days, months, or weeks.
The following example indicates that the filesystem check will be performed after 10 days.
# tune2fs -i 10d /dev/sda1 tune2fs 1.41.12 (17-May-2010) Setting interval between checks to 864000 seconds
You can view your current time dependent checking as shown below.
# tune2fs -l /dev/sda1 | grep -i check Last checked: Tue Jan 8 20:33:05 2013 Check interval: 864000 (1 week, 3 days) Next check after: Fri Jan 18 20:33:05 2013
Following are valid values:
- 10d – Indicates 10 days (same as 10)
- 10w – Indicates 10 weeks
- 10m – Indicates 10 months