RAID on LVM.

When it comes to RAID the most common scenario I’ve encoutered so far is hardware RAID, or management through mdadm. It’s not the only option though - you can achieve equivalent of this functionality through LVM.

LVM (Logical Volume Manager) is a mechanism for managing storage volumes… which IMO does not say that much. To simplify things a bit - it allows allocating of storage devices (PV) to groups (VG), from which you in the end carve logical resources (LV) which the OS treats like a partition. So for example it means we can pool several several disks into one partition. Even more - we can add more disks to the pool when we start running out of space (but mind - I’m not recommending that :D ). In the beggining this may sound weird - but in practice it’s pretty simple and adds a whole new layer of flexibility to the storage setup (and it definitely needs more reading / viewing - I oversimplified this a bit and really glanced over it). IMO the key to getting grasp of it is understanding relation between PV, VG and LV.

LVM Diagram

Ok, but why set up RAID this way? Is it faster than hardware one? No - the performance difference is pretty small (noticable mostly when dealing with small files) and sadly not in favor of LVM (I’ve added article about it at the end of this post).

Personally I’ve taken this approach mostly because of its flexibility - it’s easy to tweaks the pools. Another bonus is that I’m using a single tool while doing that, I don’t have to jump between several ones.

That was the key when I’ve been configuring a station where I want to test software deployments, start temporary VMs and experiment with settings. Some will be probably surprised by the use of RAID0 - but let me explain. Data security and its cohesion is not important in this particular use case. The speed and ease of use is. Things that are stored on it are wiped on a regular basis and even if something goes corrupted mid test that’s not a big deal. This system does not store (and it really shouldn’t) any important stuff.

Of course if someone needs something more robust you can set up RAID5 for example with this approach as well.

In short this setup involved following steps:

  1. Hard drive preparation (change sdX for appropriate device in your system)
parted /dev/sdX

in parted:

mktable gpt

Then:

fdisk /dev/sdX

, entered “n”, used whole available space, “w” to save.

  1. LVM Physical Volume setup

for each drive from step one:

pvcreate -v /dev/sdaX
  1. LVM Volume Group - adding PV to required groups
vgcreate -v GROUPNAME /dev/sdX1 /dev/sdX2
  1. LVM Logical Volume - creating the volumes accessible by operating system from the space available in group
lvcreate --type raid0 -i 2 -l 100%FREE GROUPNAME -n FINAL_VOLUME_NAME
  1. Creation of filesystem
mkfs.ext4 /dev/GROUPNAME/FINAL_VOLUME_NAME

Resources

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/lv

https://opensource.com/article/21/9/add-storage-lvm

https://blog.programster.org/create-raid-with-lvm

https://tldp.org/HOWTO/LVM-HOWTO/recipethreescsistripe.html

https://askubuntu.com/questions/219881/how-can-i-create-one-logical-volume-over-two-disks-using-lvm

https://www.linuxtoday.com/blog/raid-vs-lvm/

Image(s):

Benjamin Lehman, @Unsplash