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

  1. Using PV Move:

    • Start by using the command pvmove to relocate any extents from the volume slated for removal to the remaining active volumes in the group.

  2. Completing the Removal:

    • After all extents have been successfully moved, use the command vgreduce to 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 fdisk to 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/nvme0n1p4

    • Here, vg_demo is designated as the name of the volume group, utilizing /dev/nvme0n1p4.

Step 3: Create Logical Volume

  • Command: lvcreate -l 1G -n lv_demo vg_demo

    • This command does not allocate the entire available disk space.

Step 4: Check Available Space

  • Using vgs command 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/nvme0n2p7

    • This 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/nvme0n2p7

    • Ensures that extents are used on the newly added partition.

Step 7: Create a Filesystem

  • Using mkfs.ext4 /dev/vg_demo/lv_demo

    • This action creates an ext4 filesystem.

Step 8: Mounting the Filesystem

  • Temporary mount location: /mnt

    • Command 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=1100

    • This 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/nvme0n1p4

    • This command transfers all logical extents from /dev/nvme0n2p7 to /dev/nvme0n1p4.

    • The -v flag 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.