Any activities pertaining to shrinking of volumes and file system sizes is considered high risk. One main reason is that we cannot revert and fix the file system if it encounters an error. As a general rule of thumb, a good back out plan should be in place. Virtual machine has a snapshot features and this needs to be utilized prior to shrinking of volumes and filesystems. In the case of a physical server, make sure a completed backup of mount points is taken prior to performing the disk removal.
Before we remove any disks in a volume group, the following needs to be performed:
- Determine the physical extents of the logical volumes and volume groups. We must ensure that there are no other physical extents assigned to a logical volume groups before proceeding to the change activity.
- Regardless the file system format, whether it is EXT or XFS, if the device does not have physical extent bindings the device can be removed.
- If the device for removal contains physical extent, it will need to be destroyed first before completely removing the disk from the volume group.
- If the logical volume groups are not using the device’s physical extent, the device can be removed without unmounting the volume groups. vgreduce would register an error stating that the device is busy if there are logical volumes using it regardless of whether it is mounted or not.
1. Locate the affected Volume:
2. Determine Physical extents of Physical Volume, Volume Group, and Logical Volume:
# pvdisplay [PV name] # vgdisplay -v [VG name] | egrep "Name|Alloc PE|PV Name|Total PE" # lvdisplay -m [VG name]
3. Before unmounting the volume, make sure that there are no running processes on top of the logical volume:
# lsof [mount point]
Note: Running lsof must not return any output.
1. If a Physical Volume has a Logical Volume bindings, therefore unmount the volume and destroy it is needed:
# umount [mount point] && lvchange -a n [LV path]
2. Remove the Logical Volume:
# lvremove [LV path]
3. Remove the Physical Volume from the Volume Group:
# vgreduce [volume group] [physical volume]