Chapter 3. Managing LVM volume groups
You can create and use volume groups (VGs) to manage and resize multiple physical volumes (PVs) combined into a single storage entity.
Extents are the smallest units of space that you can allocate in LVM. Physical extents (PE) and logical extents (LE) has the default size of 4 MiB that you can configure. All extents have the same size.
When you create a logical volume (LV) within a VG, LVM allocates physical extents on the PVs. The logical extents within the LV correspond one-to-one with physical extents in the VG. You do not need to specify the PEs to create LVs. LVM will locate the available PEs and piece them together to create a LV of the requested size.
Within a VG, you can create multiple LVs, each acting like a traditional partition but with the ability to span across physical volumes and resize dynamically. VGs can manage the allocation of disk space automatically.
3.1. Creating an LVM volume group Copy linkLink copied to clipboard!
You can use the vgcreate command to create a volume group (VG). You can adjust the extent size for very large or very small volumes to optimize performance and storage efficiency. You can specify the extent size when creating a VG. To change the extent size you must re-create the volume group.
Prerequisites
- Administrative access.
-
The
lvm2package is installed. - One or more physical volumes are created. For more information about creating physical volumes, see Creating an LVM physical volume.
Procedure
List and identify the PV that you want to include in the VG:
# pvsCreate a VG:
# vgcreate VolumeGroupName PhysicalVolumeName1 PhysicalVolumeName2Replace VolumeGroupName with the name of the volume group that you want to create. Replace PhysicalVolumeName with the name of the PV.
To specify the extent size when creating a VG, use the
-s ExtentSizeoption. Replace ExtentSize with the size of the extent. If you provide no size suffix, the command defaults to MB.
Verification
Verify that the VG is created:
# vgsVG #PV #LV #SN Attr VSize VFree VolumeGroupName 2 0 0 wz--n- 28.87g 28.87g
3.2. Creating volume groups in the web console Copy linkLink copied to clipboard!
Create volume groups from one or more physical drives or other storage devices.
Logical volumes are created from volume groups. Each volume group can include multiple logical volumes.
Prerequisites
You have installed the RHEL 10 web console.
For instructions, see Installing and enabling the web console.
-
The
cockpit-storagedpackage is installed on your system. - Physical drives or other types of storage devices from which you want to create volume groups.
Procedure
- Log in to the RHEL 10 web console.
- Click .
- In the Storage table, click the menu button.
- From the drop-down menu, select Create LVM2 volume group.
- In the Name field, enter a name for the volume group. The name must not include spaces.
Select the drives you want to combine to create the volume group.
The RHEL web console displays only unused block devices. If you do not see your device in the list, make sure that it is not being used by your system, or format it to be empty and unused. Used devices include, for example:
- Devices formatted with a file system
- Physical volumes in another volume group
- Physical volumes being a member of another software RAID device
Click .
The volume group is created.
Verification
- On the Storage page, check whether the new volume group is listed in the Storage table.
3.3. Renaming an LVM volume group Copy linkLink copied to clipboard!
You can use the vgrename command to rename a volume group (VG).
Prerequisites
- Administrative access.
-
The
lvm2package is installed. - One or more physical volumes are created. For more information about creating physical volumes, see Creating an LVM physical volume.
- The volume group is created. For more information about creating volume groups, see Creating an LVM volume group.
Procedure
List and identify the VG that you want to rename:
# vgsRename the VG:
# vgrename OldVolumeGroupName NewVolumeGroupNameReplace OldVolumeGroupName with the name of the VG. Replace NewVolumeGroupName with the new name for the VG.
Verification
Verify that the VG has a new name:
# vgsVG #PV #LV #SN Attr VSize VFree NewVolumeGroupName 1 0 0 wz--n- 28.87g 28.87g
3.4. Extending an LVM volume group Copy linkLink copied to clipboard!
You can use the vgextend command to add physical volumes (PVs) to a volume group (VG).
Prerequisites
- Administrative access.
-
The
lvm2package is installed. - One or more physical volumes are created. For more information about creating physical volumes, see Creating an LVM physical volume.
- The volume group is created. For more information about creating volume groups, see Creating an LVM volume group.
Procedure
List and identify the VG that you want to extend:
# vgsList and identify the PVs that you want to add to the VG:
# pvsExtend the VG:
# vgextend VolumeGroupName PhysicalVolumeNameReplace VolumeGroupName with the name of the VG. Replace PhysicalVolumeName with the name of the PV.
Verification
Verify that the VG now includes the new PV:
# pvsPV VG Fmt Attr PSize PFree /dev/sda VolumeGroupName lvm2 a-- 28.87g 28.87g /dev/sdd VolumeGroupName lvm2 a-- 1.88g 1.88g
3.5. Combining LVM volume groups Copy linkLink copied to clipboard!
You can combine two existing volume groups (VGs) with the vgmerge command. The source volume will be merged into the destination volume.
Prerequisites
- Administrative access.
-
The
lvm2package is installed. - One or more physical volumes are created. For more information about creating physical volumes, see Creating an LVM physical volume.
- Two or more volume groups are created. For more information about creating volume groups, see Creating an LVM volume group.
Procedure
List and identify the VG that you want to merge:
# vgsVG #PV #LV #SN Attr VSize VFree VolumeGroupName1 1 0 0 wz--n- 28.87g 28.87g VolumeGroupName2 1 0 0 wz--n- 1.88g 1.88gMerge the source VG into the destination VG:
# vgmerge VolumeGroupName2 VolumeGroupName1Replace VolumeGroupName2 with the name of the destination VG. Replace VolumeGroupName1 with the name of the source VG.
Verification
Verify that the VG now includes the new PV:
# vgsVG #PV #LV #SN Attr VSize VFree VolumeGroupName2 2 0 0 wz--n- 30.75g 30.75g
3.6. Removing physical volumes from a volume group Copy linkLink copied to clipboard!
To remove unused physical volumes (PVs) from a volume group (VG), use the vgreduce command. The vgreduce command shrinks a volume group’s capacity by removing one or more empty physical volumes. This frees those physical volumes to be used in different volume groups or to be removed from the system.
Procedure
If the physical volume is still being used, migrate the data to another physical volume from the same volume group:
# pvmove /dev/vdb3/dev/vdb3: Moved: 2.0% ... /dev/vdb3: Moved: 79.2% ... /dev/vdb3: Moved: 100.0%If there are not enough free extents on the other physical volumes in the existing volume group:
Create a new physical volume from /dev/vdb4:
# pvcreate /dev/vdb4Physical volume "/dev/vdb4" successfully createdAdd the newly created physical volume to the volume group:
# vgextend VolumeGroupName /dev/vdb4Volume group "VolumeGroupName" successfully extendedMove the data from /dev/vdb3 to /dev/vdb4:
# pvmove /dev/vdb3 /dev/vdb4/dev/vdb3: Moved: 33.33% /dev/vdb3: Moved: 100.00%
Remove the physical volume /dev/vdb3 from the volume group:
# vgreduce VolumeGroupName /dev/vdb3Removed "/dev/vdb3" from volume group "VolumeGroupName"
Verification
Verify that the /dev/vdb3 physical volume is removed from the VolumeGroupName volume group:
# pvsPV VG Fmt Attr PSize PFree Used /dev/vdb1 VolumeGroupName lvm2 a-- 1020.00m 0 1020.00m /dev/vdb2 VolumeGroupName lvm2 a-- 1020.00m 0 1020.00m /dev/vdb3 lvm2 a-- 1020.00m 1008.00m 12.00m /dev/vdb4 VolumeGroupName lvm2 a-- 1020.00m 0 1020.00m
3.7. Splitting an LVM volume group Copy linkLink copied to clipboard!
If there is enough unused space on the physical volumes, a new volume group can be created without adding new disks.
In the initial setup, the volume group VolumeGroupName1 consists of /dev/vdb1, /dev/vdb2, and /dev/vdb3. After completing this procedure, the volume group VolumeGroupName1 consists of /dev/vdb1 and /dev/vdb2. The second volume group, VolumeGroupName2, consists of /dev/vdb3.
Prerequisites
-
You have sufficient space in the volume group. Use the
vgscancommand to determine how much free space is currently available in the volume group. -
Depending on the free capacity in the existing physical volume, move all the used physical extents to other physical volumes. You can do this by using the
pvmovecommand. For more information, see Removing physical volumes from a volume group.
Procedure
Split the existing volume group VolumeGroupName1 to the new volume group VolumeGroupName2:
# vgsplit VolumeGroupName1 VolumeGroupName2 /dev/vdb3Volume group "VolumeGroupName2" successfully split from "VolumeGroupName1"NoteIf you have created a logical volume by using the existing volume group, use the following command to deactivate the logical volume:
# lvchange -a n /dev/VolumeGroupName1/LogicalVolumeNameView the attributes of the two volume groups:
# vgsVG #PV #LV #SN Attr VSize VFree VolumeGroupName1 2 1 0 wz--n- 34.30G 10.80G VolumeGroupName2 1 0 0 wz--n- 17.15G 17.15G
Verification
Verify that the newly created volume group VolumeGroupName2 consists of /dev/vdb3 physical volume:
# pvsPV VG Fmt Attr PSize PFree Used /dev/vdb1 VolumeGroupName1 lvm2 a-- 1020.00m 0 1020.00m /dev/vdb2 VolumeGroupName1 lvm2 a-- 1020.00m 0 1020.00m /dev/vdb3 VolumeGroupName2 lvm2 a-- 1020.00m 1008.00m 12.00m
3.8. Moving a volume group to another system Copy linkLink copied to clipboard!
You can move an entire LVM volume group (VG) to another system by using the following commands:
vgexport- Use this command on an existing system to make an inactive VG inaccessible to the system. Once the VG is inaccessible, you can detach its physical volumes (PV).
vgimport- Use this command on the other system to make the VG, which was inactive in the old system, accessible in the new system.
Prerequisites
- No users are accessing files on the active volumes in the volume group that you are moving.
Procedure
Unmount the LogicalVolumeName logical volume:
# umount /mnt/LogicalVolumeNameDeactivate all logical volumes in the volume group, which prevents any further activity on the volume group:
# vgchange -an VolumeGroupName0 logical volume(s) in volume group "VolumeGroupName" now activeExport the volume group to prevent it from being accessed by the system from which you are removing it:
# vgexport VolumeGroupNameVolume group "VolumeGroupName" successfully exportedView the exported volume group:
# pvscanPV /dev/sda1 is in exported VG VolumeGroupName [17.15 GB / 7.15 GB free] PV /dev/sdc1 is in exported VG VolumeGroupName [17.15 GB / 15.15 GB free] PV /dev/sdd1 is in exported VG VolumeGroupName [17.15 GB / 15.15 GB free] ...- Shut down your system and unplug the disks that make up the volume group and connect them to the new system.
Plug the disks into the new system and import the volume group to make it accessible to the new system:
# vgimport VolumeGroupNameNoteYou can use the
--forceargument of thevgimportcommand to import volume groups that are missing physical volumes and subsequently run thevgreduce --removemissingcommand.Activate the volume group:
# vgchange -ay VolumeGroupNameMount the file system to make it available for use:
# mkdir -p /mnt/VolumeGroupName/users# mount /dev/VolumeGroupName/users /mnt/VolumeGroupName/users
3.9. Removing LVM volume groups Copy linkLink copied to clipboard!
You can remove an existing volume group by using the vgremove command. Only volume groups that do not contain logical volumes can be removed.
Prerequisites
- Administrative access.
Procedure
Ensure the volume group does not contain logical volumes:
# vgs -o vg_name,lv_count VolumeGroupNameVG #LV VolumeGroupName 0Replace VolumeGroupName with the name of the volume group.
Remove the volume group:
# vgremove VolumeGroupNameReplace VolumeGroupName with the name of the volume group.
3.10. Removing LVM volume groups in a cluster environment Copy linkLink copied to clipboard!
In a cluster environment, LVM uses the lockspace <qualifier> to coordinate access to volume groups shared among multiple machines. You must stop the lockspace before removing a volume group to make sure no other node is trying to access or modify it during the removal process.
Prerequisites
- Administrative access.
- The volume group contains no logical volumes.
Procedure
Ensure the volume group does not contain logical volumes:
# vgs -o vg_name,lv_count VolumeGroupNameVG #LV VolumeGroupName 0Replace VolumeGroupName with the name of the volume group.
Stop the
lockspaceon all nodes except the node where you are removing the volume group:# vgchange --lockstop VolumeGroupNameReplace VolumeGroupName with the name of the volume group and wait for the lock to stop.
Remove the volume group:
# vgremove VolumeGroupNameReplace VolumeGroupName with the name of the volume group.