4
$ sudo losetup -f ~/vhost/.test_04

was hanging (sat for an hour without finding the next available loop.) So I checked by hand

$ sudo losetup -f
/dev/loop1

That looked to be functioning as expected, so I checked for availability with

$ sudo losetup -nl
/dev/loop8         0      0         1  0 ~/vhosts/.test_02 0
/dev/loop2         0      0         1  0 ~/vhosts/.test_03 0
/dev/loop0         0      0         1  0 ~/vhosts/.test_00 0 
/dev/loop3         0      0         0  0 ~/vhosts/.test_01 0

Good, loop1 seems unoccupied

$ sudo losetup /dev/loop1 ~/vhost/.test_04
losetup: ~/vhost/.test_04: failed to set up loop device: Device or resource busy

I checked with

$ for i in $(seq 0 14);do sudo losetup -nl /dev/loop$i; done 
/dev/loop0         0      0         1  0 ~/vhosts/.test_00 0
/dev/loop1         0      0         1  0 ~/vhosts/.test_01 0
/dev/loop2         0      0         1  0 ~/vhosts/.test_02 0
/dev/loop3         0      0         0  0 ~/vhosts/.test_03 0
/dev/loop4                          0  0             0
/dev/loop5                          0  0             0
/dev/loop6                          0  0             0
/dev/loop7                          0  0             0
/dev/loop8         0      0         1  0 ~/vhosts/.test_01 0
/dev/loop9         0      0         1  0 ~/vhosts/.test_01 0
/dev/loop10         0      0         1  0 ~/vhosts/.test_01 0
/dev/loop11         0      0         1  0 ~/vhosts/.test_01 0
/dev/loop12         0      0         1  0 ~/vhosts/.test_01 0
/dev/loop13         0      0         1  0 ~/vhosts/.test_01 0
losetup: /dev/loop14: failed to use device: No such device
$ ls -la /vhosts/.test_01
-rw------- 1 x x 2097152 Oct 17 21:31 ~/vhosts/.test_01

$ sudo cryptsetup status /dev/mapper/vda_01
/dev/mapper/vda_01 is active and is in use.
  type:    PLAIN
  cipher:  aes-xts-plain64
  keysize: 256 bits
  device:  /dev/loop8
  loop:    ~/vhosts/.test_01
  offset:  0 sectors
  size:    <good> sectors
  mode:    read/write

$ uname -a
Linux desktop 4.12.0-1-amd64 #1 SMP Debian 4.12.6-1 (2017-08-12) x86_64 GNU/Linux
$ sudo losetup --version
losetup from util-linux 2.30.2

Is this a bug in losetup or the linux kernel?

losetup -f Find the first unused loop device and print its name

does not seem to be functioning as expected from the documentation.

$ sudo lsof|grep loop
loop2      3208             root  cwd       DIR                8,6         4096          2 /
loop2      3208             root  rtd       DIR                8,6         4096          2 /
loop2      3208             root  txt   unknown                                            /proc/3208/exe
loop8      6958             root  cwd       DIR                8,6         4096          2 /
loop8      6958             root  rtd       DIR                8,6         4096          2 /
loop8      6958             root  txt   unknown                                            /proc/6958/exe
loop3     19520             root  cwd       DIR                8,6         4096          2 /
loop3     19520             root  rtd       DIR                8,6         4096          2 /
loop3     19520             root  txt   unknown                                            /proc/19520/exe
loop0     19605             root  cwd       DIR                8,6         4096          2 /
loop0     19605             root  rtd       DIR                8,6         4096          2 /
loop0     19605             root  txt   unknown                                            /proc/19605/exe
2
  • Nothing funny in syslog? Could the file ~/vhost/.test_04 itself have been busy, not losetup?
    – Xen2050
    Oct 18 '18 at 2:10
  • I checked lsof and .test_04 doesn't show up. syslog has no entry for losetup; kern.log and messages has: losetup invoked oom-killer: gfp_mask=0x14280ca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO), nodemask=(null), order=0, oom_score_adj=0 Oct 18 '18 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.