The previous administrator of a server that is now under my supervision made a mistake. He accidentally created a LVM volume (no more than pvcreate, I think, though not sure) on a disk that actually contained an Ext4 partition with data. How do I recover data from a mistake like this? I'm ready to read ext4 documentation and roll out my own, but perhaps I don't need to? A few tools that I tried were unable to find an Ext4 filesystem on it, so I guess I need something more serious.
If you run
mkfs.ext4 -n /the/partition
it will print out what a EXT4 formatted drive would look like on that system.Of note is that it will tell you where the superblock locations are.
Using this information, attempt to mount the drive using an alternative superblock..
Providing only the headers of the partition were destroyed this may work.
If that doesn't work however, you can try to fix the filesystem using
fsck.ext4
by specifying the superblock address. Backup the data with dd or something before you do this.This may just end up overwriting the bad superblock with one of the known good ones, which could be enough to get the entire disk remounted. Then again you may lose key inodes (like your root filesystem inode). Mileage may vary.
I would give the UFS Explorer demo a try to see what it can detect... It's my go-to utility for filesystem recovery. I once had an XFS partition with 4 million files accidentally deleted and used this utility to recover the data.
But outside of that, it's a learning experience and a chance to test your backup routine. Sorry for the loss.
The first step in any recovery operation is to make a copy of the data, and perform the recovery on the copy. Once you've done that, you can attempt to recover the data.
Depending on what exactly the admin did, the most likely damage is that the partition table has been corrupted, the volume's primary superblock has been corrupted, or both. You can re-build the partition table using
fdisk
: simply create a new partition table with the same setup as the original. Make sure you get the type (MBR or GPT) right.e2fsck -b
will let you perform a filesystem repair using one of the secondary copies of the superblock, or in the unlikely event that they've all been corrupted,mke2fs -S
will re-create the metadata structure without touching the data.