Kpartx Can Not Detach

Home » CentOS » Kpartx Can Not Detach
CentOS 2 Comments

OS: EL6 – sometimes I use

kpartx -a /mnt/…/lvdisk.img

to map the partitions and mount them via

/dev/mapper/loop0pX

After using the disk (unmounting it) I noticed that detaching such mapping via kpartx -d does not result in freeing up the loop devices. Results: System reboots shows that the filesystem where lvdisk.img is located can’t be unmounted.

lsof, fuser, ps does not show any usage. Even removing the device node via

dmsetup remove /dev/mapper/loop0pX

does not help. Trying to unmount the underlying filesystem still shows /mnt: device is busy.

Any other suggestions would be greatly appreciated!

2 thoughts on - Kpartx Can Not Detach

  • Am 07.03.2018 um 19:35 schrieb Jim Perrin :

    With some heuristic I got following results (briefly):

    Jumping into the image/file directory and adding the partition map (kpartx -a) and removing it (kpartx -d) works!

    So the output of losetup between this two activities shows:

    losetup -a
    /dev/loop0: [0821]:130822 (kvm-system-CentOS6_x86_64-devel-lv_vm_intern_spare.img)

    but when adding the partition map with an absolut _long_ path detaching/deleting the map doesn’t work.

    losetup -a
    /dev/loop0: [0821]:130822 (/mnt/pool/VirtLibrary/3-live/kvm-system-CentOS6_x86_64-devel-l*)

    shortening the path and adding the partition map with an absolut path and removing it works again.

    losetup -a
    /dev/loop0: [0821]:130822 (/mnt/kvm-system-CentOS6_x86_64-devel-lv_vm_intern_spare.img)

    So, is kpartx or the underlying loop handle limited to a 64 character long file pointer?

    Anyway, at least I can work around it …