使用最新的 ubuntu 13.04;我已经安装了 lxc 和各种其他工具
这是我的 XML 定义:
<domain type='lxc'>
<name>vm1</name>
<memory>500000</memory>
<os>
<type>exe</type>
<init>/bin/bash</init>
</os>
<vcpu>1</vcpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/lib/libvirt/libvirt_lxc</emulator>
<interface type='network'>
<source network='default'/>
</interface>
<console type='pty' />
</devices>
</domain>
我定义它:
virsh --connect lxc:/// define application-test.xml
但是当我尝试开始时:
root@lxc:~# virsh --connect lxc:/// start vm1
error: Failed to start domain vm1
error: internal error guest failed to start: PATH=/bin:/sbin TERM=linux container=lxc-libvirt container_uuid=1302678e-0447-79b7-6cc1-db4be64fdaf5 LIBVIRT_LXC_UUID=1302678e-0447-79b7-6cc1-db4be64fdaf5 LIBVIRT_LXC_NAME=vm1 /bin/bash
2013-05-16 14:33:49.930+0000: 1: info : libvirt version: 1.0.2
2013-05-16 14:33:49.930+0000: 1: error : lxcContainerMountCGroups:1893 : Failed to mount cgroup on '/sys/fs/cgroup': No such file or directory
2013-05-16 14:33:49.932+0000: 1866: info : libvirt version: 1.0.2
2013-05-16 14:33:49.932+0000: 1866: error : virLXCControllerRun:1462 : Unable to send container continue message: Broken pipe
2013-05-16 14:33:49.938+0000: 1866: error : virCommandWait:2287 : internal error Child process (ip link del veth1) unexpected exit status 1: Cannot find device "veth1"
并安装:
root@lxc:~# mount
/dev/xvda1 on / type ext3 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
cgroup on /sys/fs/cgroup type cgroup (rw)
如图所示,它已安装;但仍然无法启动。
拔掉我的头发;有什么想法吗?
答案1
我认为这与您的 rootfs 设置不正确有关。您在 XML 文件中的哪个位置挂载了 rootfs?我认为发生错误是因为“/bin/bash”文件本身不可见/未挂载。我在下面链接了我的一个容器的示例 DOM.XML 文件,该文件应该说明了 rootfs 的挂载情况。
文件名:originalcopy.xml
<domain type="lxc">
<name>originalcopy</name>
<vcpu placement="static">1</vcpu>
<cputune>
<shares>1024</shares>
<period>10005000</period>
</cputune>
<memtune>
<hard_limit unit="M">1024</hard_limit>
<soft_limit unit="M">128</soft_limit>
<min_guarantee unit="M">64</min_guarantee>
</memtune>
<blkiotune>
<weight>800</weight>
</blkiotune>
<memory unit="KiB">102400</memory>
<os>
<type>exe</type>
<init>/bin/lxc_defaultinit.sh</init>
</os>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/"/>
<target dir="/"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/sbin"/>
<target dir="/sbin"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/opt"/>
<target dir="/opt"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/selinux"/>
<target dir="/selinux"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/bin"/>
<target dir="/bin"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/lib"/>
<target dir="/lib"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/tmp"/>
<target dir="/tmp"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/mnt"/>
<target dir="/mnt"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/etc"/>
<target dir="/etc"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/usr"/>
<target dir="/usr"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/home"/>
<target dir="/home"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/var"/>
<target dir="/var"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/root"/>
<target dir="/root"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/dev"/>
<target dir="/dev"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/sys"/>
<target dir="/sys"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/media"/>
<target dir="/media"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/srv"/>
<target dir="/srv"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/boot"/>
<target dir="/boot"/>
</filesystem>
<filesystem accessmode="passthrough" type="mount">
<source dir="/containers/originalcopy/lib64"/>
<target dir="/lib64"/>
</filesystem>
<interface type="bridge">
<source bridge="br0"/>
</interface>
<console type="pty" port="0"/>
</devices>
</domain>
如您所见,我已经在文件系统标记中挂载了与容器相关的文件系统目录。您需要对 rootfs(根文件系统)执行相同操作。只需替换源目录以指向您机器中的特定路径即可。在我看来,这应该可以解决问题。如果您在创建 rootfs 时遇到任何困难,请告诉我。