Home > Computers, Howto, Linux > Recovering Bad Superblock on ext4

Recovering Bad Superblock on ext4

Shortly after my last post, my aging Dell Studio laptop learned the hard way that gravity can sometimes be a cruel and heartless mistress. I learned a couple of lessons too. Notably that 1) Dell Studio laptops do not bounce and 2) hardwood floors are called that for a reason. After recovering the pieces (well most of them), sadly the computer would no longer boot, and the screen was beyond repair.

I got myself set up again with a nice, Ubuntu-happy laptop, which I’ll tell you about in another post. I removed the hard drive from the old Dell and put it in a 2.5″ external USB enclosure to try to try and mount my /home partition for data recovery, which is when I got the dreaded “Bad superblock on /dev/sdb3″ error.

Interestingly fsck is happy to tell you that you have a bad superblock, but it doesn’t tell you either what a superblock is, or how to fix the problem. So, first things first, the superblock is a record of the filesystem details, such as its size, block size, the used and unused blocks, the size and location of the inode tables, and so on. Any time you access a file, the superblock is read.

So, how can you recover a bad superblock? Fortunately for us, backup copies of the superblock are kept at certain offsets on the disk. To find out where the superblock backups are, open a terminal window and type:

sudo mke2fs -n /dev/????

Where ???? is the partition you want to check, which in my case was sdb3. This produces output, like the following:

Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

These are block numbers, signifying the location of the superblock backups.

To replace the superblock with one from a backup, type the following:

sudo e2fsck -y -b block_location /dev/????

Replace block_location with one of the above numbers and, again, ???? is the partition, so in my case it was sdb3.

There was significant corruption on my hard drive, but supplying the -y switch stopped fsck asking for confirmation every time it encountered a bad block.

After running this, I was able to mount the partition and recover my data.

  1. March 17th, 2012 at 23:23 | #1

    Useful posting. Wish never use it for my hds. :-)

  2. gully
    March 18th, 2012 at 16:17 | #2

    Thanks for such an usefull howto.
    Very good finding about laptop not bouncing :)

  3. March 18th, 2012 at 17:14 | #3

    Thanks for your comments :)

    Yes…Newtown proved gravity with an Apple…I used a Dell!

    I’ll get my coat :P

  4. Sebastien
    April 2nd, 2012 at 13:12 | #4

    Being in IT you probably know of SpinRite. http://www.grc.com/spinrite.htm

    I haven’t had a dropped laptop yet, but do use it for regular preventive maintenance and many users have found it invaluable in recuperating bad / damaged hard drives.

    p.s. I have nothing to do with that company!

  5. April 2nd, 2012 at 13:24 | #5

    Hi Sebastien,

    Yes, I’d used SpinRite before. I might give it a try again because, although I recovered nearly all of my data, the drive doesn’t format properly now. SpinRite might help me resurrect it :)

    Thanks for the tip!

  6. Chris webb
    June 21st, 2012 at 00:37 | #6

    I just wanted to say thank you I have been spending the last few days scouring for ways to fix this very issue and to this point none had worked until I stumbled across yours. Thanks you so much for putting this out there.
    Not to mention unlike most sites it was incredibly easy to follow.

  7. June 21st, 2012 at 00:49 | #7

    You’re welcome – I’m glad it worked for you, because I know the stress and anxiety that data loss can cause!!

  8. July 28th, 2012 at 10:49 | #8

    Actually, a few hard disks back I had this sort of thing a lot on one particular drive — naturally my main drive — after fscking frequently for a long time, I found it was caused by the SATA connector: I had changed SATA cables several times, but not thought it was the motherboard connection… Asus isn’t particularly Linux friendly at the best of times, so I thought it was due to general incompatibility with OpenSUSE for a time.

    After switching to another connection, no more badblocks.

  9. Tim
    May 16th, 2013 at 12:14 | #9

    Sir, u indeed saved my ass trying to restore a broken ext4 within a vmware vmdk image… long story… it worked out by inserting by converting the broken vmdk with StarWind V2V and reinserting it into a functional VM… then inside the VM i could use your code and a hundred attempts to get my data back… thx a lot!

  1. March 17th, 2012 at 21:29 | #1