Tuesday, April 6, 2010

A quick LVM HOWTO for Ubuntu linux and SAN disk LUNs

First get your luns in order using multipath-tools.

If you have a whole bunch of LUNs presented to the same box, it can be hard to figure out which one is which. I found that multipath-tools creates devices like '/dev/disk/by-id/scsi-3600342349827399729' where the big number is the same as the WWID in the HP management console. If worst comes to worst you can present LUNs one-by-one and use the WWID to match them with what is in the HP management console.

Be aware that restarting multipath-tools didn't refresh the /dev/mapper/ list properly for me (and also threw out some segfaults, yay). I couldn't remove the kernel module because it was in use, so a reboot was the only way to ensure the /dev/mapper list was accurate.

Once you know which LUN you need to work on (in this example it is mpath0), create a LVM partition on your LUN, selecting '8e' as the partition type:
fdisk /dev/mapper/mpath0

Create your physical volume:
pvcreate /dev/mapper/mpath0-part1

At this point I noticed I had two identical devices: "/dev/mapper/mpath0p1" and "/dev/mapper/mpath0-part1". You should use "mpath0-part1" - the p1 partition disappeared for me after a reboot. Before I rebooted I tried restarting multipath-tools to see if that would remove the extra partition, but no dice (partprobe would be another thing to try...). While this partition exists, pvscan will give you an error like this (but it doesn't seem to cause any problems):
Found duplicate PV xKBwhsdfssdfkshdfkdfgdfDGiRj: using /dev/mapper/mpath0p1 not /dev/mapper/mpath0-part

Now create your volume group:
vgcreate myvgname /dev/mapper/mpath0-part1

Create your logical volume specifying size:
lvcreate -L 10G -n mylvname myvgname

OR
lvcreate -l 100%FREE -n mylvname myvgname

Slap on a filesystem:
mkfs -t ext4 /dev/myvgname/mylvname

and it is ready to be mounted. Grab the UUID for your fstab entry:
blkid /dev/myvgname/mylvname

No comments: