Course contentsShow
← Linux
Lesson 682 of 1,8197. Storage Management and Logical VolumesFree lesson

Removing unused LVM components

Safely shrink and decommission physical devices from a production volume group.

In this lesson, you will learn how to safely shrink your storage pool by migrating data off a disk and decommissioning it from your LVM configuration.

Understanding the Decommissioning Workflow

When you need to remove a physical disk (a Physical Volume or PV) from a Volume Group (VG), you cannot simply unplug it. LVM treats the VG as a unified pool of blocks; if those blocks belong to a Logical Volume (LV) that is currently in use, removing the disk will cause filesystem corruption.

The process of safely decommissioning a device follows a strict "data-out, device-out" workflow:

1. Migrating Data (pvmove)

Before a PV can be removed, you must ensure no data is stored on it. LVM provides the pvmove command, which acts like a "rebalancing" tool. It transparently copies the data from the source disk to other available disks within the same Volume Group while the system is still running.

# Move all extents from /dev/sdb1 to other free space in the VG
sudo pvmove /dev/sdb1

2. Reducing the Volume Group (vgreduce)

Once pvmove confirms that the disk is empty (using pvs to verify that "Allocated PE" is 0), you must tell the Volume Group to stop managing that device. The vgreduce command updates the LVM metadata to remove the physical volume from the group's registry.

# Remove the empty physical volume from the volume group
sudo vgreduce my_volume_group /dev/sdb1

3. Cleaning Up (pvremove)

Finally, once the disk is no longer part of an LVM group, you can wipe the LVM metadata headers from the drive itself using pvremove. This resets the disk, making it look like a "blank" block device again, ready to be repurposed or safely removed from the server.

# Erase the LVM label from the device
sudo pvremove /dev/sdb1

By following these three steps in order, you ensure that your data is never left in a "dangling" state and that your Logical Volumes remain intact throughout the physical hardware transition.

Key Takeaway: Always use pvmove to clear data off a disk before using vgreduce to detach it from the Volume Group, ensuring your storage remains consistent and healthy.