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.
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_ 0,,0f _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.
Now it’s time to create a volume group:
# vgcreate vgstor_01 /dev/vdb1
Creating a logical volume
# lvcreate -l 3071 -n vstorage_01 vgstor_01