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:
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
.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.
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.