Questo contenuto non è disponibile nella lingua selezionata.
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
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
lvm2
package is installed. - One or more physical volumes are created. For more information about creating physical volumes, see Creating LVM physical volume.
Procedure
List and identify the PV that you want to include in the VG:
# pvs
Create a VG:
# vgcreate VolumeGroupName PhysicalVolumeName1 PhysicalVolumeName2
Replace 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 ExtentSize
option. 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:
# vgs VG #PV #LV #SN Attr VSize VFree VolumeGroupName 1 0 0 wz--n- 28.87g 28.87g
Additional resources
-
vgcreate(8)
,vgs(8)
, andpvs(8)
man pages on your system
3.2. Creating volume groups in the web console
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 8 web console.
For instructions, see Installing and enabling the web console.
-
The
cockpit-storaged
package 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 8 web console.
For details, see Logging in to the 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
You can use the vgrename
command to rename a volume group (VG).
Prerequisites
- Administrative access.
-
The
lvm2
package is installed. - One or more physical volumes are created. For more information about creating physical volumes, see Creating LVM physical volume.
- The volume group is created. For more information about creating volume groups, see Section 3.1, “Creating an LVM volume group”.
Procedure
List and identify the VG that you want to rename:
# vgs
Rename the VG:
# vgrename OldVolumeGroupName NewVolumeGroupName
Replace 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:
# vgs VG #PV #LV #SN Attr VSize VFree NewVolumeGroupName 1 0 0 wz--n- 28.87g 28.87g
Additional resources
-
vgrename(8)
,vgs(8)
man pages
3.4. Extending an LVM volume group
You can use the vgextend
command to add physical volumes (PVs) to a volume group (VG).
Prerequisites
- Administrative access.
-
The
lvm2
package is installed. - One or more physical volumes are created. For more information about creating physical volumes, see Creating LVM physical volume.
- The volume group is created. For more information about creating volume groups, see Section 3.1, “Creating an LVM volume group”.
Procedure
List and identify the VG that you want to extend:
# vgs
List and identify the PVs that you want to add to the VG:
# pvs
Extend the VG:
# vgextend VolumeGroupName PhysicalVolumeName
Replace 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:
# pvs PV VG Fmt Attr PSize PFree /dev/sda VolumeGroupName lvm2 a-- 28.87g 28.87g /dev/sdd VolumeGroupName lvm2 a-- 1.88g 1.88g
Additional resources
-
vgextend(8)
,vgs(8)
,pvs(8)
man pages
3.5. Combining LVM volume groups
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
lvm2
package is installed. - One or more physical volumes are created. For more information about creating physical volumes, see Creating LVM physical volume.
- Two or more volume group are created. For more information about creating volume groups, see Section 3.1, “Creating an LVM volume group”.
Procedure
List and identify the VG that you want to merge:
# vgs VG #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.88g
Merge the source VG into the destination VG:
# vgmerge VolumeGroupName2 VolumeGroupName1
Replace VolumeGroupName2 with the name of the source VG. Replace VolumeGroupName1 with the name of the destination VG.
Verification
Verify that the VG now includes the new PV:
# vgs VG #PV #LV #SN Attr VSize VFree VolumeGroupName1 2 0 0 wz--n- 30.75g 30.75g
Additional resources
-
vgmerge(8)
man page on your system
3.6. Removing physical volumes from a volume group
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/vdb4 Physical volume "/dev/vdb4" successfully created
Add the newly created physical volume to the volume group:
# vgextend VolumeGroupName /dev/vdb4 Volume group "VolumeGroupName" successfully extended
Move 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/vdb3 Removed "/dev/vdb3" from volume group "VolumeGroupName"
Verification
Verify that the /dev/vdb3 physical volume is removed from the VolumeGroupName volume group:
# pvs PV 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
Additional resources
-
vgreduce(8)
,pvmove(8)
, andpvs(8)
man pages on your system
3.7. Splitting a LVM volume group
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 will consist of /dev/vdb1 and /dev/vdb2, and the second volume group, VolumeGroupName2, will consist of /dev/vdb3.
Prerequisites
-
You have sufficient space in the volume group. Use the
vgscan
command 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 volume using the
pvmove
command. 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/vdb3 Volume group "VolumeGroupName2" successfully split from "VolumeGroupName1"
NoteIf you have created a logical volume using the existing volume group, use the following command to deactivate the logical volume:
# lvchange -a n /dev/VolumeGroupName1/LogicalVolumeName
View the attributes of the two volume groups:
# vgs VG #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:
# pvs PV 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
Additional resources
-
vgsplit(8)
,vgs(8)
, andpvs(8)
man pages on your system
3.8. Moving a volume group to another system
You can move an entire LVM volume group (VG) to another system 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 /dev/mnt/LogicalVolumeName
Deactivate all logical volumes in the volume group, which prevents any further activity on the volume group:
# vgchange -an VolumeGroupName vgchange -- volume group "VolumeGroupName" successfully deactivated
Export the volume group to prevent it from being accessed by the system from which you are removing it:
# vgexport VolumeGroupName vgexport -- volume group "VolumeGroupName" successfully exported
View the exported volume group:
# pvscan PV /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 VolumeGroupName
NoteYou can use the
--force
argument of thevgimport
command to import volume groups that are missing physical volumes and subsequently run thevgreduce --removemissing
command.Activate the volume group:
# vgchange -ay VolumeGroupName
Mount the file system to make it available for use:
# mkdir -p /mnt/VolumeGroupName/users # mount /dev/VolumeGroupName/users /mnt/VolumeGroupName/users
Additional resources
-
vgimport(8)
,vgexport(8)
, andvgchange(8)
man pages on your system
3.9. Removing LVM volume groups
You can remove an existing volume group 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 VolumeGroupName VG #LV VolumeGroupName 0
Replace VolumeGroupName with the name of the volume group.
Remove the volume group:
# vgremove VolumeGroupName
Replace VolumeGroupName with the name of the volume group.
Additional resources
-
vgs(8)
,vgremove(8)
man pages on your system
3.10. Removing LVM volume groups in a cluster environment
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 VolumeGroupName VG #LV VolumeGroupName 0
Replace VolumeGroupName with the name of the volume group.
Stop the
lockspace
on all nodes except the node where you are removing the volume group:# vgchange --lockstop VolumeGroupName
Replace VolumeGroupName with the name of the volume group and wait for the lock to stop.
Remove the volume group:
# vgremove VolumeGroupName
Replace VolumeGroupName with the name of the volume group.
Additional resources
-
vgremove(8)
,vgchange(8)
man page