losetup 未找到第一个未使用的循环设备,并且无法列出繁忙的设备

losetup 未找到第一个未使用的循环设备,并且无法列出繁忙的设备
$ sudo losetup -f ~/vhost/.test_04

挂了(坐了一个小时都没找到下一个可用的循环。)所以我手动检查了一下

$ sudo losetup -f
/dev/loop1

它看起来运行正常,所以我检查了

$ 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

很好,loop1 似乎无人使用

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

我检查过了

$ 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

这是 losetup 或 Linux 内核的一个错误吗?

losetup -f 查找第一个未使用的循环设备并打印其名称

似乎没有按照文档预期的那样运行。

$ 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

相关内容