Yesterday, I unintentionally deleted the (master) ext4 superblock of one of my (virtual) server’s partitions by accidentally executing
pvcreate <device>
Only some seconds later, I realised that I definitively chose the wrong lvm volume. Some more minutes later, I found out that this can be (partly) reverted by letting e2fsck recreate the master superblock by first going through the information stored in one of the backup superblocks. Their locations can be calculated by mke2fs, given the parametrisation is still known. Given, as in most cases no custom values were used, the list of backup superblocks is revealed by running
mke2fs -n <device>
The -n
argument makes e2fsck carry out a dry run only. Finally, the master superblock is restored by issuing
e2fsck -p <backup superblock offset> <device>
Some error messages will be displayed and some corrections will be carried out. In the end, however, I got back a fully functional filesystem with all the data … at least it seems so :)