About
LVM adds an abstraction layer between filesystems and partitions.
Logical volume management is a widely-used technique for deploying logical rather than physical storage. With LVM, “logical” partitions can span across physical hard drives and can be resized (unlike traditional ext3 “raw” partitions). A physical disk is divided into one or more physical volumes (Pvs), and logical volume groups (VGs) are created by combining PVs as shown below. Notice the VGs can be an aggregate of PVs from multiple physical disks.
LVM adds an abstraction layer between filesystems and partitions. This is extremely handy because it's easy to add a disk (which is made physical volume) to a volume group which makes space available, which can be added to any logical volume in the volume group. When that's done, the filesystem in the logical volume can be enlarged with resize2fs, even online. Without LVM, it's not possible or very hard at best to do that.
To know all the command of the Logical Volume Manager tape:
man lvm
because lvm use a lot of symlink.
Articles Related
Basic LVM commands
The basic
To start lvm (the logical volume manager software), just tape lvm on the command prompt. To have:
- a list of all lvm command, tape help
- an help for one specific command, tape “help lvmcommand”
Example:
[root@oel11g ~]# lvm
lvm> help
Available lvm commands:
Use 'lvm help <command>' for more information
dumpconfig Dump active configuration
formats List available metadata formats
help Display help for commands
lvchange Change the attributes of logical volume(s)
..................................
lvm> help pvresize
pvresize: Resize physical volume(s)
pvresize
[-d|--debug]
[-h|-?|--help]
[--setphysicalvolumesize PhysicalVolumeSize[kKmMgGtTpPeE]
[-t|--test]
[-v|--verbose]
[--version]
PhysicalVolume [PhysicalVolume...]
Converting disks or disk partitions into physical volumes (PVs)
To use LVM, partitions and whole disks must first be converted/initialized into physical volumes (PVs) using the pvcreate command.
In a “normal” production system it is recommended that only one PV exists on a single real disk, for the following reasons:
- Administrative convenience
It's easier to keep track of the hardware in a system if each real disk only appears once. This becomes particularly true if a disk fails.
- To avoid striping performance problems
LVM can't tell that two PVs are on the same physical disk, so if you create a striped LV then the stripes could be on different partitions on the same disk resulting in a decrease in performance rather than an increase.
Whole disks
For example, to convert /dev/sda and /dev/sdb into PVs use the following commands:
pvcreate /dev/sda
pvcreate /dev/sdb
Partitions
If a Linux partition is to be converted make sure that it is given partition type 0x8E using fdisk:
[root@ebs121 ~]# fdisk -l
Disk /dev/sda: 375.8 GB, 375809638400 bytes
255 heads, 63 sectors/track, 45689 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
then use pvcreate:
pvcreate /dev/sda2
Creating/Managing a volume group (VG)
Once you have one or more physical volumes created, you can create a volume group from these PVs using the vgcreate command.
The following command:
vgcreate volume_group_one /dev/hda /dev/hdb
creates a new VG called volume_group_one with two disks, /dev/hda and /dev/hdb, and 4 MB PEs. If both /dev/hda and /dev/hdb are 128 GB in size, then the VG volume_group_one will have a total of 2**16 physical extents that can be allocated to logical volumes.
Additional PVs can be added to this volume group using the vgextend command. The following commands convert /dev/hdc into a PV and then adds that PV to volume_group_one:
pvcreate /dev/hdc
vgextend volume_group_one /dev/hdc
This same PV can be removed from volume_group_one by the vgreduce command:
vgreduce volume_group_one /dev/hdc
Note that any logical volumes using physical extents from PV /dev/hdc will be removed as well. This raises the issue of how we create an LV within a volume group in the first place.
pvdisplay will show an which VG belongs a PV
[root@ebs121 ~]# pvdisplay
/dev/hdc: open failed: No medium found
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 19.89 GB / not usable 19.49 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 636
Free PE 0
Allocated PE 636
PV UUID rg85Xj-lu0n-HWmE-50D5-8SfC-AGtC-Ln0JaL
Logical Volume
[root@ebs121 ~]# lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID B0EwV0-5XTH-1GLF-LTW2-8q9q-3Ou0-rsggEM
LV Write Access read/write
LV Status available
# open 1
LV Size 347.94 GB
Current LE 11134
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
Extending a logical volume
An LV can be extended by using the lvextend command. You can specify either an absolute size for the extended LV or how much additional storage you want to add to the LVM. For example:
[root@ebs121 ~]# lvextend -L+330G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 347.94 GB
Logical volume LogVol00 successfully resized
will extend LV /dev/VolGroup00/LogVol00 by an additional 330 GB.
Once a logical volume has been extended, the underlying file system can be expanded to exploit the additional storage now available on the LV.