Data recovery from an accidental format on ext4 partition
Solution 1
Take a look at the e2fsprogs
package. It seems that you can get all your backup superblocks from dumpe2fs /dev/sd<partition-id> | grep -i superblock
and then have e2fsck
check the FS for you, or just try to do mount -o sb=<output-of-dumpe2fs> /dev/sd<partition-id> /your/mountpoint
with a backup superblock. See this for reference: http://www.cyberciti.biz/faq/linux-find-alternative-superblocks/.
testdisk
works well to recover partition tables, not clobbered file systems. Photorec is a last resort when you have really messed things up and can't get any of the filesystem structure recovered.
Solution 2
You will need to use TestDisk's sister program PhotoRec to recover your files. It's been a couple of years since I last used these programs, but IIRC you won't be able to recover them in-place, so I hope you have enough spare HD space to recover your files to.
It's a good idea to read through the relevant TestDisk & PhotoRec docs before you attempt to actually do the recovery work - using these programs when you don't know what you're doing can be a nerve-wracking experience...
If you have lots of spare storage, I suggest cloning the nuked partitions to image files, eg using dd
. Both TestDisk & PhotoRec happily operate on such image files. That way, if you do make a mistake you'll only mess up your image files.
Solution 3
I accidentally formatted an ext4 partition to NTFS in my Ubuntu 16.04 recently and was able to recover the full partition successfully by running a file system check.
sudo fsck.ext4 -v /dev/sda10
I recorded the steps in this blog post.
Related videos on Youtube
Neovatar
Updated on September 18, 2022Comments
-
Neovatar almost 2 years
When I was installing Mint Debian edition unlike the classic edition, the installation automatically formated my home partition when I did not specify to format.
So the formatting previously was ext4 as is now. I believe the data is still there as it was a quick format.
I have now booted the computer up on a live USB to prevent writing on it. Ran testDisk. Is there anyway to recover to a previous superblock so i can recover my data?
-
Neovatar over 9 yearsthanks for the reply. I'm a total noob at data recovery, It is possible to restore a previous superblock through TestDisk. Can I get my data back.
-
PM 2Ring over 9 years@user1976545: It's worth trying. As I said earlier, it's been a few years since I last used TestDisk and PhotoRec, so I'm certainly not an expert. But this might be helpful. But if you have the space I urge you to first clone the partition to an image file on another disk & work on the clone. If you need help making a partition image file, please ask another question.