08 June, 2009

Adding LVM2 for flexible volume management on top of RAID

So as I mentioned a while back I also added LVM2 (Logical Volume Management) on top of my software RAID arrays (well, only one of them so far). This is really easy as LVM can use any existing partitions, be they actual regular partitions or RAID partitions. Here's what I did:
First tell lvm which existing partitions you want to use (pv stands for "physical volume"). In my case there are three RAID arrays
lvm pvcreate /dev/md0
lvm pvcreate /dev/md1
lvm pvcreate /dev/md2
You can probably leave out lvm, it seems to work anyway. The same goes for all commands below, I just included them for completeness.
Then you create an actual volume group out of each physical volume (I guess this adds data structures so that lvm can keep track of the logical volumes you create in the next step, and any changes later on). I only use one of the physical volumes due to the issue with hal that I mentioned in the previous post. data is my name for the volume group.
lvm vgcreate /dev/md0 data
I then add the logical volumes that I want. These are then used like ordinary partitions and must be formatted with a file system before use. You decide how large the logical volumes should be and their name. The final part of the command tells lvm which volume group should be used according to the name in the previous command.
lvm lvcreate --size 200G --name home data
lvm lvcreate --size 200G --name bkp data
lvm lvcreate --size 800G --name media data
These "partitions" will then show up in in /dev/mapper/home, /dev/mapper/bkp, /dev/mapper/media and can be formatted and mounted like any regular partition. Note that I did leave quite a bit of space unused, mainly this is for testing resizing later on. The nice thing with lvm is that you can eaily resize these things as disk space is added to the volume group, but of course the file system must be able to handle it.
Finally to get my Arch Linux system to recognize the volumes I modified the lvm line in /etc/rc.conf to read:
USELVM="yes"
And then I added a couple of hooks in /etc/mkinitcpio.conf, one for RAID and one for LVM2, so that the volumes are recognized when the system boots: mdadm lvm2
Finally I rebuilt the kernel and initrd to include the hooks by just letting pacman reinstall with the new settings:
pacman -Sy kernel26
This is probably the easiest way although you can rebuild manually as well of course, if you have specific requirements.
And then it was a breeze to install Arch, telling it to use the logical volumes home, bkp, and media wherever I wanted them in the file system. home is obviously used for home directories (currently mainly used for "backing up" home directories on other computers), bkp is used for backup storage of family photos and videos (and probably other stuff too in the future), while media is used to store recorded TV (Mythtv recordings as well as old movies) and our audio library (including iTunes audio - only iTunes Plus so it is portable). The setup seems to work very well, but we'll see if any problems arise in case I have all four tuners recording at the same time... :D
Btw, you can actually boot from a RAID/LVM2 partition as well but I did not want to do this, I want the system to boot even if there's something wrong with this slightly complex setup.

No comments:

Post a Comment