Diskussions- und Newsboard der Linux Interessen Gruppe Suletuxe
allgemeine Kategorie => Installation, Einrichtung und Systempflege => Thema von: Sebastian am 01. April 2025, 14:59:52

Titel: How recover a ext4 header
Beitrag von: Sebastian am 01. April 2025, 14:59:52

Hallo Suletuxe,

Mir ist gestern ein Missgeschick passiert. Beim Herumprobieren habe ich aus Versehen mit wipefs -af /dev/sdX3 eine falsche Partition erwischt und darauf hin ein ext4 Dateisystem gelöscht das ich noch benötigt habe.

Nachdem der erste Schreckmoment vorbei war, dachte ich ruhig bleiben. Heutige Dateisysteme sind sehr robust. Und man weiß ja bei so einer schnellen Löschung die durch wipefs durchgeführt wird, wird ja nur der Header des Dateisystems gelöscht und die Daten sind eigentlich alle noch da. Zudem hat sich meine Partitionierung nicht geändert, so das ich die Dateisystem grenzen alle noch habe.

Im Handbuch von fsck.ext4 fand ich nun folgendes:
Zitat:
-b superblock
Instead of using the normal superblock, use an alternative superblock specified by superblock. This option is normally used when the
primary superblock has been corrupted.
The location of backup superblocks is dependent on the file system's blocksize, the number of
blocks per group, and features such as sparse_super.

Additional backup superblocks can be determined by using the mke2fs program using the -n option to print out where the superblocks ex‐
ist, supposing mke2fs is supplied with arguments that are consistent with the file system's layout (e.g. blocksize, blocks per group,
sparse_super, etc.).


If an alternative superblock is specified and the file system is not opened read-only, e2fsck will make sure that the primary superblock
is updated appropriately upon completion of the file system check.



Ha, also genau das was ich brauchte. noch mal das mkfs.ext4 Handbuch gegengeprüft:
Zitat:
-n Causes mke2fs to not actually create a file system, but display what it would do if it were to create a file system. This can be used
to determine the location of the backup superblocks for a particular file system, so long as the mke2fs parameters that were passed when
the file system was originally created are used again. (With the -n option added, of course!)



Also mit einen Dry run einmal so getan als ob ich ein neues Dateisystem anlegen wollte mit den gleichen Optionen wie bei der erstellung, und tasächlich ich bekamm sogar offsets von mehren Backup Superblöcken.

Einen der gefundenen Werte dann fsck übergeben:


Code:

fsck.ext4 -b <superblock_backup_offset> -p /dev/sdX3


Und zack hatte ich mein Dateisystem wieder, und konnte es wieder mounten um an meine Daten zu kommen.

LG
Sebastian

Titel: Re:How recover a ext4 header
Beitrag von: Andreas am 01. April 2025, 15:36:19

Habe ich auch schon ab und zu gebraucht. Zeigt einem aber auch mal wieder, wie man nicht "löschen" sollte, wenn man einen Datenträger weggibt oder verkauft...

LG
Andreas


Diskussions- und Newsboard der Linux Interessen Gruppe Suletuxe | Powered by YaBB SE
© 2001-2003, YaBB SE Dev Team. All Rights Reserved.