Superblock Mirroring

Discussion in 'Filesystem' started by Jarret W. Buse, Jul 9, 2013.

  1. Jarret W. Buse

    Jarret W. Buse Well-Known Member Staff Writer

    Jul 3, 2013
    Likes Received:
    Superblock Mirroring

    For redundancy, some file systems create mirrors of the Superblock. Before we get into the subject, let’s take a closer look at Superblocks.

    When partitioning and formatting a hard disk (as one or more logical drives), each drive has an addressing scheme. For example, suppose we partition a 500 GB hard disk as two drives. The first partition (hda1) we’ll assume is Drive C and the second partition (hda2) is drive D. After formatting each, the first block on each partition is Block 0. Every Block 0, of each partition, holds a Superblock.

    It may be best to understand the logical and physical drives. Physical drives are the easy one. Each physical hard disk or storage unit is a physical drive. When the physical drive is split into partitions, we have logical drives. So if a physical drive is split into drives E and F, we can say that E and F are logical drives, while, logical drives E and F make up a physical drive. Just remember that each partition will contain at least one Superblock.

    So, what is a Superblock?

    A Superblock is a file at Block 0 to store all needed information by the file system including: logical disk size, block size, size and location of the inode tables, empty and filled blocks, disk block map and usage information, size of the block groups and other items. Each file system can place its own specific entries into the Superblock.

    NOTE: The mkfs specific to each file system creates the Superblocks.

    Let's look at some items in the EXT2 Superblock. It contains the following (and more):

    Magic Number
    A number signifying the file system is EXT2, which should be 0xEF53 (all EXT file systems use the same Magic Number).

    Revision Level
    Lists the revision numbers so the kernel can determine which file system features are available for the partition.

    Mount Count and Maximum Mount Count
    The counts are an incremental counter. The counters help confirm whether the file system needs checking for consistency because of an improper system shutdown. When the system is shutdown, the Maximum Mount Count is incremented by one. At startup, the Mount Count is incremented by one and if the two do not match, then the system had not shut down properly.

    Block Group Number
    The Block Group Number containing the Superblock.

    Block Size
    The file system’s block size (usually 4,096 bytes).

    Blocks per Group
    By default on an EXT2 file system, there are 8,192 blocks per group. The group size is set when the file system is made. The EXT2 file system keeps a copy of the Superblock at the beginning of each block group.

    Free Blocks
    The file system’s number of free blocks.

    Free Inodes
    The file system’s number of free inodes.

    First Inode
    The inode number of the file system’s first inode.

    This partial entry list shows some of the items included in the Superblock. Every file system has similar entries and even entries dependent on the file system and its version. For instance, if a file system is released, and an update is released later, the update can modify the Superblock.

    For file systems that support Superblock Mirroring, there is another entry that is important – the Generation Number. The Superblock is given a number similar to a revision number. When a Superblock is updated, the generation number is incremented.

    On a file system with Superblock Mirroring, a copy of the Superblock is written at various hard disk addresses. Each file system would have a set of specific addresses, so there isn’t a standard. When mounting the file system, the Superblock with the highest Generation Number is used when loading the file system information. All Superblocks on the file system are considered mirrors, since they are all updated together. On SSD type devices, such as USB Flash Drives, the Superblocks can be written to various areas rather than overwriting the same address, if SSD mode is enabled. By not writing over the same address block, the specific area is not overused to cause the drive to be damaged. Blocks can only be overwritten so many times on a Solid State Drive (SSD).

    Be aware that multiple Superblocks do exist on file systems, but they do not act as mirrors.

    NOTE: On some file systems, the main Superblock is used, but the backups are not. The backup Superblocks are only updated once the drive is off-line. With Superblock Mirroring, the Superblocks are updated while the drive is mounted.

Share This Page