You are here: Home » Hardware » Servers » What is it LVM?

What is it LVM?

Let me begin, however, a brief introduction describing the benefits of LVM. The idea of using LVM is the ability to dynamically expand the space by adding a partition.

Alternatively, an explicit entire disk volume groups. We are expanding in this way, a physical place. Besides expanding “hot” can also shorten the space. Additional advantages of LVM are: backup in the form of snapshots that can be used as a data backup (without the need for file copy example. Rsync) and combining different volume groups (in whole or in parts) into one unit. LVM also allows mirroring.

To understand LVM better, imagine the physical volume as a pile of blocks.

A block is simply a unit of data storage. Several piles of blocks can be combined to make a much larger pile, just as physical volumes are combined to create a volume group. The resulting pile can be subdivided into several smaller piles of arbitrary size, just as a volume group is allocated to several logical volumes. The administrator may grow or shrink logical volumes without destroying data, unlike standard disk partitions. If the physical volumes in a volume group are on separate drives or RAID arrays then administrators may also spread a logical volume across the storage devices. You can lose data if you shrink a logical volume to a smaller capacity than required by the data contained in it. Therefore, create logical volumes of this size to meet your current needs, and leave excess storage capacity unallocated. You may safely grow logical volumes as needed.

Creating LVM

In this example, we will operate on a separate disk dedicated exclusively to the LVM. Let’s start with the preparation of the primary partition with LVM.

sfdisk /dev/vdb<<_EOF_

This command creates a new disk / dev / vdb primary partition on the entire disk with LVM. To view the correct partition we created.

# fdisk -l /dev/vdb
Disk /dev/vdb: 12.9 GB, 12884901888 bytes
16 heads, 63 sectors/track, 24966 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/vdb1 1 24966 12582863+ 8e Linux LVM[/code]

Creating a physical volume and volume group

To create pv our LVM execute:

#  pvcreate /dev/vdb1

Pvcreate command takes as a parameter the path to the physical partition on which I initialize the physical volume. To check the available physical volumes are made.

#  pvdisplay

Now it’s time to create a volume group:

#  vgcreate vgstor_01 /dev/vdb1
Vgcreate command as a basic parameter takes the name of the group (in this case vgstor_01) and the path to the partition on which it is already established PV. Please read the man 8 vgcreate to explore all possible options. To view all volume groups are made.
#  vgdisplay

Creating a logical volume

The following example will form a volume of the entire space available. To take all the free space the new LV we need the information displayed by vgdisplay and exactly the Total PE (total physical extents). In our example, this parameter has a value of 3071 extents (full value talking about how some data is divided into the resource LVM). And so we create LV volumes using the whole group:
#   lvcreate -l 3071 -n vstorage_01 vgstor_01
Now we can see all the logical volumes:
#   lvdisplay
This command displays the information to us such as. Size, name vg on which the logical volume creation time and the name of the host on which it was created.