quarta-feira, 3 de junho de 2015

Recover data from a single RAID1 drive

If you found this blog post you probably know why you need it.

One good reason to run RAID1 is that all data is contained on both drives of the array. RAID1 is a cheap uptime-friendly setup which is not space efficient and should not be used on current hard drives (> 1TB). That's why current systems run RAID6 ... on expensive and reliable hardware with automatic backups and disaster recovery plans in place. What follows regarding RAID1 is, in general, impossible with any other RAID level.

With that in mind...

1. Insert drive on USB dock and connect it to a computer running Linux; in this example the device appears as /dev/sdb 

2. List available partitions
root@laptop:~# parted -l /dev/sdb
[...]
Model: WDC WD50 00AAKS-00YGA0 (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags
4 1049kB 10.7GB 10.7GB raid
5 10.7GB 21.5GB 10.7GB raid
1 21.5GB 23.6GB 2147MB raid
3 23.6GB 24.2GB 537MB raid
2 24.2GB 500GB 476GB raid
[...]
3. Setup RAID1 device using a single drive

If you know which partition was in use in the RAID array (ex: partition 2) just run
mdadm --assemble --verbose /dev/md0 /dev/sdb2
Otherwise, you can let mdadm guess. If you don't have other RAID members in the system it will probably work:
root@laptop:~# mdadm --assemble --verbose /dev/md0
mdadm: looking for devices for
/dev/md0

mdadm: no RAID superblock on /dev/sdb5
mdadm: /dev/sdb4 has wrong uuid.
mdadm: /dev/sdb3 has wrong uuid.
mdadm: /dev/sdb1 has wrong uuid.
mdadm: no RAID superblock on /dev/sdb
mdadm: no RAID superblock on /dev/sda5
mdadm: no RAID superblock on /dev/sda2
mdadm: no RAID superblock on /dev/sda1
mdadm: no RAID superblock on /dev/sda
mdadm: /dev/sdb2 is identified as a member of /dev/md0, slot 0.
mdadm: added /dev/sdb2 to /dev/md0 as 0
mdadm: /dev/md0 has been started with 1 drive.
4. Check status
root@laptop:~# cat /proc/mdstat Personalities : [raid1] [linear]
md0 : active linear sdb2[0]
464779264 blocks super 1.2 0k rounding

unused devices:

5. Mount device
mount /dev/md0 /mnt/recover
If the mount fails and you see this in the logs
Jun 3 14:32:53 ghlaptop kernel: [16068.061347] EXT4-fs (md0): bad block size 65536
try
apt-get fuseext2
fuseext2 -o ro -o sync_read /dev/md0 /mnt/recover
6. Backup your data
mkdir /root/raid1data
cp -R /mnt/recover /root/raid1data

References:
https://blog.sleeplessbeastie.eu/2012/05/08/how-to-mount-software-raid1-member-using-mdadm/
http://unix.stackexchange.com/questions/73536/how-can-i-mount-filesystems-with-4kb-block-sizes