🌐 🇵🇱 Polski · 🇬🇧 EN
LVM (Logical Volume Manager) is a form of advanced partition management in Linux. The benefit of using LVM is the simplicity of managing and configuring two or more disks. However, working with LVM requires a more comprehensive approach to the subject to understand its essence. After completing the practical tasks, you will understand why LVM definitely makes life easier. If you are configuring your system for the first time, you have a certain number of physical disks. These disks form the basis for the LVM structure, and further for physical volumes. The next layer of the structure is the volume group, where physical volumes form a single storage pool. All of this together creates a structure called a logical volume, which constitutes the actual partition in the system.
There are many commands and tools in the system for managing logical volumes. Below is a list of useful commands and tools.
- pvs - Display physical volumes
- vgs - Display volume groups
- lvs - Display logical volumes
- pvdisplay - Detailed information for physical volumes
- vgdisplay - Detailed information for volume groups
- lvdisplay - Detailed information for logical volumes
- pvcreate - Create a new physical volume
- vgcreate - Create a new volume group
- lvcreate - Create a new logical volume
- vgextend - Extend an existing volume group
- lvextend - Extend a logical volume
- lvresize - Resize a logical volume
- lvreduce - Reduce the size of a logical volume
- lvrename - Rename a logical volume
- pvmove - Move / migrate data from one physical volume to another
- vgreduce - Reduce a volume group
- pvremove - Remove a physical volume
- vgremove - Remove a volume group
- lvremove - Remove a logical volume
There are many commands, and instead of describing each one separately, I will try to show their operation in practical tasks whenever possible. Let's start ...
Task 1 - Installing the necessary packages on the system (if they are present, you can skip this step)
# yum install -y lvm2
Task 2 - Verifying the installation
# rpm -qa | grep lvm in the output (the output may vary slightly depending on the version) :
lvm2-libs-2.02.72-8.el6.x86_64
lvm2-2.02.72-8.el6.x86_64
Task 3 - Display physical volumes in the system.
# pvs the output will look something like this:
PV VG Fmt Attr PSize PFree
/dev/hda2 vg_rhel601 lvm2 a- 19.51g 0
In RHEL5 versions, the names VolGroup and LogVol were used by default for volume groups and logical volumes; since the RHEL6 release, the names have been shortened to "vg_" and "lv-" used as a prefix.
Task 4 - Show detailed information about physical volumes.
# pvdisplay
-- Physical volume --
PV Name /dev/hda2
VG Name vg_rhel601
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID XI3mef-f2Qm-J5Ri-jiU9-qI8S-hBTI-No6tPn
By default, during RedHat installation, LVM is used for disk management. The command above displays the physical volumes created during installation. The next layer in the LVM structure will be the volume group.
Task 5 - display information about the volume group.
# vgs
VG #PV #LV #SN Attr VSize VFree
vg_rhel601 1 2 0 wz—n- 19.51g 0
Task 6 - Show detailed information about the volume group
# vgdisplay
-- Volume group --
VG Name vg_rhel601
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 19.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 0 / 0
VG UUID pDycLd-SMos-RLeW-656R-xUZv-b45T-485S8D
Task 7 - Show logical volumes
# lvs
LV VG Attr LSize Origin Snap% Move Log
Copy% Convert
lv_root vg_rhel601 -wi-ao 15.57g
lv_swap vg_rhel601 -wi-ao 3.94g
Task 8 - Display detailed information about logical volumes
# lvdisplay
-- Logical volume --
LV Name /dev/vg_rhel601/lv_root
VG Name vg_rhel601
LV UUID I1rLRo-T8Qu-uprj-FdIh-oCQi-6PgL-d0bGeC
LV Write Access read/write
LV Status available
# open 1
LV Size 15.57 GiB
Current LE 3986
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
-- Logical volume --
LV Name /dev/vg_rhel601/lv_swap
VG Name vg_rhel601
LV UUID JgOxey-h7Ih-mFgO-6mdt-uibZ-9W9H-I8tZKv
LV Write Access read/write
LV Status available
# open 1
LV Size 3.94 GiB
Current LE 1008
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
From this point on, it is clear how to extract information about LVM existing in a Linux system. You can also view the contents of the /etc/lvm directory, which contains all information on this topic.
Comments