Restoring data from raid + lvm disks
If you are, like me, using this kind of layout for your disks:
disks => raid1 => lvm (encrypted or not) => partitions => filesystems
(Remember never to use XFS with this layout, unless you want to be sure to loose data - XFS still has problems with the 4k stack. Also, do not use XFS if you are not using a power supply. Oh, well, remember not to use to XFS at all …)
This setup should ensure you to keep your data safe if one of the disk crashes. Good ! But what happens if you want to take one of the disks and mount it elsewhere (for ex. with an external USB converter) ? You have to re-create the FS stack manually, which can be quite tricky, so I post the commands here:
0 - find your disk partitions layout
# fdisk -l /dev/sdb
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 122 979933+ fd Linux raid autodetect
/dev/sdb2 123 14946 119073780 fd Linux raid autodetect
1 - Create a (degraded) raid array
# mdadm --assemble --run /dev/md0 /dev/sdb2
mdadm: /dev/md0 has been started with 1 drive (out of 2).
2 - Scan and create the LVM volume group
# lvmdiskscan |grep md
/dev/md0 [ 113.56 GB] LVM physical volume
# vgscan
Reading all physical volumes. This may take a while...
Found volume group \"raid1\" using metadata type lvm2
# lvscan |grep raid1
inactive '/dev/raid1/root' [20.00 GB] inherit
inactive '/dev/raid1/opt' [15.00 GB] inherit
inactive '/dev/raid1/pollux' [78.55 GB] inherit
Before the volume group can be used, it has to be activated.
# vgchange raid1 -a y
3 logical volume(s) in volume group "raid1" now active
If one of the volumes is encrypted, you have to play with cryptsetup
# cryptsetup luksOpen pcrypt /dev/raid1/pollux
3 - mount volumes
mount /dev/raid1/root /mnt
x - clean up the mess
It’s better to close properly the cryt, lvm, and raid devices before removing the disk.
# umount /mnt
# cryptsetup luksClose pcrypt
# vgchange raid1 -a n
0 logical volume(s) in volume group "raid1" now active
# mdadm --stop /dev/md0
mdadm: stopped /dev/md0
Happy Christmas, Hanukkah, Kwanzaa, Solstice, Insert-Favorite-Holiday, whatever !