RAID1 – How to Recover File System from Corrupted RAID1

data-recoveryext4mdadmraidsynology

TL;DR
How to recover the ext4 file system from a corrupted RAID1 partition?

My situation

I have one failed disk that belonged to an RAID1 array on a Synology DiskStation, the other one is lost.
Using ddrescue I've copied most of the relevant data to a new disk.
The partition table survied, however some blocks essential to the RAID setup are corrupted.

# fdisk -l /dev/sdd
Disk /dev/sdd: 3000.6 GB, 3000592982016 bytes
255 heads, 63 sectors/track, 364801 cylinders, total 5860533168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x0003f44a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1             256     4980735     2490240   fd  Linux raid autodetect
/dev/sdd2         4980736     9175039     2097152   fd  Linux raid autodetect
/dev/sdd3         9437184  3907024064  1948793440+  fd  Linux raid autodetect

The actual data is on the third partition /dev/sdd3, but mdadm can't assemble the array.

# mdadm --examine /dev/sdd
/dev/sdd:
   MBR Magic : aa55
Partition[0] :      4980480 sectors at          256 (type fd)
Partition[1] :      4194304 sectors at      4980736 (type fd)
Partition[2] :   3897586881 sectors at      9437184 (type fd)


# mdadm --examine /dev/sdd3
mdadm: No md superblock detected on /dev/sdd3.

As a result I am unable to mount the partition. The data is there and it is recognized by tools like foremost.

I have also tried using extundelete, but it fails without a proper ext superblock.

# extundelete --superblock /dev/sdd3
extundelete: failed to read-only open device "/dev/sdd3": Error code 2133571347

The question(s)

How to recover files and directories from a corrupted RAID1 partition?

Is there any way to recreate the md superblock, without loosing the existing data?

Would it be possible to ignore the md parts, to treat the partition as a corrupted ext4 partition and recover it that way?

Best Answer

You can use a loop mount to mount a partition in your disk image as a device. When creating the loop device, you give an offset which makes the loop device begin at that spot in the partition.

This way you can skip the missing MD superblock, and make the loop device start at the start of the ext4 partition or possible LVM.

Now, we need to know the size of the MD superblock in order to provide proper offset when creating loop device.

From MD manual article, one can see the superblock sizes and locations for different MD versions.

0.9 and 1.0 versions have the superblock at the end of the device, therefore the filesystem starts at the start of the device, and your mount command should have succeeded. So, your RAID Superblock must be some other version.

1.1 version has the superblock at start of the device, and 1.2 version has the superblock at 4k from start of the device.

However, there is plenty of space reserved for possible superblock expansion later on. One source tells me that the filesystem would start one megabyte after device start. In this case, you would try the following commands:

losetup /dev/loop0 /dev/sdd3 -o 1048576
mount /dev/loop0 /mnt

The first command sets up a loop device that starts at offset at one megabyte from the /dev/sdd3 partition start. Then, this loop device is mounted under /mnt.

The offset can be something else though, and unfortunately I couldn't find a good source for what the offsets could actually be.