In this article I explained the concepts behind the Logical Volume Manager (LVM). In this continuation I will have a look at the commands necessary to actually setup an environment with logical volumes. I will once again use the scenario of our storage machine as an example.
Our storage machine has three "disks". Two are the result of a raid 5 setup (/dev/sda and /dev/sdb) and one is a single disk (/dev/sdc) where the operating system lives. So of the three, sdc is where the OS is and both /dev/sda and /dev/sdb are fully used in their respective physical volumes (PV). You can run the command pvdisplay to see what PV's exist on your server. In the case of storage the output looks like this:
Fig. 1: The output of pvdisplay on our storage server
Two 2.73TB PV's are the base of our machine. So how where these PV's created? The command in question is pvcreate (You might start to notice a certain naming pattern ;) ). It takes several options and one ore more locations (remember, a PV can use a disk or a partition on a disk). The commands to create both PV's for storage look like pvcreate /dev/sda and pvcreate /dev/sdb.
Now, for the next step we need to create the volume group (VG). The command in question is vgcreate. Using this command to use the two PV's as base for our new volume group looks like this: vgcreate vg0 /dev/sd[a-b]. The result of this action can be seen below:
Fig. 2: The output of vgdisplay on our storage server
Time for the last step, creating a logical volume. Just as with our volume group, there's only one logical volume. The command is, you guessed it, lvcreate. To be more exact, this command has delivered the result below: lvcreate -L 5.46T -n lv0 vg0. A 5.46TB large logical volume called lv0 is created inside the volume group called vg0:
Fig. 3: The output of lvdisplay on our storage server
So I have a logical volume, now what?
A logical volume is a block device, so you can use it as you would any other block device (bonus info: read on (creating) Block device drivers). In the case of our storage machine, the newly created logical volume /dev/vg0/lv0 was added as a partition and mounted at /data.
So this was no rocket science, but I liked the idea of following the theory up with some practical information. It is not exhaustive at all, but the manpages of the different commands offer all information you're likely to need. I'd recommend using an old computer you don't use anymore to toy with these concepts so you will not ruin anything particularly valuable ;)