Skip to content
Superblock
step 1/5

Reading — step 1 of 5

Read

~1 min readDisk Layout

Superblock

The superblock holds filesystem-wide metadata: the first thing read on mount.

Typical fields:

struct superblock {
    uint32_t magic;          // FS magic number (e.g. 0xEF53 for ext)
    uint64_t total_blocks;
    uint64_t free_blocks;
    uint64_t total_inodes;
    uint64_t free_inodes;
    uint32_t block_size;
    uint32_t inode_size;
    uint32_t blocks_per_group;
    uint64_t root_inode;     // typically 1 or 2
    uint32_t mkfs_time;
    uint32_t mount_count;
    uint32_t max_mount_count;
    uint32_t state;          // clean, error, etc.
    uint8_t  uuid[16];
    char     volume_name[32];
    ...
};

Position: typically at fixed offset (e.g. block 1 in ext4; offset 1024).

Multiple copies:

  • ext4 keeps backup superblocks in some block groups (e.g., every 8th).
  • If primary corrupted: e2fsck -b <backup_offset> recovers.

Magic number:

  • Identifies FS type at mount time.
  • ext: 0xEF53.
  • xfs: "XFSB" ASCII.
  • btrfs: "_BHRfS_M".

Mount sequence:

  1. Read superblock. Check magic.
  2. Verify state (clean? Otherwise replay journal / fsck).
  3. Increment mount_count.
  4. Read root inode.
  5. Mounted; ready for syscalls.

Unmount:

  1. Flush all dirty buffers.
  2. Update superblock state to "clean".
  3. Write superblock to disk.

Mount errors → kernel rejects, returns EIO/EROFS.

tune2fs -l <device> shows ext superblock fields.

mkfs.<fs> creates a fresh filesystem: writes superblock, allocates bitmaps, sets up root directory.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…