12

docker挂载ISO/分区时报failed to setup loop device: No such file or directory

 3 years ago
source link: https://my.oschina.net/u/3059462/blog/5088856
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

docker挂载ISO/分区时报failed to setup loop device: No such file or directory

在使用Docker容器的时候,如果需要使用mount命令,则必须使用特权模式启动Docker

使用特权模式启动docker的方式为添加--privileged  例如 docker run -it --privileged -d 镜像名

如果是API模式,则需要添加HostConfig参数中{"Privileged":true }

在使用特权模式启动docker后,进入到docker内部使用mount命令挂载某些ISO或者分区文件时可能出现

mount -o loop ./xxx.iso /mnt/cdrom
mount: ./xxx.iso: failed to setup loop device: No such file or directory

当然,如果没有使用特权模式的情况下,使用mount命令会提示权限不足

mount -t ./xxx.iso /dev/cdrom /mnt/cdrom
mount: permission denied

我们假设我们使用了特权模式,在挂载的情况下遇到了failed to setup loop device

那么我们需要关注以下两点

1、确保安装了循环设备内核模块

lsmod |grep loop

如果没有任何输出,则代表你需要安装内核模块

modprobe loop

2、确认下/dev和/dev/shm分区的大小

这两个分区通常挂载tmpfs分区文件,在正常的物理服务器或者虚拟服务器中不会出现这类问题,而在docker中很有可能出现

我们需要使用

df -h

命令查看下这两个分区的大小

如果分区太小也会出现failed to setup loop device的问题,作者就遇到了这个情况。

mount -o size=10240M -o remount /dev
mount -o size=10240M -o remount /dev/shm

我将这两个分区调整大小后。搞定


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK