Showing posts with label can't remove open logical volume. Show all posts
Showing posts with label can't remove open logical volume. Show all posts

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