e2fsck saved my sleep

Yesterday, I unin­ten­tion­ally deleted the (master) ext4 super­b­lock of one of my (virtual) server’s par­ti­tions by acci­dent­ally executing

pvcreate <device>

Only some seconds later, I realised that I defin­it­ively chose the wrong lvm volume. Some more minutes later, I found out that this can be (partly) reverted by letting e2fsck recreate the master super­b­lock by first going through the inform­a­tion stored in one of the backup super­b­locks. Their locations can be cal­cu­lated by mke2fs, given the para­met­risa­tion is still known. Given, as in most cases no custom values were used, the list of backup super­b­locks is revealed by running

mke2fs -n <device>

The -n argument makes e2fsck carry out a dry run only. Finally, the master super­b­lock is restored by issuing

e2fsck -p <backup superblock offset> <device>

Some error messages will be displayed and some cor­rec­tions will be carried out. In the end, however, I got back a fully func­tion­al filesys­tem with all the data … at least it seems so :)