Recovering RAID and LVM

From Gentoo Linux Wiki

Jump to: navigation, search

Contents

[edit] Introduction/Scope

This page was created after I spent a number of hours trying to recover a LVM2 partition atop a RAID1 element. I figured this may save someone else the trouble and stress, or at least mitigate either somewhat.

The configuration that I had before attempting this recovery was thus:

/dev/hdb[1235] + /dev/sda[1234] = /dev/md[1234]

/dev/md1 = /boot
/dev/md2 = swap
/dev/md3 = /
/dev/md4 = LVM2 (main_vg)
 - contained home, opt, usr, tmp, var

[edit] Boot a Gentoo Live CD

No other Live CD I possess has the necessary tools to recognize both the raid and the lvm2. Just pop it in and wait for it to load up

[edit] Load Necessary Modules

If you are running RAID1, modprobe the following:

modprobe md
modprobe raid1

For LVM2, modprobe the following:

modprobe dm-mod

[edit] Prepare RAID

With some Live CDs, the md devices are not immediately present. To enable these, execute the following:

cd /dev 
MAKEDEV md

If you have access to your raidtab/mdadm.conf file, you should copy it into /etc (with the Live CD still being the root), and enable raid via

raidstart /dev/md?

or the mdadm way (TODO: add mdadm directions)

mdadm -E --scan {list of raid devices /dev/hda1 /dev/hdb1} > /etc/mdadm.conf
echo "DEVICE /dev/hda*" >> /etc/mdadm.conf
echo "DEVICE /dev/hdb*" >> /etc/mdadm.conf
mdadm -A -s

or

mdadm -A /dev/md0 /dev/hda1 /dev/hdb1

View the /proc/mdstat file to ensure the expected number of drives are operational.

[edit] Mount the Mundane

Mount the devices that are non-LVM (which may be different for your box):

mount /dev/md3 /mnt/gentoo
mount /dev/md1 /mnt/gentoo/boot

[edit] Reestablish Volume Group

To tap into the volume group you wish to work with, make sure /etc/lvm/lvm.conf filters are able to see the /dev/md? devices, and execute the following:

vgscan

which should display the volume group associated with an md device you enabled. Then, to make the logical volumes (LVs) available for mounting, execute the following:

vgchange -ay {vg name}

[edit] Mount the Less Mundane

Now all you need do is mount the reestablished LVs. I find this an excellent time to make use of Bash:

for i in `ls /dev/{vg name}`; do mount /dev/{vg name}/$i /mnt/gentoo/$i; done;

Of course, you must change {vg name} to the name of your volume group, as above.

Personal tools