In This Article
What is Superblock?
A superblock refers to the segment of the hard drive that contains a metadata. It describes and contains the details of the file system on a block device.
In simple words, it is the collection of metadata that tells about the properties of file systems.
- In a few types of operating systems, the properties of the file systems are described by the superblock, which is present in most of the hard disk drives.
- This specific tool or segment of metadata specifies different characteristics of the file system, such as the number of inodes along with the free and used ones, the number and size of the data blocks, and more.
- The superblock is very useful in Unix and other similar operating systems in which an assortment of subdirectories is contained in the root directory.
- When a hard disk drive is mounted incorrectly, a superblock error message may be displayed, especially to the Linux users.
- The superblock has a specific location, usually at the start of the disk slice. However, several copies of it are also stored in several locations in each cylinder group as well as in the memory of the computer system.
Most of the computer hard drives contain a superblock that holds the information about the file system.
Ideally, on a disk or in the partition of the disk drive, the first data block holds the metadata, or data about data, of the partition itself. This is where the superblock got its name from.
However, that was back in time, but today, superblocks are not dependent on the traditional data block concept.
Instead, it is now more of a data structure that contains the vital information and details of each of the file systems mounted on the hard disk drive.
If the term is quite new to you and you are used to Microsoft Windows systems, be informed that the equivalent to the superblock on the Windows file system is the File Allocation Table, or FAT.
This contains the information about which particular block of the disk holds which records related to the topmost directory.
On a Unix-like operating system, however, the superblock is virtually located in the memory always, as opposed to the older operating systems such as Microsoft Disk Operating System (MS-DOS).
One of the primary objectives of the superblocks, apart from holding the information about the file system, is to alert the users, especially the Linux users, with a superblock error message when they try to mount a hard disk drive inappropriately.
In addition to that, it also ensures that every request to access any file within the filesystem is made through the superblock. This means that if you cannot access the superblock, you will not be able to mount a filesystem on your disk.
This, in technical terms, also means that it will not allow you to attach logically to the main filesystem or access the files.
Also, if you want to mount a filesystem with a tarnished or otherwise damaged superblock, you are likely to fail and will usually receive an error message stating ‘Cannot read superblock.’
Need for Multiple Copies
The importance of the superblocks may be overlooked by the average user, but it is quite immense.
It is due to its importance that the chances of any potential damage that can be caused to it and the effects of it need to be considered. These damages could be any of the following or others that may erase critical data:
- Any kind of physical damage
- Corruption of the magnetic recording medium on the drive disk
To minimize the chances of permanent data loss, multiple backup copies of these superblocks are created at block offsets or at intervals on the file system itself and stored at the beginning of each individual block group, or at the start of the disk slice. It is also duplicated in every cylinder group.
As already mentioned, for Unix and Linux, a copy of the superblock of every mounted filesystem is also maintained in the memory.
The main reason to store the several redundant copies of superblock in multiple locations on the disk and even in the main memory of the system is that it is considered to be an extremely critical metadata structure for a given file system.
For instance, if, at any point in time, the superblock of a partition, /var for instance, is damaged or becomes corrupt, the operating system will not be able to mount the specific file system.
Typically, in such situations, you will need to run File System Check. This will help you to choose an alternate superblock automatically from the backup copies and try to recover the file system.
Ideally, all of the backup copies of the superblock cannot get damaged altogether because they are stored in several block groups spread across the disk and the file system, with the first one stored at the first block offset from the beginning of the partition.
This feature plays a very crucial role in specific situations where there is a need for manual recovery.
It is especially very important to create redundant multiple copies of the superblock if you are using a multi-platter disk drive.
In such cases, the offsets are so calculated, created, and stored that there is a copy of them available on every platter of the hard disk drive.
This will ensure that, even in the event of the first platter failing or being lost, there is a substitute superblock available always that can be easily retrieved to restore the filesystem.
However, at this point, it is to be remembered that, apart from the principal blocks in the primary cylinder group, it is the leading blocks that are typically formed by the offsets that are used to store data.
The Summary Block
There is also a block containing the summary information that is also stored within the superblock, but this particular block is not replicated.
Instead, it is congregated with the principal superblock, which is typically located in the cylinder group 0.
The summary block normally records modifications and changes that occur as and when the filesystem is used. It typically lists the following:
- The number of inodes
- The number of directories
- The number of fragments
- The number of storage blocks in the file system
Contents of a Superblock
The superblock is a segment of metadata that contains all the characteristics and information about the file system.
Typically, it contains the following information:
- The size of the file system
- The size of the logical block for the file system
- The status or state of the file system
- The label or name of the file system and its volume name
- The date and time when the file system was last updated
- The size of the cylinder group
- The number of data blocks in the cylinder group
- The name of the path of the last mount point
- The number of inodes
- The number of free inodes
- The number of used inodes
- The summary data block
How to Recover Superblock?
If you find a superblock of your file system to be damaged by using File System Check (fsck), you can recover it quite easily because there are redundant copies of it stored in the file systems, fortunately.
You may use the fsck -o b command to replace the damaged superblock with one of these copies.
Using File System Check (fsck)
The steps to follow for the entire process are as follows:
- Become a superuser
- Change the directory outside the file system that is damaged
- Unmount the file system by using the command: # umount mount-point
- Display the values of the superblock using the command: # newfs -N /dev/rdsk/device-name
- Provide a substitute superblock with the fsck command: # fsck -F ufs -o b=block-number /dev/rdsk/device-name
The File System Check will use the alternate superblock specified by you in order to restore the primary damaged superblock.
You can use any of the substitute block numbers displayed in the output of the newfs -N command that are used to make copies of superblocks while creating the file system. However, you can always use 32 as a substitute block.
Alternatively, if you are using Ubuntu, you can follow these steps as mentioned below in order to restore a damaged Ext4 superblock.
Assuming that at this stage the system won’t boot, probably the easiest way to go ahead with this process is to download and burn Parted Magic.
When you boot from there, you will have access to a lot of useful tools and you can follow these steps:
- Find out the partition that you need to deal with in the first place, using the command sudo fdisk -l.
- Use Testdisk to find the partition number, such as /dev/sda3 or /dev/hdb1.
- Start the file system check with the command sudo fsck. ext4 -v /dev/xxx, but replace xxx with the partition name.
At this point, you can change ext4 to ext2 or ext3, depending on the filesystem.
Now, you will need to check what the superblock backups are and where they are kept by using the command sudo mke2fs -n /dev/xxx.
Finally, choose a backup from the list displayed and restore the damaged superblock, making sure that the x’s are replaced by the name of your partition and the block number with the first superblock backup in the command sudo e2fsck -b block_number /dev/xxx.
Complete the process by rebooting your system, which should fix the damaged superblock. If it does not, repeat the above steps, but this time use a different backup superblock to restore.
Fixed disk (fdisk)
In addition to the above steps, there is also a relatively outdated method of restoring a damaged superblock, which is by using the fdisk command.
- If you are absolutely certain about the original size of the block after running testdisk, say 4096, you can use the command mke2fs -S in order to rewrite the superblock on the disk.
- If you are sure about the right block size, you can use the command mke2fs -n -b 2048 /dev/sdb1 and try using all of the backups of the superblock displayed by this command.
However, this process will not support GPT disks because, as said at the beginning, this process is pretty outdated.
You will need to use GParted or some other similar tool for that matter.
Now that you have reached so far and are reading this line, you must have gained a fair amount of knowledge about the superblocks sited in the hard disk drive of your computer.
You know its value, benefits, and how exactly you can recover or restore a damaged superblock in the drive with a few easy steps and commands.