What is the procedure to remove a logical volume or a LVM snapshot from a volume group?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux
  • Logical Volume Manager 2 (LVM 2)

Issue

  • What is the procedure to remove a logical volume (LV) or a LVM snapshot from a volume group?
  • How to delete an LVM volume or a volume snapshot?
  • How do I remove the inactive snapshots from RHEL server? They are not mounted and do not show in a df -h but are using space:
kernel: dracut: Scanning devices sda2 sda3  for LVM logical volumes root_vg/lv_swap root_vg/lv_root
kernel: dracut: inactive Original '/dev/root_vg/lv_root' [45.00 GiB] inherit
kernel: dracut: inactive '/dev/root_vg/lv_swap' [11.77 GiB] inherit
kernel: dracut: inactive Original '/dev/root_vg/lv_home' [74.53 GiB] inherit
kernel: dracut: inactive Snapshot '/dev/root_vg/lv_snapshot.1059735224' [4.50 GiB] inherit
kernel: dracut: inactive Snapshot '/dev/root_vg/lv_snapshot.1348956789' [7.45 GiB] inherit
kernel: device-mapper: snapshots: Snapshot is marked invalid.
kernel: Buffer I/O error on device dm-3, logical block 11796464
kernel: Buffer I/O error on device dm-3, logical block 11796464

Resolution

  • In order to remove LVM volumes first you need to check its existence and its status using the lvs command:

    # lvs -a
      LV    VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
      lvol0 vg2 owi-a-s-   2.00g                                           
      lvol1 vg2 swi-a-s- 100.00m      lvol0   25.22                        
      lvol2 vg2 swi-a-s- 100.00m      lvol0   50.33                        
      home  vg   -wi-ao--  43.97g                                           
      root  vg   -wi-ao--  40.00g                                           
      swap  vg   -wi-ao--  16.00g                                           
    
  • For each volume planning to remove it is essential to make sure that it is not mounted (in use). The lvremove command will normally not allow the removal of a volume that is in use but successful removal of a volume that is in use may cause instability to the system.

  • Finally the volume can be removed by using the command lvremove and as arguments the path of the volume under /dev filesystem. For example, if the volume to be removed on the above lvs output is lvol1 on vg2 volume group, the command will be:

    # lvremove vg2/lvol1
    Do you really want to remove active logical volume lvol1? [y/n]: y
      Logical volume "lvol1" successfully removed
    
  • If the volume is not active (doesn't have the "a" attribute at lvs output) the above confirmation message will not be displayed and the volume will be immediately removed.

    Note: that any data on the removed volumes will be deleted and the space they allocate will be again available to the volume group for future use. In case of removing snapshot volume, the data of the original volumes (from which these volumes where snapshots) will remain untouched.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments