【发布时间】:2018-07-24 18:24:22
【问题描述】:
我有一个本地构建的 qemu。我正在使用 libvirt python API 来定义 XML。我得到错误:
libvirt:错误:内部错误:子进程(LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /home/deepti/testqemu/bin/qemu-system-arm -help) 意外退出 状态 126:libvirt:错误:无法执行二进制 /home/deepti/testqemu/bin/qemu-system-arm:权限被拒绝 Traceback (最近一次通话最后):文件“testcustomQemu.py”,第 70 行,在 dom = conn.defineXML(xmlconfig) 文件“/home/deepti/.virtualenvs/testlibvirt/local/lib/python2.7/site-packages/libvirt.py”, 第 3685 行,在 defineXML 中 如果 ret 是 None:raise libvirtError('virDomainDefineXML() failed', conn=self) libvirt.libvirtError: internal error: Child process (LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /home/deepti/testqemu/bin/qemu-system-arm -help) 意外退出 状态 126:libvirt:错误:无法执行二进制 /home/deepti/testqemu/bin/qemu-system-arm: 权限被拒绝
/home/deepti/testqemu 的所有权是 root:root。将权限更改为+x 也不起作用。
我错过了什么。如何获取我的自定义 qemu?
我的脚本和xml如下:
import libvirt
import sys
xmlconfig = """<domain type='qemu' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>limom_instance</name>
<uuid>35615c44-b004-4b3f-9f42-da182b9662ef</uuid>
<memory unit='KiB'>786432</memory>
<currentMemory unit='KiB'>786432</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='armv7l' machine='limott'>hvm</type>
<kernel>/home/deepti/limom/FinalArtifacts/kerneldist1/zImage</kernel>
<dtb>/home/deepti/limom/FinalArtifacts/dtbdist1/emmc.dtb</dtb>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/home/deepti/testqemu/bin/qemu-system-arm</emulator>
<serial type='pty'>
<target port='0'/>
</serial>
<serial type='pty'>
<target port='1'/>
</serial>
<serial type='pty'>
<target port='2'/>
</serial>
<serial type='pty'>
<target port='3'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<memballoon model='none'/>
</devices>
<qemu:commandline>
<qemu:arg value='-sdl'/>
<qemu:arg value='-show-cursor'/>
<qemu:arg value='-nographic'/>
<qemu:arg value='-sd'/>
<qemu:arg value='/home/deepti/limom/FinalArtifacts/emmc.dat'/>
</qemu:commandline>
</domain>"""
conn = libvirt.open('qemu:///system')
if conn == None:
print('Failed to open connection to qemu:///system')
exit(1)
uri = conn.getURI()
print('Canonical URI: '+uri)
dom = conn.defineXML(xmlconfig)
if dom == None:
print('Failed to define a domain from an XML definition')
exit(1)
conn.close()
【问题讨论】:
-
重要的不仅仅是文件的权限,还有访问文件所在目录的权限。如果
/home/deepti不是o+x,那么除了你(或任何组中拥有所述目录的用户)之外,没有人可以通过它递归。/home/deepti/limom等也一样。 -
如果你是
root,最简单的测试方法是sudo -u qemu:qemu bash,然后实际尝试cd /home/deepti/testqemu/bin/和./qemu-system-arm --help等。如果cd失败,您就知道目录权限是问题所在。如果执行二进制文件失败,您需要查看它的权限 *以及它所依赖的库的权限; the output ofldd ./qemu-system-arm` 可能会有用。如果使用sudo以qemu(或libvirt或任何帐户名称)运行bash不会让您重现问题,那么是时候开始调查SELinux 配置了。