You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义Qemu通过Libvirt运行时Permission Denied问题求助

解决Libvirt运行自定义Qemu的权限拒绝问题

1. 检查二进制文件及目录的基础权限

先排除最基础的文件权限问题:

  • 给自定义Qemu二进制添加可执行权限:
    chmod +x /home/shiyue/USWAP/uswap-dev/build/br2-uswap-vm/target/usr/bin/qemu-system-x86_64
    
  • 确保路径中每一层目录都有执行权限(让libvirt-qemu用户能遍历到目标文件):
    chmod o+x /home/shiyue/
    chmod o+x /home/shiyue/USWAP/
    chmod o+x /home/shiyue/USWAP/uswap-dev/
    chmod o+x /home/shiyue/USWAP/uswap-dev/build/
    chmod o+x /home/shiyue/USWAP/uswap-dev/build/br2-uswap-vm/
    chmod o+x /home/shiyue/USWAP/uswap-dev/build/br2-uswap-vm/target/
    chmod o+x /home/shiyue/USWAP/uswap-dev/build/br2-uswap-vm/target/usr/
    chmod o+x /home/shiyue/USWAP/uswap-dev/build/br2-uswap-vm/target/usr/bin/
    
  • 测试libvirt-qemu用户能否执行该二进制:
    sudo -u libvirt-qemu /home/shiyue/USWAP/uswap-dev/build/br2-uswap-vm/target/usr/bin/qemu-system-x86_64 --version
    
    如果这个命令报错,说明是文件/目录权限问题,优先解决此问题。

2. 修复AppArmor配置

仅停止AppArmor服务可能仍有残留规则生效,需正确配置:

  • 找到对应VM的AppArmor配置文件,通常位于/etc/apparmor.d/libvirt/libvirt-<UUID>,UUID可通过virsh list --all查看VM的UUID值
  • 在配置文件中添加允许执行自定义Qemu的规则:
    /home/shiyue/USWAP/uswap-dev/build/br2-uswap-vm/target/usr/bin/qemu-system-x86_64 rmix,
    
  • 重新加载AppArmor规则:
    sudo apparmor_parser -r /etc/apparmor.d/libvirt/libvirt-<UUID>
    
  • 或临时将libvirtd的profile设为complain模式(仅用于测试):
    sudo aa-complain /etc/apparmor.d/usr.sbin.libvirtd
    

3. 调整Libvirt XML配置

  • 如果XML中是通过shell脚本调用Qemu,先尝试直接指定Qemu二进制路径,排除脚本权限问题:
    将XML中类似<emulator>/path/to/script.sh</emulator>改为<emulator>/home/shiyue/USWAP/uswap-dev/build/br2-uswap-vm/target/usr/bin/qemu-system-x86_64</emulator>
  • 修改XML后重新定义VM:
    virsh define /path/to/your/vm.xml
    

4. 彻底禁用AppArmor(仅临时测试)

若以上步骤均无效,可尝试彻底禁用AppArmor:

sudo systemctl stop apparmor
sudo systemctl disable apparmor
sudo rmmod apparmor

重启系统后AppArmor不会自动加载,再测试VM运行情况。


内容的提问来源于stack exchange,提问作者Shiyue Chen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 15:13:10