Monday 17 November 2014

Recovering corrupted partition from a Bad Superblock

First, I will explain what is a superblock and its relation with metadata.

The simple way to explain metadata is by comparing it with an employee of a company.  When an employee works for a company, he/she will have a joining date, employee id, team identity etc. The same is in case of a file/folder, it will have its own identity such as its creation date, permission ownership etc:

Now, the question is what is superblock.

Superblock in simple words is a bigger form of metadata. For example, when you create a partition, it will be created with specific size, inode numbers, file system type etc:

This is stored in superblock.

Sometimes you may encounter following error, while trying an fsck on a corrupted partition.
/dev/sda3: Input/output error
mount: /dev/sda3: can't read superblock

Don't panic, we have to follow the following procedure inorder to solve the issue.

As I explained before, superblock is a bigger form of metadata information. It has got very important information about the whole filesystem. So, it is important to have its backup and infact, it will be created when a filesystem is formatted. The location of backup superblocks can be found using the following command:

root@manoj[~]# dumpe2fs /dev/sda1 | grep superblock
dumpe2fs 1.41.12 (17-May-2010)
  Primary superblock at 0, Group descriptors at 1-1
  Backup superblock at 32768, Group descriptors at 32769-32769
  Backup superblock at 98304, Group descriptors at 98305-98305

Now, perform an fsck to the partition using the alternate superblock.
fsck -b 32768 /dev/sda1

That's it :)  Now, some important notes:
NEVER TRY TO RUN FSCK ON A MOUNTED PARTITION. YOU WILL END UP IN DATA LOSS.  The reason behind this is that, the data of the mounted partition, will be accessed by several applications and it may be loaded to the memory. Once you start running fsck, you will start loosing data which is in memory.


You can also try to mount the partition using backup superblock as below:

mount sb={alternative-superblock} /dev/device /mnt
mount sb=32768 /dev/sda2 /mnt

No comments:

Post a Comment

Note: only a member of this blog may post a comment.