Wednesday, February 1, 2012

lvremove: Can't remove open logical volume

Working with lvm I have come across many a times when the logical volume removal doesn't work. I am listing down those steps to stop searching solution on google every time. Moreover the information is scattered. So I include all here.

Details
My Volume Groups = deploy
My Logical Volume = relimg

The lvremove command is used to remove. But many a times this might not work in one shot. I use a shell script to do it-
lvremove -f /dev/deploy/relimg_*        while [ $? -ne 0 ];
do
   sleep 1;
   lvremove -f /dev/deploy/
relimg_*;
done

lvremove /dev/deploy/relimg*
  Can't remove open logical volume "relimg_root"
  Can't remove open logical volume "relimg_var"
  Can't remove open logical volume "relimg_swap"

dmsetup ls| grep relimg
deploy-relimg_swap    (253, 28)
deploy-relimg_root    (253, 26)
deploy-relimg_var    (253, 27)

See for each
dmsetup info -c deploy-relimg_var
 Name              Maj Min Stat Open Targ Event  UUID                                                                
deploy-relimg_var 253  30 L--w    1    1      0 LVM-JWRaaEr4Fpx0HGFzDuIXNgy0CDzV4KpWQ9tWYGVu3tT5sR1nAjJPc5FBM2rhT8vF

See that Open as 1 is the problem.
Now you need to use dmsetup to close.

dmsetup remove deploy-relimg_var
lvremove /dev/deploy/relimg_var

You might also get follow error on this command (dmsetup remove deploy-relimg_var)
device-mapper: remove ioctl failed: Device or resource busy
Command failed

If so, following will help
  • lsof, see where device is busy, stop it and do above steps again
  • mount, see if logical volume is mounted, unmount and do above steps again

8 comments:

  1. if you still face that issue, you can reboot the server to fix that :)

    ReplyDelete
  2. Just tried rebooting my server and indeed it worked! Thanks! :)

    ReplyDelete
  3. This works but it has a drawback....

    If you create an LVM snapshot using "lvcreate -s" you get 3 additional "kdmflush" processes in the process list. If you can successfully destroy it using "lvremove" they all disappear. However, if you have to use "dmsetup remove" it leaves one of the "kdmflush" processes hanging around.

    As I am continously creating snapshots and destroying them this results in hundreds of unreaped "kdmflush" processes.

    ReplyDelete
  4. still not successful.

    # dmsetup remove linux1vg-linux1smap
    device-mapper: remove ioctl failed: Device or resource busy
    Command failed

    both fuser and lsof didn't find anything using it.

    ReplyDelete
  5. Thanks much Boss - Saved my day.

    ReplyDelete
  6. Hi Vivek, you can go through the following link to resolve this kind of issue.

    http://kb.eclipseinc.com/kb/why-cant-i-remove-a-linux-logical-volume/

    ReplyDelete