Logical Volume Management (LVM)
Logical Volume Management is a method of managing disk drives and similar mass-storage devices. In Linux, a logical volume manager perform this task for the Linux kernel. The manager is capable to allocate space on the mass-storage devices, dynamically move or resize the space while it is being used. The manager controls physical volumes, physical extends, logical extends, volume groups and logical volumes in order to perform this flexible space allocation.
A physical volume (PV) may be a hard disk partition, a RAID device or a SAN. A PV is split into chunks called physical extends (PEs). PEs are mapped one-to-one to logical extents (LEs) or are mirrored onto one LE. A volume group (VG) is a pool of LEs. LEs in a volume group can be concatenated into Logical Volumes (LVs). And finally these LVs are useable as a raw block devices just as disk partitions are; file systems can be created on an LV.
A VG can grow its storage pool by adding in new PVs or shrink by reducing PVs. An LV can grow by adding in more LEs or shrink by returning LEs to the pool.
In Linux operating systems, a logical volume manager can:
- Resize VGs online by adding in or reducing PVs.
- Resize LVs online by adding in or reducing LEs.
- Stripe whole or parts of LV across multiple PVs, in a fashion similar to RAID0.
- Mirror whole or parts of LV, in a fashion similar to RAID1.
- Move online logical volumes between PVs.
In the 2.6 Linux kernels, the LVM is implemented in terms of the device mapper, creating virtual block devices and mapping their space onto other block devices. While LVM user-space tools manipulate these mappings and reconstruct their state from on-disk metadata upon each invocation.
Redhat Enterprise Linux (RHEL) 5 provides an LVM user-space tool to implement logical volumes. The good news is that the tool runs on Terminal; thus, the implementation logical volumes in RHEL 5 can be performed via SSL connection remotely.
# lvm lvm>
There are a number of LVM commands available in this tool.
Available lvm commands: Use 'lvm help ' 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) lvconvert Change logical volume layout lvcreate Create a logical volume lvdisplay Display information about a logical volume lvextend Add space to a logical volume lvmchange With the device mapper, this is obsolete and does nothing. lvmdiskscan List devices that may be used as physical volumes lvmsadc Collect activity data lvmsar Create activity report lvreduce Reduce the size of a logical volume lvremove Remove logical volume(s) from the system lvrename Rename a logical volume lvresize Resize a logical volume lvs Display information about logical volumes lvscan List all logical volumes in all volume groups pvchange Change attributes of physical volume(s) pvresize Resize physical volume(s) pvck Check the consistency of physical volume(s) pvcreate Initialize physical volume(s) for use by LVM pvdata Display the on-disk metadata for physical volume(s) pvdisplay Display various attributes of physical volume(s) pvmove Move extents from one physical volume to another pvremove Remove LVM label(s) from physical volume(s) pvs Display information about physical volumes pvscan List all physical volumes segtypes List available segment types vgcfgbackup Backup volume group configuration(s) vgcfgrestore Restore volume group configuration vgchange Change volume group attributes vgck Check the consistency of volume group(s) vgconvert Change volume group metadata format vgcreate Create a volume group vgdisplay Display volume group information vgexport Unregister volume group(s) from the system vgextend Add physical volumes to a volume group vgimport Register exported volume group with system vgmerge Merge volume groups vgmknodes Create the special files for volume group devices in /dev vgreduce Remove physical volume(s) from a volume group vgremove Remove volume group(s) vgrename Rename a volume group vgs Display information about volume groups vgscan Search for all volume groups vgsplit Move physical volumes into a new volume group version Display software and driver version information
The example was performed using HP Integrity Server with RHEL 5.1 (Tikanga). The target hard disk was /dev/cciss/c0d1 that had one partition /dev/cciss/c0d1p1. The purpose was to create a logical volume on the partition. Notice that a hard disk partition like /dev/hdb1 or /dev/sdb1 may also be a target hard disk to implement logical volume.
- Add a new physical volumeShow the existing physical volumes.
lvm> pvs PV VG Fmt Attr PSize PFree /dev/cciss/c0d0p2 VolGroup00 lvm2 a- 68.22G 0
Add a new physical volume.
lvm> pvcreate /dev/cciss/c0d1p1 Physical volume "/dev/cciss/c0d1p1" successfully created
Show the current physical volumes.
lvm> pvs PV VG Fmt Attr PSize PFree /dev/cciss/c0d0p2 VolGroup00 lvm2 a- 68.22G 0 /dev/cciss/c0d1p1 lvm2 -- 67.77G 67.77G
- Create a new volume groupShow the existing volume groups.
lvm> vgs VG #PV #LV #SN Attr VSize VFree VolGroup00 1 2 0 wz--n- 68.22G 0
Create a new volume group.
lvm> vgcreate VolGroup01 /dev/cciss/c0d1p1 Volume group "VolGroup01" successfully created
Show the existing volume groups and physical volumes.
lvm> vgs VG #PV #LV #SN Attr VSize VFree VolGroup00 1 2 0 wz--n- 68.22G 0 VolGroup01 1 0 0 wz--n- 67.77G 67.77G lvm> pvs PV VG Fmt Attr PSize PFree /dev/cciss/c0d0p2 VolGroup00 lvm2 a- 68.22G 0 /dev/cciss/c0d1p1 VolGroup01 lvm2 a- 67.77G 67.77G
- Create a new logical volumeShow the existing logical volumes.
lvm> lvs LV VG Attr LSize Origin Snap% Move Log Copy% LogVol00 VolGroup00 -wi-ao 66.28G LogVol01 VolGroup00 -wi-ao 1.94G
Create a new logical volume.
lvm> lvcreate --size 30000 --name LogVol02 VolGroup01 Rounding up size to full physical extent 29.31 GB Logical volume "LogVol02" created
Show the current logical volumes and physical volumes.
lvm> lvs LV VG Attr LSize Origin Snap% Move Log Copy% LogVol00 VolGroup00 -wi-ao 66.28G LogVol01 VolGroup00 -wi-ao 1.94G LogVol02 VolGroup01 -wi-a- 29.31G lvm> pvs PV VG Fmt Attr PSize PFree /dev/cciss/c0d0p2 VolGroup00 lvm2 a- 68.22G 0 /dev/cciss/c0d1p1 VolGroup01 lvm2 a- 67.75G 38.44G
- Use the new logical volumeFormat the new logical volume.
# mkfs -t ext3 /dev/VolGroup01/LogVol02 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 3842720 inodes, 7684096 blocks 384204 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 235 block groups 32768 blocks per group, 32768 fragments per group 16352 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 38 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Mount the new logical volume.
# mount /dev/VolGroup01/LogVol02 /mnt/storage01 # df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 67323516 3138844 60709628 5% / /dev/cciss/c0d0p1 102182 9230 92952 10% /boot/efi tmpfs 1998224 0 1998224 0% /dev/shm /dev/mapper/VolGroup01-LogVol02 30254032 176200 28541016 1% /mnt/storage01