0

I recently had to use testdisk as well as these steps (Recover ext4 file system after quick format) to recover an accidentally formatted ext4 partition.

After recovering the Ext4 partition from a backup superblock, I can mount it manually and view my lost files. However, the partition still shows up as unknown in the "disks" utility, and I can't mount the drive through Nautilus.

Any ideas how to fix this problem?

EDIT:

What went wrong in the first place is that I accidentally formatted an ext4 partition (named "ExtraDrive1") to Fat32 (named "aaaaa"). The device name corresponding to this partition is /dev/sdb1.

I have tried:

  • Opening gdisk and hitting "w" to fix.

This did not work because the metadata of the partition still contains information about the drive "aaaaa". So, it restored the accidentally created fat32 filesystem instead of the lost ext4 drive.

  • using the Disks utility and Gparted:

It seems like there is no way to deal with this situation built into these utilities. They only support formatting drives, not repairing the metadata of a drive without formatting.

  • Using the "write" option in Testdisk

When I open up testdisk, it initially shows the drive "aaaaa". After performing a quick search, it shows "ExtraDrive1" and it gives me the "Write" option. However, hitting the "write" button and then rebooting doesn't seem to change anything.

Additional info

I can open ExtraDrive1 in testdisk and view the files. I can also manually mount /dev/sdb1 using sudo mount -t ext4 /dev/sdb1 ./temp/. The problem is that the partition shows up as "Unknown" in the disks utility, and it can't be mounted through nautilus. This seems to suggest that the metadata of /dev/sdb1 still reflects "aaaaa", not "ExtraDrive1".

The output of file -s /dev/sdb1 is:

/dev/sdb1: DOS/MBR boot sector, code offset 0x58+2, OEM-ID "mkfs.fat", sectors/cluster 64, reserved sectors 64, Media descriptor 0xf8, sectors/track 63, heads 255, FAT (32 bit), sectors/FAT 476864, serial number 0x80d4b4c6, label: "aaaaa      "
  • You probably need to set the correct partition type again using Disks or Gparted. I recommend you backup your recovered data first before attempting any. If that would fail, you then can still repartition and reformat the drive and restore the data. – vanadium Jun 11 '22 at 08:02
  • I don't think that the Disks utility nor Gparted can solve my problem. See the OP, I just added a bunch of additional info. – firstname gklsodascb Jun 11 '22 at 14:35
  • Testdisk is the tool to use here. It can recover the old partition sheme without data loss. The process is rather complicated and time consuming. If you can, do a backup and then read wikis and how to`s about testdisk. It is important that you stop using the "corrupted" disk because every write on that disk might overwrite data that you want to recover. – AlexOnLinux Jun 27 '22 at 07:29

1 Answers1

0

Rather than try to fix the corrupted metadata on "ExtraDrive1", I decided to manually mount "ExtraDrive1", copy the files to an external SDD, reformat "ExtraDrive1", then copy the files back.

lesson learned:

Utilities like testdisk, fsck and gparted do not seem to be applicable to drives that can be mounted but still have problems. In this case, it is far easier to just backup the files and reformat.