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.
Useful posting. Wish never use it for my hds.
Thanks for such an usefull howto.
Very good finding about laptop not bouncing
Thanks for your comments
Yes…Newtown proved gravity with an Apple…I used a Dell!
I’ll get my coat
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!
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!
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.
You’re welcome – I’m glad it worked for you, because I know the stress and anxiety that data loss can cause!!
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.
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!