A superblock is a record of the characteristics of a filesystem, including its size, the block size, the empty and the filled blocks and their respective counts, the size and location of the inode tables, the disk block map and usage information, and the size of the block groups. The term filesystem can refer to an entire hierarchy of directories, or directory tree, that is used to organize files on a computer system. On Unix-like operating systems, the directories start with the root directory (designated by a forward slash), which contains a series of subdirectories, each of which, in turn, contains further subdirectories, etc. A variant of this definition is the part of the entire hierarchy of directories (or of the directory tree) that is located on a single disk or partition. A partition is a logically independent section of a hard disk drive (HDD) that contains a single type of filesystem. An inode is a data structure on a filesystem on a Unix-like operating system that stores all the information about a file except its name and its actual data. A data structure is a way of storing data so that it can be used efficiently; different types of data structures are suited to different types of applications, and some are highly specialized for specific types of tasks. A request to access any file requires access to the filesystem's superblock. If its superblock cannot be accessed, a filesystem cannot be mounted (i.e., logically attached to the main filesystem) and thus files cannot be accessed. Any attempt to mount a filesystem with a corrupted or otherwise damaged superblock will likely fail (and usually generate an error message such as can not read superblock). Because of the importance of the superblock and because damage to it (for example, from physical damage to the magnetic recording medium on the disk) could erase crucial data, backup copies are created automatically at intervals on the filesystem (e.g., at the beginning of each block group). For each mounted filesystem, Linux also maintains a copy of its superblock in memory. An ext2 filesystem, the basic Linux filesystem type, is divided into block groups, each of which contains, by default, 8192 blocks. The default block size on the same filesystem is 4096 bytes. Thus there are backup copies of the superblock at block offsets 8193, 16385, 24577, etc. If the ext2 filesystem is used, that the filesystem has block groups each comprised of 8192 blocks can be confirmed with the dumpe2fs command as follows:
device_name is the name of the partition on which the filesystem resides. The output of dumpe2fs is piped (i.e., sent) to the less command because it can be long and thus in order to read it one screenful at a time. It can be seen that dumpe2fs also provides a great deal of additional information about the filesystem, including the block size. For example, the following will provide the location of the primary and backup superblocks on the first partition of the first HDD:
On most systems it will be necessary to be the root user (i.e., administrative user) in order to use dumpe2fs. On home computers and other systems for which the user has access to the root password, that user can become root by issuing the su (i.e., substitute user) command and then supplying the password as prompted. It will also likely be necessary to use the full pathname of dumpe2fs by adding /sbin to its beginning, i.e.,
If a filesystem cannot be mounted because of superblock problems, it is likely that e2fsck, and the related fsck command, which are used to check and repair the filesystem, will fail as well, at least initially. Fortunately, however, e2fsck can be instructed to use one of the superblock copies instead by issuing a command similar to the following:
block_offset is the offset to a superblock copy, and it is usually 8193. The -f option is used to force e2fsck to check the filesystem. When using superblock backup copies, the filesystem may appear to be clean, in which case no check is needed, but -f overrides this. For example, to check and repair the filesystem on /dev/hda2 (i.e., the second partition of the first HDD) if it has a defective superblock, the following can be used:
This command can be executed from an appropriate emergency floppy disk, and it is possible that it will allow the designated filesystem to be mounted again. The equivalent to the superblock on Microsoft Windows filesystem is the file allocation table (FAT), which records which disk blocks hold the topmost directory. On Unix-like operating systems the superblock is virtually always held in memory, whereas it is not for older operating systems such as MS-DOS. The superblock acquired its name from the fact that the first data block of a disk or of a partition was used to hold the meta-data (i.e., data about data) about the partition itself. Superblock are now independent of the concept of the data block, but it remains the data structure that holds information about each mounted filesystem. Created August 14, 2005. |