5

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)

  • That really depends on what path you took through that wood. In most cases they should be the same after fsck. – Satō Katsura May 13 '17 at 6:43
4
+100

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 is depending on the fs. 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.

  • Thanks @dr01. But how I could recover my partition with the help of e2fsck if formatting it clears the superblocks? – Dante May 19 '17 at 10:50
  • @Dante I've edited my answer to reply. – dr01 May 19 '17 at 12:01
  • Oops! I made a mistake. I meant backup superblocks. I've edited my question. – Dante May 19 '17 at 18:11
  • @Dante Ok, answered again up there :) – dr01 May 20 '17 at 16:42
  • 2
    Formatting clears the superblock but not the inodes because inodes are scattered throughout the disk; where exactly is depending on the fs. 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. – dr01 May 23 '17 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.