Resolving “Can’t Remove Open Logical Volume” Error in LVM: Immediate Deletion Techniques


3 views

Many Linux administrators encounter this frustrating scenario when working with LVM:

$ sudo lvcreate vg -L 10G -n testvol
$ sudo lvremove vg/testvol
  Can't remove open logical volume "testvol"

Despite lvs showing no open indicator (-wi-a- instead of -wi-ao), the system insists the volume is in use.

The root cause lies in how udev and the device-mapper interact with LVM:

  • Immediately after creation, the kernel may still have temporary references to the device
  • Background udev processing might be scanning the new volume
  • Device-mapper might not have completed all cleanup operations

Method 1: Forced Removal with -f

The simplest approach is using the force flag:

$ sudo lvremove -f vg/testvol

Method 2: Explicit Deactivation First

Sometimes explicitly deactivating helps:

$ sudo lvchange -an vg/testvol
$ sudo lvremove vg/testvol

Method 3: Udev Synchronization

Wait for udev to complete processing:

$ sudo udevadm settle
$ sudo lvremove vg/testvol

Method 4: Device Cleanup

Manual device node cleanup can help:

$ sudo dmsetup remove vg-testvol
$ sudo lvremove vg/testvol

For scripting environments, consider this robust approach:

#!/bin/bash
VOLNAME="testvol"
VG="vg"

lvcreate -L 10G -n $VOLNAME $VG
dmsetup remove $VG-$VOLNAME || true
lvremove -f $VG/$VOLNAME

If issues persist, investigate with:

$ sudo dmsetup info -c vg-testvol
$ sudo lsof /dev/vg/testvol
$ sudo ls -l /dev/mapper/vg-testvol

Many Linux system administrators encounter this frustrating scenario when working with LVM:

$ sudo lvcreate vg -L 10G -n testvol
$ sudo lvremove vg/testvol
Can't remove open logical volume "vg/testvol"

$ sudo lvs vg/testvol
LV      VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
testvol vg   -wi-a----- 10.00g

Notice the attributes show -wi-a----- where we'd expect -wi-ao---- if the volume were truly open.

This occurs because of how device-mapper handles logical volumes internally. Even though the volume isn't mounted or actively used, there's a brief period where the kernel maintains references due to:

  • Device-mapper udev synchronization
  • Delayed cleanup in the device-mapper subsystem
  • Pending operations in the storage stack

Here are several approaches to force immediate removal:

Method 1: Using dmsetup

$ sudo dmsetup info -c | grep testvol
$ sudo dmsetup remove vg-testvol
$ sudo lvremove vg/testvol

Method 2: Forcing Removal

$ sudo lvremove --force vg/testvol

Method 3: Using wipefs

$ sudo wipefs -a /dev/vg/testvol
$ sudo lvremove vg/testvol

To avoid this issue in automated scripts:

# Best practice in scripts
sudo lvcreate vg -L 10G -n tempvol
sleep 0.5  # Brief delay to allow device initialization
sudo lvremove -f vg/tempvol

The device-mapper subsystem maintains several internal data structures. When you examine the device status in detail:

$ sudo dmsetup status vg-testvol
$ sudo ls -l /sys/block/dm-*/holders/

You'll often find transient references that haven't been cleared yet. Modern Linux kernels (5.4+) have improved this behavior, but it still occurs in certain storage configurations.