在 amd64 LXC 容器内运行的命令:
debootstrap --arch armhf --foreign --variant=buildd --components=main,restricted,universe,multiverse vivid /var/lib/schroot/chroots/vivid-armhf http://ports.ubuntu.com/ubuntu-ports
最终失败如下:
W: Failure trying to run: mount -t proc proc /proc
W: See //debootstrap/debootstrap.log for details
主机上的系统日志有以下内容:
audit: type=1400 audit(1449495124.972:29): apparmor="DENIED" operation="mount" info="failed type match" error=-13 profile="lxc-container-default" name="/var/lib/schroot/chroots/vivid-armhf/proc/" pid=25739 comm="mount" fstype="proc" srcname="proc" flags="rw"
audit: type=1400 audit(1449495124.976:30): apparmor="DENIED" operation="mount" info="failed type match" error=-13 profile="lxc-container-default" name="/var/lib/schroot/chroots/vivid-armhf/proc/" pid=25739 comm="mount" fstype="proc" srcname="proc" flags="ro"
而且确实不可能挂载:
user@vm:~$ sudo chroot /var/lib/schroot/chroots/vivid-armhf
/usr/bin/groups: cannot find name for group ID 0
I have no name!@vm:/# mount -t proc proc /proc
mount: proc is write-protected, mounting read-only
mount: cannot mount proc read-only
I have no name!@vm:/#
需要在 LXC 容器配置中添加什么才能允许这样的挂载?
答案1
新的配置文件:
sudo tee /etc/apparmor.d/lxc/lxc-default-with-proc-mounting <<EOM
profile lxc-default-with-proc-mounting flags=(attach_disconnected,mediate_deleted) {
#include <abstractions/lxc/container-base>
mount fstype=proc options=ro -> /**,
}
EOM
进入容器配置:
lxc.aa_profile = lxc-default-with-proc-mounting
重新加载配置文件:
sudo systemctl reload apparmor
重新启动容器。