Reducing Volume Groups
Overview of Reducing a Volume Group
Understanding the concept of volume groups and physical volumes in the context of Logical Volume Management (LVM).
Advanced Operation: Reducing a Volume Group
A volume group (VG) can consist of multiple physical volumes (PVs).
A physical volume can be removed from a volume group if:
The remaining physical volumes have sufficient free space to accommodate its extensions.
The condition for successful removal is that there exists free extents, noted as "$p_{free} > 0$" in the output for PVs.
If remaining PVs are fully utilized, the removal process will fail.
Procedure for Reducing a Volume Group
Using PV Move:
Start by using the command
pvmoveto relocate any extents from the volume slated for removal to the remaining active volumes in the group.
Completing the Removal:
After all extents have been successfully moved, use the command
vgreduceto complete the removal of the specified physical volume from the volume group.
Practical Application of Reducing a Volume Group
This procedure is particularly useful in scenarios such as:
Anticipating potential hard disk failures (e.g., removing a failing disk).
Demonstration of the Procedure
Step 1: Setup Requirements
Creating Initial Partitions:
Utilize
fdiskto create two partitions, each sized at 2 GB and set to type LVM (Logical Volume Manager).Acknowledgment that no new partitions need to be created if free partitions already exist.
The partitions available:
NVMe0n1p4 (2 GB)
NVMe0n2p7 (2 GB)
Step 2: Create Volume Group
Command:
vgcreate vg_demo /dev/nvme0n1p4Here,
vg_demois designated as the name of the volume group, utilizing /dev/nvme0n1p4.
Step 3: Create Logical Volume
Command:
lvcreate -l 1G -n lv_demo vg_demoThis command does not allocate the entire available disk space.
Step 4: Check Available Space
Using
vgscommand shows:Size of 4 GB for VG demo, with 1 GB used, indicating 3 GB available.
Step 5: Adding a New Physical Volume to the Group
Command:
vgextend vg_demo /dev/nvme0n2p7This action adds the new physical volume (2 GB) to the existing volume group (vg_demo).
Step 6: Utilize Logical Extents
Command:
lvextend -L +500m /dev/vg_demo/lv_demo /dev/nvme0n2p7Ensures that extents are used on the newly added partition.
Step 7: Create a Filesystem
Using
mkfs.ext4 /dev/vg_demo/lv_demoThis action creates an ext4 filesystem.
Step 8: Mounting the Filesystem
Temporary mount location:
/mntCommand used:
mount /dev/vg_demo/lv_demo /mnt
Step 9: Creating a File for Testing
Command to create a file:
dd if=/dev/zero of=/mnt/bigfile bs=1M count=1100This command generates a sizable file (1100 MB), ensuring data allocation across both physical volumes.
Step 10: Move Extents from One PV to Another
Command:
pvmove -v /dev/nvme0n2p7 /dev/nvme0n1p4This command transfers all logical extents from /dev/nvme0n2p7 to /dev/nvme0n1p4.
The
-vflag indicates verbose output for tracking progress.
Final Steps: Verify Changes
Post-operation check using
pvs:Shows /dev/nvme0n2p7 is now empty, while /dev/nvme0n1p4 has increased in size.
Proceed to eliminate the empty physical volume with
vgreduce vg_demo /dev/nvme0n2p7.
Conclusion
Successful execution of the aforementioned steps demonstrates an advanced, yet attainable, procedure for safely removing storage devices from a volume group in LVM.
This enhanced understanding helps in managing disk space and ensuring system integrity when dealing with potential hardware failures.
Reducing a volume group is a valuable skill for systems administrators when maintaining efficient storage management strategies.