Adjusting filesystems with tune2fs

Fine Tuning

Article from Issue 179/2015
Author(s):

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.

Figure 1: The -l option for tune2fs displays the current settings of a filesystem.

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.

Figure 2: Several filesystem attributes concern the last time a check was made for inconsistencies.

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

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Configuring Filesystems

    Although most Linux distributions today have simple-to-use graphical interfaces for setting up and managing filesystems, knowing how to perform those tasks from the command line is a valuable skill. We’ll show you how to configure and manage filesystems with mkfs, df, du, and fsck.

  • File systems

    Many users just opt for the defaults and don’t think about the file system when they install Linux. But if better performance is your goal, it pays to do some shopping.

  • Ext4

    The newest child in the Ext filesystem family provides better performance and supports bigger filesystems. Are you ready for Ext4?

  • Write Barriers

    Your journaling filesystem is carefully tracking write operations – but what happens when the data gets to the disk? A write barrier request can help protect your data.

  • The ext Filesystem

    The extended filesystem has been part of the Linux kernel since 0.96c – a faithful companion of the free operating system. With its developments – or, rather, rebirths – through ext2, ext3, and ext4, it is one of the oldest Linux-specific software projects.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News