I need to learn how to use LVM and I just want to write some summary here.
The first I see are the main components:
- Physical Volumes: This are basically as real disk, or loopback disk, I imagine that any block device can be used as a physical volume.
- Volume Group: This acts as a bunch of virtual space that can be extendend with different physical groups. We have here a unit of space called PE.
- Logic Volume: This is like a virtual block device formed from a subset of a volume group (some amount of PEs). We can control in which Physical group of the volume group we want the logic volume.
- Snapshots: Basically it take a copy of some base logic volumen and make a new one but changes to the base are not seen in the new one, we can use it as a good strategy for taking backups without stop our system. Also changes on the new system are stored in a COW-space that we can control its size when we create it.
Some useful commands:
pvcreate /dev/loop0it basically creates a new physical volumen.
vgcreate test /dev/loop0creates a new volume group with the
vgextend test /dev/loop1adds a new physical group (
/dev/loop1) to the volumen group
lvcreate -L2G -n base testcreates a new logical volume (
base) in the volume group
lvcreate -s -L1G -n snapshot0 /dev/test/base /dev/loop1Create an snapshot in
/dev/test/snapshot0from the logic volume
/dev/test/baseand reserve 1G the space for the COW Space.
To mount loopbacks:
losetup /dev/loop0 file.dd.
If you run out of loopbacks:
modprobe loop max_loop=64, you can make it permanent in
And to create empty files in a fast way:
truncate --size 1G file
Read the LVM [manuals][http://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/index.html] of Centos, in particular the [LV_Create section][http://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/LV_create.html]. This [blog][http://www.anthonyldechiaro.com/blog/2010/12/19/lvm-loopback-how-to/] was useful too.