Linux tune2fs Command
Linux tune2fs Command Examples
The "tune2fs" command is used by the system administrator to change/modify tunable parameters on ext2, ext3 and ext4 type filesystems. To display the current values that are set you can use the tune2fs command with the "-l" option or use the dumpe2fs command.
Basic Usage of tune2fs
Usage: tune2fs [-c max_mounts_count] [-e errors_behavior] [-g group] [-i interval[d|m|w]] [-j] [-J journal_options] [-l] [-m reserved_blocks_percent] [-o [^]mount_options[,...]] [-r reserved_blocks_count] [-u user] [-C mount_count] [-L volume_label] [-M last_mounted_dir] [-O [^]feature[,...]] [-E extended-option[,...]] [-T last_check_time] [-U UUID] [ -I new_inode_size ] device
tune2fs - View Filesystem Information
The command to display filesystem information is "tune2fs -l /dev/sdax" - (amend device name accordingly to match your system)
ls001a:~ # tune2fs -l /dev/sda1 tune2fs 1.41.9 (22-Aug-2009) Filesystem volume name: <none> Last mounted on: <not available> Filesystem UUID: 8816cb40-7618-4596-906c-510321ef30ba Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super Filesystem flags: signed_directory_hash Default mount options: (none) Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 40000 Block count: 159744 Reserved block count: 7987 Free blocks: 118755 Free inodes: 39955 First block: 1 Block size: 1024 Fragment size: 1024 Reserved GDT blocks: 256 Blocks per group: 8192 Fragments per group: 8192 Inodes per group: 2000 Inode blocks per group: 250 Filesystem created: Wed Mar 21 15:17:43 2012 Last mount time: Mon Jul 22 13:01:37 2013 Last write time: Mon Jul 22 13:01:37 2013 Mount count: 25 Maximum mount count: -1 Last checked: Wed Mar 21 15:17:43 2012 Check interval: 0 (<none>) Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 128 Journal inode: 8 Default directory hash: half_md4 Directory Hash Seed: a9e266b1-8c1a-4581-8409-40a036cdbd13 Journal backup: inode blocks
Display Filesystem Volume Name
In the following example we are going to use the grep command to extract information that relates to the "Filesystem volume name"
You will need to amend the device name accordingly.
ls001a:~ # tune2fs -l /dev/sda1 | grep volume Filesystem volume name: <none>
Change Filesystem Volume Name
Using the "-L" parameter, we can give add/change the filesystem volume name.
ls001a:~ # tune2fs -L Disk_One /dev/sda1 tune2fs 1.41.9 (22-Aug-2009) ls001a:~ # tune2fs -l /dev/sda1 | grep volume Filesystem volume name: Disk_One
Displaying Filesystem Check Intervals and Mount Counts
By default, most systems will automatically attempt to check your filesystems after a defined time limit. This may be the number of times a filesystem has been mounted or literally a set time. To display the current settings we can use the "tune2fs" command and grep for " interval" and "count".
john@john-desktop:~$ sudo tune2fs -l /dev/sda1 |grep interval Check interval: 15552000 (6 months) john@john-desktop:~$ sudo tune2fs -l /dev/sda1 |grep -i count Inode count: 9609216 Block count: 38419456 Reserved block count: 1920972 Mount count: 6 Maximum mount count: 35
Disable Filesystem Check on Boot
The following parameters should only be used in a test environment where you may be carrying out multiple reboots during the course of the day. The Mount Count and check interval values below are set to "-1" which disables any checking!
tune2fs -c -1 /dev/sda1 tune2fs -i -1 /dev/sda1
Modifying Filesystem Checks
The following will modify the Check interval and Mount Count to only check after 100 mounts or a 2 month period.
tune2fs -c 100 -i 2m /dev/sda1
Staggering the mount counts at which filesystems are checked can avoid all filesystems being checked at one time. This will avoid all filesystems being checked at the same time and can reduce boot time.
tune2fs Popular Options
For a full list of available options consult the man pages: man tune2fs
OPTIONS -c max-mount-counts Adjust the number of mounts after which the filesystem will be checked by e2fsck(8). If max-mount-counts is 0 or -1, the number of times the filesystem is mounted will be disregarded by e2fsck(8) and the kernel. -C mount-count Set the number of times the filesystem has been mounted. If set to a greater value than the max-mount-counts parameter set by the -c option, e2fsck(8) will check the filesystem at the next reboot. -f Force the tune2fs operation to complete even in the face of errors. This option is useful when removing the has_journal filesystem feature from a filesystem which has an external journal (or is corrupted such that it appears to have an external journal), but that external journal is not available. WARNING: Removing an external journal from a filesystem which was not cleanly unmounted without first replaying the external journal can result in severe data loss and filesystem corruption. -i interval-between-checks[d|m|w] Adjust the maximal time between two filesystem checks. No postfix or d result in days, m in months, and w in weeks. A value of zero will disable the time-dependent checking. It is strongly recommended that either -c (mount-count-dependent) or -i (time-depen- dent) checking be enabled to force periodic full e2fsck(8) checking of the filesystem. Failure to do so may lead to filesystem corruption (due to bad disks, cables, memory, or kernel bugs) going unnoticed, ultimately resulting in data loss or corruption. -l List the contents of the filesystem superblock, including the current values of the parameters that can be set via this program. -L volume-label Set the volume label of the filesystem. Ext2 filesystem labels can be at most 16 char- acters long; if volume-label is longer than 16 characters, tune2fs will truncate it and print a warning. The volume label can be used by mount(8), fsck(8), and /etc/fstab(5) (and possibly others) by specifying LABEL=volume_label instead of a block special device name like /dev/hda5. -m reserved-blocks-percentage Set the percentage of the filesystem which may only be allocated by privileged pro- cesses. Reserving some number of filesystem blocks for use by privileged processes is done to avoid filesystem fragmentation, and to allow system daemons, such as sys- logd(8), to continue to function correctly after non-privileged processes are prevented from writing to the filesystem. Normally, the default percentage of reserved blocks is 5%. -T time-last-checked Set the time the filesystem was last checked using e2fsck. The time is interpreted using the current (local) timezone. This can be useful in scripts which use a Logical Volume Manager to make a consistent snapshot of a filesystem, and then check the filesystem during off hours to make sure it hasn't been corrupted due to hardware prob- lems, etc. If the filesystem was clean, then this option can be used to set the last checked time on the original filesystem. The format of time-last-checked is the inter- national date format, with an optional time specifier, i.e. YYYYMMDD[HH[MM[SS]]]. The keyword now is also accepted, in which case the last checked time will be set to the current time. -U UUID Set the universally unique identifier (UUID) of the filesystem to UUID. The format of the UUID is a series of hex digits separated by hyphens, like this: "c1b9d5a2-f162-11cf-9ece-0020afc76f16". The UUID parameter may also be one of the fol- lowing: clear clear the filesystem UUID random generate a new randomly-generated UUID time generate a new time-based UUID The UUID may be used by mount(8), fsck(8), and /etc/fstab(5) (and possibly others) by specifying UUID=uuid instead of a block special device name like /dev/hda1. See uuidgen(8) for more information. If the system does not have a good random number generator such as /dev/random or /dev/urandom, tune2fs will automatically use a time- based UUID instead of a randomly-generated UUID.