7

I am trying to detach a loopback device.

The losetup --detach presumably succeeds (no error message and return code 0) but the device is still there.

Any ideas?

root@Cassiopeia:~# losetup -a
/dev/loop1: [2053]:5243868 (/var/lib/snapd/snaps/core_6034.snap)
/dev/loop6: [2053]:19401380 (/tmp/imagefile)
/dev/loop4: [2053]:5249290 (/var/lib/snapd/snaps/canonical-livepatch_49.snap)
/dev/loop2: [2053]:5243293 (/var/lib/snapd/snaps/canonical-livepatch_50.snap)
/dev/loop0: [2053]:5249134 (/var/lib/snapd/snaps/core_5897.snap)
/dev/loop5: [2053]:5249130 (/var/lib/snapd/snaps/core_6130.snap)
/dev/loop3: [2053]:5244442 (/var/lib/snapd/snaps/canonical-livepatch_54.snap)
root@Cassiopeia:~# losetup --detach /dev/loop6
root@Cassiopeia:~# echo $?
0
root@Cassiopeia:~# losetup -a
/dev/loop1: [2053]:5243868 (/var/lib/snapd/snaps/core_6034.snap)
/dev/loop6: [2053]:19401380 (/tmp/imagefile)
/dev/loop4: [2053]:5249290 (/var/lib/snapd/snaps/canonical-livepatch_49.snap)
/dev/loop2: [2053]:5243293 (/var/lib/snapd/snaps/canonical-livepatch_50.snap)
/dev/loop0: [2053]:5249134 (/var/lib/snapd/snaps/core_5897.snap)
/dev/loop5: [2053]:5249130 (/var/lib/snapd/snaps/core_6130.snap)
/dev/loop3: [2053]:5244442 (/var/lib/snapd/snaps/canonical-livepatch_54.snap)
1
  • You have to umount them first. Commented Jan 6, 2019 at 8:57

2 Answers 2

2

I know it's old but I just came across a similar problem.

It's that way because something has the device still open, it doesn't have to be mounted. Try lsof and similar commands to find what is it.

It my case it was parted hanging on the other terminal ;)

2

That happened to me too a while ago, and noticed this can happen in a number of ways:

  • If you accessed one of the directories, through some terminal (eg, used cd and you didn't either closed said terminal or you're still on those said directories)

  • If other process/command is using the mounted loop device/directories.

Based on this answer, you can use:

fuser -c /dev/loop0
fuser -d /dev/loop0
fuser -f /dev/loop0

To get all necessary information, such as PID, etc.

You can then use either fuse -k or kill -9 if you really must, but do know it's probably a bad idea to force the termination of the process like this.

If you want to attempt to gracefully kill it, (say, if you don't know how to access the process who use the mount/loop device):

kill PID

should work.

Lastly, given that this is about snap (based on the output on your post) you probably shouldn't try to remove or unmount them, unless you want to either uninstall snap completely or remove individual snap package.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .