Deleting a volume frees its storage back to the volume group, which can then be used to create new logical volumes or support growing an existing volume. lvremove command can be used to delete an LVM volume which we no longer intend to use. Please make sure you take a backup of the mount point in case you may want the data in it later on.
How to remove a LVM volume with lvremove
1. Unmount the filesystem with umount:
# umount /mnt
2. Open /etc/fstab and verify that there isn’t an entry to automatically mount the filesystem. If there is, remove the entry, save your changes, and close the file.
3. Use lvremove to delete the logical volume:
# lvremove vg0/myvol
4. Review the output of lvs to verify the removal.
How to remove LVM volume with error “filesystem in use”
Sometimes you might get below error while removing an LVM volume:
# lvchange -an /dev/mapper/vg-lv Logical volume vg/lv contains a filesystem in use
You may follow the steps outlined below in such cases:
Step 1: Try to identify if this particular LVM is mounted in your server.
# mount -a |grep /path-to-LV-volume
If mounted, unmount it.
Step 2: Check for open file desriptors or active processes running on this LV.
# lsof | grep /path-to-LV-volume
If the above command doesn’t return any output, try to ‘grep’ using just LV name. If you see any open processes or file descriptors, kill them using ‘pkill’ or ‘kill -9’ [ ‘man’ command for options].
Step 3: Remove LV.
# lvchange -an -v /path-to-LV-volume # lvremove -vf /path-to-LV-volume
Replace /path-to-LV-volume with actual path in the above commands.
lvremove Command Examples
1. To remove the logical volume:
# lvremove LV00
2. To forcefully remove the logical volume:
# lvremove -f LV00 # lvremove --force LV00
3. To disable udev synchronization:
# lvremove --noudevsync
4. To remove all logical volumes under any VG:
# lvremove VG00