“mount: could not find any free loop device”解决方案

在一次关于KVM的测试中,这个命令:mount -o offset=16384 /share/xvs/var/tmep.img /mnt
得到如下错误提示信息:
mount: could not find any free loop device

表示loop Device以已经用完。最简单有效的方法是释放一些被占用的loop device,可以用如下命令:
losetup -d /dev/loop7 
(当然这里的loop7根据自己的情况来选择释放哪个loop device)

ll /dev/loop*   #查看有哪些loop deive
losetup -a   #show status of all loop devices
losetup /dev/loop0   #如果该设备loop已被使用,则会得到如下的提示
/dev/loop0: [0801]:266646 (/share/xvs/var/tmp-img_VTD_ASS_04_131), offset 16384
losetup /dev/loop6   #如果该设备loop未被使用,则会得到如下的提示
loop: can't get info on device /dev/loop6: No such device or address
losetup -d /dev/loop7     #detach the file or device associated with the specified loop device(s)

It is possible to increase the number of available loop devices. Free all loop devices, and add a line with the following to /etc/modprobe.conf(有的系统中是:/etc/modprobe.d/modprobe.conf):
options loop max_loop=64

或者直接运行命令(重启后将失效):
rmmod loop; modprobe loop max_loop=64

或者再grub中添加:
max_loop=64  #在kernel的启动行

和loop device相关的重要源代码文件为loop.c,里面有关于max_loop等的具体设置和实现:
drivers/block/loop.c

我用kvm时,loop device没有解除连接的问题,有人说qemu/KVM的问题,也有人说是mount工具自己的问题;有空再研究下吧,也许是qemu-kvm在guest关闭之时没有将资源释放完全。

参考资料:
https://github.com/dagwieers/mrepo/blob/master/docs/loop-devices.txt
http://lists.linuxcoding.com/rhl/2007q2/msg12780.html

master

Stay hungry, stay foolish.

发表评论

邮箱地址不会被公开。 必填项已用*标注

*