Mounting a Linux software raid array with lvm

November 17, 2008
I recently had a hard drive crash on my home Linux NAS box. The important files were on a software raid 5 array, but the root filesystem (with the majority of the OS) were on a separate IDE hard drive.Only the IDE drive crashed so my important files were safe, but I needed to remount the raid array. It took me quite a while before I got that right, so I'll share my knowledge here for you. Here are the commands needed to reconstruct / remount a raid array with a Gentoo live cd:load the raid module and lvm driver if you need to:# modprobe raid5# modprobe dm-mod

Find the UUID's of the devices

( you can skip this step if you have a backup of your /etc/mdadm.conf file )# mdadm --examine --scan /dev/sda1Where /dev/sda1 points to one of the partitions used for the raid array. The output looks like this on my box:ARRAY /dev/md1 level=raid5 num-devices=4 UUID=94366f38:ccdadda0:06f85cb1:f1263d52copy it to /etc/mdadm.conf# mdadm --examine --scan /dev/sda1 >> /etc/mdadm.confNow we need to add a list of devices to mdadm.conf of where to look for member disks:
(manually add this to mdadm.conf, the devices i had to add where /dev/sda1 to /dev/sdd1)DEVICE /dev/sd[abcd]1At the end that leaves us with this in our mdadm.conf file:DEVICE /dev/sd[abcd]1ARRAY /dev/md1 level=raid5 num-devices=4 UUID=94366f38:ccdadda0:06f85cb1:f1263d52

Assemble the raid array

We make the mirror device node:# mknod /dev/md1 b 9 1Assemble the array:# mdadm --assemble --scan You can check /proc/mdstat to see if the array is online:# cat /proc/mdstatPersonalities : [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]md1 : active raid5 sda1[0] sdd1[3] sdc1[2] sdb1[1] 937705728 blocks level 5, 64k chunk, algorithm 2 [4/4] [UUUU]

Activate the logical volumes

# vgscanScans your disk and should show you the Volume Group that was on the raid array and add it to the lvm database# vgchange -ayThis should activate the volumes and auto create the nodes in /dev

Mount the filesystems

I just needed to mount the filesystems just like I would mount a regular one:mount --type ext3 /dev/vg2/var /mnt/gentoo/varHope this helps someone!

Discussion, links, and tweets

I work at Venture Spirit. Follow me on Twitter; you'll enjoy my tweets. I take care to carefully craft each one. Or at least aim to make you giggle. Or offended. One of those two— I haven't decided which yet.