Difference between backup superblocks

ext4filesystemsfscksuperblock

Recently I accidentally formatted an EXT4 partition to FAT. I got into a panic. After a long journey through a dark wood in which my hope was fading I could recover my partition and it seems ok. After sudo mke2fs -n /dev/sdx introduced some superblocks I picked up one and ran sudo e2fsck -b a_block_number /dev/sdxy and bingo! All my files and directories were put in a lost+found folder.

The question is that are all backup superblocks the same or it is possible one be more updated than another?

The second question is that does reformatting an EXT4 partition to EXT4 overwrite the backup superblocks? (between ourselves, I reformatted the FAT partition again to EXT4 before trying mke2fs and e2fsck)

Best Answer

All backup superblocks are the same. They are all a copy of the superblock, and are scattered throughout the disk to provide redundancy in case a large contiguous part of the disk is corrupted.

Formatting a partition, even with the same filesystem type, clears the superblock. (It makes sense: the purpose of formatting is to create a clean slate on the partition, so all filesystem metadata is erased.) However, it does not erase the backup superblocks, since there is no need to do so (and your experience confirms this).


EDIT: to answer your comment questions:

How I could recover my partition with the help of e2fsck if formatting it clears the superblocks?

The first format to FAT cleared the superblock but all the files and directories were still there, just non-available because they are not referenced anymore in the filesystem. (Inexperienced users are often surprised by the fact that after formatting a disk, 99% of the content is still there. Therefore, if you plan to sell an used disk, never do a simple format -- securely wipe all content bit by bit!)
mke2fs -n displayed the location of the backup superblock for the ext4 filesystem, which was the filesystem you had before formatting to FAT; that superblock was therefore the "correct" superblock. e2fsck -b applied the superblock found at that location. This allowed the data fragments to be recovered in /lost+found.

How formatting say EXT4 to FAT clear the superblock but not the other parts of a filesystem like inodes?

Formatting clears the superblock but not the inodes because inodes are scattered throughout the disk; where exactly thy are scattered depends on the filesystem type. For instance, space in a EXT2/EXT3 filesystems is split up into blocks, grouped into block groups; inodes are stored just before data blocks in each block group. And as I said before, formatting leaves a very large part of the disk untouched.

when are backup superblocks created? According to SUSE Linux 9 Bible by Justin Davies, "backup superblocks are created when an EXT2 or EXT3 filesystem is created.". So I expect when I reformat my partition the backup superblocks be reformatted.

No, only the main superblock is erased. The backup superblock reside in other locations of the disk and, like metadata (inodes...) and files, are not wiped out by the format, as said before. They might be overwritten by the backup superblocks of the new fs, however; this depends on the new fs type.

Related Question