The superblock contains metadata about the filesystem. It is crucial for the system to understand how the filesystem is organized. Each filesystem (e.g., ext4, XFS) has a superblock that acts like a “header” or “master record” for the entire filesystem.
Key Information Stored in the Superblock:
- Filesystem size: The total number of blocks in the filesystem.
- Block size: The size of each block (typically 1KB, 2KB, 4KB, etc.).
- Inode count: Total number of inodes available in the filesystem.
- Free block count: Number of available blocks.
- Free inode count: Number of available inodes.
- Filesystem mount status: Whether the filesystem was cleanly unmounted or if errors occurred.
- Filesystem magic number: A unique identifier to recognize the filesystem type (e.g., ext2, ext4).
Importance:
The superblock is critical for filesystem integrity. If it gets corrupted, the filesystem may become unreadable. For this reason, many filesystems store backup copies of the superblock at different locations on the disk.
Checking the Superblock:
You can inspect the superblock with tools like dumpe2fs
on ext-based filesystems:
sudo dumpe2fs /dev/sda1 | grep -i superblock
You’ll see the primary superblock and any backup superblocks listed.
Recovering from Superblock Corruption:
If the primary superblock is corrupted, you can attempt to use a backup superblock to repair the filesystem. Example for ext4:
sudo e2fsck -b <backup_superblock_number> /dev/sda1
Superblock Inspection:
Use the dumpe2fs
command to inspect the superblock of a partition:
sudo dumpe2fs /dev/sda1 | grep -i superblock
Superblock Recovery:
Simulate superblock corruption and attempt recovery using a backup superblock:
sudo e2fsck -b 32768 /dev/sda1