Adjusting filesystems with tune2fs
Fine Tuning
The advanced tune2fs command lets you check and modify the tunable parameters of ext filesystems.
Most users know that the Bash shell includes commands that change the attributes of files and directories, such as chown
or chgattr
. What is less well known is that filesystems have a single command for changing their attributes called tune2fs
[1]. With large or multiple filesystems becoming the norm, tune2fs is an increasingly important command.
Tune2fs is bundled in e2fsprogs [2], a collection of utilities for administering ext2, 3, and 4 filesystems. Other members of e2fsprogs include e2fsck
, which corrects inconsistencies, mk2fs
for creating filesystems, and several defraggers. All are installed by default in most distributions.
To begin using tune2fs, you must log in as root. If you are unsure what filesystems are on your system, you can run fdisk -l
to receive a list, because the options for tune2fs all require specifying a filesystem. To begin, you can list the attributes of a filesystem with
tune2fs -l FILESYSTEM
(Figure 1). From there, you can go on to edit general attributes, reserve blocks, journals, and mount options, referring back to the list of attributes as your interests or needs take you.
Editing Basic Behavior
Filesystems are identified by UUIDs and, optionally, by labels. With -U
, tune2fs can edit a UUID, completing the command with clear
to remove it, random
to generate a new UUID in hex digits, and time
to generate a time-based UUID. Similarly, -L
can be followed by a label, which is usually the most human-accessible way of identifying a filesystem. The label can be especially useful for identifying the function of a filesystem (e.g., boot
or swap
). Both UUIDs and labels can be used when mounting a filesystem, or in files such as /etc/fstab
, which lists the files to be mounted at boot time.
Another set of options sets how kernel code reacts to errors on the filesystem. The -e
option can be followed by continue
, which instructs the kernel code to attempt to continue normal execution; remount-ro
, to remount the filesystem as read-only; and panic
, which triggers a kernel panic, causing the filesystem to shutdown. All three completions trigger the running of e2fsck the next time the computer starts.
However, the most important basic characteristics center around checking a filesystem during bootup. If you run a distribution that displays startup messages, you might have noticed messages about the last time a filesystem was checked for inconsistencies or when one was next due to be checked or seen. These messages are reading attributes stored on each filesystem.
Filesystem checks are scheduled with -c
or --option
, which set the Maximum mount count attribute for a filesystem – that is, the number of times a filesystem is mounted before being checked. This number is a balance between keeping your system efficient and staggering the running of e2fsck so that all filesystems are not checked at the same time. On the one hand, if e2fsck is not run often enough, problems with a filesystem could worsen and, in extreme cases, cause your system to crash. On the other hand, if all filesystems are checked at the same time, the process could delay bootup for 10 minutes, even on a home system. Typically, filesystems are set by default to be checked every 30-40 bootups (Figure 2). If this attribute is set to 0
or less, then the filesystem will never be checked, although the man page advises against using this setting.
Instead, if you have any reason to prevent the regular filesystem check, your filesystem is safer if you use the -C
option to reduce the Mount count and delay a check. In contrast, setting the Mount count to a number equal to or greater than the Maximum mount count forces a check at next bootup.
Another option is -i
, which schedules the checking of a filesystem by time, adjusting the Check interval attribute. By default, the interval is specified in days, but adding m
or w
schedules by months or weeks. Using the YYYYMMDDHHMMSS format, the -T
option can delay the next check by adjusting the Last checked date, which in turn alters the Next check after attribute. In general, scheduling checks by time is most useful in scripts or on systems with long periods of uptime.
Other filesystem features can be cleared or added using
-O FEATURE, FEATURE
Placing a caret (^
) before a feature will clear it, whereas placing a plus sign (+
) or no character before a feature will enable it. Some of the most useful features are listed in Table 1. (For a complete list, see the man page.) Running e2fsck after editing a feature will guarantee that your changes take effect.
Table 1
Filesystem Features
Feature | Effect |
---|---|
dir_index |
Uses hashed B-tree algorithm for more efficient searches in large directories. |
dir_nlink |
Allows more than 65,000 sub-directories in each directory |
filetype |
Stores information in directory entries. |
has_journal |
Enables journal. |
mmp |
Toggles multiple mount protection (MMP). |
spare_super |
Limits backup superblocks to save space on large filesystems. |
Editing Reserved Blocks
Filesystems for Unix-like operating systems include a section called superblock that includes filesystem attributes. Reserved blocks are portions of the superblock that are reserved for root users. Typically, the reserved blocks are 5 percent of the total space, as can be seen from the ratio of the Reserved blocks attribute to the Block count. Having reserved blocks prevents users from filling up so much of the disk space that system daemons like syslogd
can no longer operate and is one of the ways that ext2-4 systems resist fragmentation. Tune2fs accepts several options for reserved blocks. The -m PERCENT
option adjusts by percentage the size of reserved blocks, which may improve performance on a very small filesystem or a very active one, such as root. Another way to adjust the size of reserved blocks is to change the number of reserved bocks with -r NUMBER
, although, given that many users are not accustomed to thinking in terms of blocks, -m
is probably the easiest option to use.
Tune2fs also lets you adjust who else besides root can access reserved blocks with -g GROUP
and -u USER
. Both groups and users can be specified by name, but they are stored as UUIDs.
Creating and Editing Journals
One of the major changes during the evolution of the standard Linux filesystem is the inclusion of a journal to assist recovery. Probably not too many ext2 systems are in use today, but if you have one and are using a kernel that supports ext3, you can add an appropriately sized journal with the -j
option, in effect, converting it to an ext3 system. The option creates a .journal
file in the top-level directory of the filesystem. The file is transferred to the journal inode the next time e2fsck is run.
A created journal or an existing one can be defined with -J PARAMETER=VALUE
, with multiple parameters in a comma-separated list. The size
parameter must be a minimum of one block and cannot be more than 102,400 blocks. The location of the journal can also be set, either as a specific block number or as a space from the beginning of the filesystem.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.