fixing corrupted drive in linux

· bergpb's blog

Fix corrupted partitions on a disk using Linux

Today I was checking my SSD devices and one was not working as expected after connect it on my Linux laptop (Fedora/Gnome user here).

Checking with Disks program, the disk was failed to mount due a bad superblock error 😿.

I was thinking that I've lost all data in there, but before try the full disk format I've performed a few searchs on the web, and found this: https://unix.stackexchange.com/a/566822.

Then with my fingers crossed 🍀, I've started to run all required commands to see if the disk back to life:

$ sudo e2fsck -f -v /dev/sdb
e2fsck 1.47.2 (1-Jan-2025)
The filesystem size (according to the superblock) is 125026902 blocks
The physical size of the device is 125026901 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? no
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

          51 inodes used (0.00%, out of 31260672)
           0 non-contiguous files (0.0%)
           0 non-contiguous directories (0.0%)
             # of inodes with ind/dind/tind blocks: 0/0/0
             Extent depth histogram: 4/39
    21689469 blocks used (17.35%, out of 125026902)
           0 bad blocks
          17 large files

          38 regular files
           4 directories
           0 character device files
           0 block device files
           0 fifos
           0 links
           0 symbolic links (0 fast symbolic links)
           0 sockets
------------
          42 files

First one without errors, even with a message showing about corrupted partitions.

Next one:

$ sudo fsck -f /dev/sdb
fsck from util-linux 2.40.4
e2fsck 1.47.2 (1-Jan-2025)
The filesystem size (according to the superblock) is 125026902 blocks
The physical size of the device is 125026901 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? no
/dev/sdb contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb: 51/31260672 files (0.0% non-contiguous), 21689469/125026902 blocks

Finally the last one:

$ sudo resize2fs /dev/sdb
resize2fs 1.47.2 (1-Jan-2025)
Resizing the filesystem on /dev/sdb to 125026901 (4k) blocks.
The filesystem on /dev/sdb is now 125026901 (4k) blocks long.

No major issues running the commands, now let's try to mount the disk and see if data still in there:

$ sudo mount /dev/sdb

$ ls

lost+found  folder1  folder2

After checking a few files, seems like they are not corrupted 🎉.
Now time to do a backup 🙂!

last updated: