如何解决 libvirt 中 qemu:commandline 的“权限被拒绝”错误?

Dee*_*pti 5 json libvirt virsh

请在下面找到我的 dom xml 示例。我正在运行命令 virsh create 并收到此错误:

Unable to open file <json file located inside install_dir>
Run Code Online (Sandbox Code Playgroud)

这个文件的权限都很好。

标签下的参数是否需要特殊权限qemu:commandline?无论我在本节中提到什么参数和文件,我都会收到错误。

 <domain type='qemu' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>my_instance</name>
  <uuid>35615c44-b004-4b3f-9f42-da182b9662ee</uuid>
  <memory unit='KiB'>786432</memory>
  <currentMemory unit='KiB'>786432</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='armv7l' machine='my_machine'>hvm</type>
    <kernel>/home/user/KernelPath/zImage</kernel>
    <dtb>/home/user/DTPPath/emmc.dtb</dtb>
  </os>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/qemu-system-arm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/home/user/Install_Dir/emmc.dat'/>
      <target dev='sd' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='usb' index='0'/>
    <controller type='scsi' index='0'/>
    <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>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='60316' autoport='no' websocket='60381' listen=''>
      <listen type='address' address=''/>
    </graphics>
    <graphics type='sdl'/>
    <video>
      <model type='qxl'/>
    </video>
    <memballoon model='none'/>
  </devices>
  <qemu:commandline>
    <qemu:arg value='-spdir'/>
    <qemu:arg value='/home/user/Install_Dir'/>
    <qemu:arg value='-show-cursor'/>
  </qemu:commandline>
</domain>
Run Code Online (Sandbox Code Playgroud)

小智 2

Libvirt 将尝试使用专用用户帐户(通常是qemu:qemu用户/组对)来运行来宾,并应用SELinux 或 AppArmor 规则来限制它。通常,libvirt 会自动设置文件所有权并将 SELinux/AppArmor 策略设置为“正常工作”。qemu 命令行直通对于 libvirt 来说是一个黑盒,因此它不知道它需要与您的/home/user/Install_Dir路径相关的内容。如果您的用户/组所有权正确,则可能是 SELinux/AppArmor 策略拒绝访问。唯一可行的解​​决方法是禁用它们(通过/etc/libvirt/qemu.conf),并接受较低的安全保护