DEV Community

Cover image for Linux ext4 superblock errors -- testdisk to the rescue
drmikecrowe
drmikecrowe

Posted on

Linux ext4 superblock errors -- testdisk to the rescue

So, my Sunday has been great, how about yours? It all started trying to upgrade from Ubuntu 19.04 to 20.10...

I've done this a number of times. You see, I have this system:

  • /home is in a separate partition
  • Most of my applications are installed by my linux-bootstrap
  • Wipe / and install fresh. Tell the installer to use my /home partition
  • Use direnv, pyenv, nodenv, etc to handle specific versions

The problems started when I used gparted to clean up some old partitions (specifically deleting some old Windows diag partitions). These were from Win7, so it was probably time. They were hidden/system partitions, and it seemed like gparted handled removing them correctly. I resized the home partition to use the (small) space freed, and everything seemed fine.

Started to do the installation, and something weird happened, still not sure what. The cryptic error message was something to the tune of:

The filesystem size (according to the superblock) is 11296582 blocks
The physical size of the device is 10093482 blocks
Either the superblock or the partition table is likely to be corrupt! 
Enter fullscreen mode Exit fullscreen mode

Apparently, it resized my home partition over the newly deleted diagnostic partitions, but those partitions weren't actually gone. Fortunately, I was running on the live-usb, and I felt I could recover. Google to the rescue...

However, most solutions seemed to fall short, and nothing seemed to work. Then I found TestDisk. This is the hammer you need when you are really in trouble. Using this, I was able to scan all the partitions. It lingered over the newly-resized home partition and managed to find the old partitions. Further, it gave me the choice of how to rewrite the partition table. I was able to really mark the diag partitions as deleted and write the new partitions.

e2fsck /dev/sda6 now showed no issues.

Huge sigh of relief...

Top comments (0)