Life and times of the classic ext Linux filesystem


For an ext filesystem to be able to organize itself, it keeps a record of some important configuration parameters and current states. This information lives in the superblock, which always follows the first 1024 bytes of a storage medium (Figure 2).

Figure 2: The tune2fs tool reads the superblock of an ext2 filesystem.

This fixed position is important, for example, for the mount operation or for checking the filesystem. Among other things, the superblock contains the following:

  • the exact block size
  • the number of blocks and block groups
  • the number of free and used inodes
  • the date of the last successful mount
  • the last change date
  • the name of the operating system that created the filesystem
  • the current state of the filesystem.

The superblock is more or less the heart of the ext filesystem. To avoid damage to the superblock that could destroy the filesystem, ext2 creates several copies of the superblock distributed across block groups. For repairs, tools rely on these backup copies.

Each block group has a group descriptor that holds some information about the block group. For security reasons, all block groups store all group descriptors of the ext filesystem.

Additionally, each block group contains inode and block bitmaps. These bitmaps act as registers that list all the inodes and blocks of each block group. A bit with a value of 0 marks an inode or block as free; a value of 1 indicates an occupied inode or block. A bitmap must always fit in one block, which also limits the size of a block group.

Storage in Action

If you create a new file or folder on ext2, the filesystem first makes a decision on the exact storage location. For an empty filesystem, the data could theoretically end up anywhere, but for performance reasons, it makes sense to store contiguous data as close together as possible. Ext2 thus tries to put subfolders and files in the block group in which the directory that holds them resides. The filesystem assumes that this data is related and the system will retrieve it, in quick succession if necessary. If the block group fills up, ext2 is forced to divert to another location. To determine which blocks and inodes are usable for storage, ext2 looks at the inode and block bitmaps.

Good References

Ext2 also introduced support for symbolic links, or symlinks for short. A symlink is a special type of file that only contains a reference to another file or directory instead of data. In contrast to hard links, Symlinks point to targets on all filesystems, not just their own.

Unlike hard links, you can recognize a symlink. Applications that access the files or folders hiding behind symlinks treat them as ordinary files. But when it matters, such as when creating backups, a program needs to handle a symlink separately.

Symlinks exist independently of the target. If you delete the file that is referenced by a symlink, the link will remain – after all, it is a separate file with its own inode. The potential downside: If you change the name or location of a file, you also need to modify the symlink accordingly.

The filesystem stores all symlinks fewer than 60 bytes in size directly in the associated inode. Storing the symlink in the inode avoids the association of a separate block in the ext2 filesystem. (Actually, this same procedure is also used for normal files: If the content of a file takes up fewer than 60 bytes, the filesystem writes the data directly to the associated inode as "inline data.")

Buy this article as PDF

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

Buy Linux Magazine

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.

  • Managing Linux Filesystems

    Even with all the talk of Big Data and the storage revolution, a steady and reliable block-based filesystem is still a central feature of most Linux systems.

  • Choose a Filesystem

    Every Linux computer needs a filesystem, and users often choose a filesystem by habit or by default. But, if you're seeking stability, versatility, or a small performance advantage, it pays to take a closer look.

  • Accessing NTFS Intro

    Whether you are troubleshooting or just configuring for efficiency, it is a good idea to explore your options for accessing your Windows partitions from Linux.

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