新しい Ubuntu 20.04 ホスト (libvirtd (libvirt) 6.0.0) で新しい VM を使用していますが、AppArmor が VM ディスクへの読み取りアクセスを拒否しているため、起動に失敗しています。ディスクは次のように定義されます。
<disk type='volume' device='disk'>
<driver name='qemu' type='qcow2'/>
<source pool='default' volume='awesome.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/ubuntu-20.04.1-live-server-amd64.iso'/>
<target dev='hda' bus='sata'/>
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
VM の起動中に、次のメッセージで失敗します。
error: Failed to start domain playground
error: internal error: qemu unexpectedly closed the monitor: 2020-09-06T20:25:32.047663Z qemu-system-x86_64: -blockdev {"driver":"file","filename":"/var/lib/libvirt/images/awesome.qcow2","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}: Could not open '/var/lib/libvirt/images/awesome.qcow2': Permission denied
アクセス許可は正しいです。AppArmor を無効にして確認しました。また、カーネル ログに次のように出力されます。
[10757.098291] audit: type=1400 audit(1599423932.042:131): apparmor="DENIED" operation="open" profile="libvirt-b68582b8-0f35-4298-afd8-45c89ff3cbaa" name="/var/lib/libvirt/images/awesome.qcow2" pid=8654 comm="qemu-system-x86" requested_mask="r" denied_mask="r" fsuid=64055 ouid=64055
(VM の起動中に) によって生成されたプロファイルを見ると、次の内容が表示されvirt-aa-helper
ます。/etc/apparmor.d/libvirt/
# DO NOT EDIT THIS FILE DIRECTLY. IT IS MANAGED BY LIBVIRT.
"/var/log/libvirt/**/playground.log" w,
"/var/lib/libvirt/qemu/domain-playground/monitor.sock" rw,
"/var/lib/libvirt/qemu/domain-17-playground/*" rw,
"/run/libvirt/**/playground.pid" rwk,
"/run/libvirt/**/*.tunnelmigrate.dest.playground" rw,
"/var/lib/libvirt/images/ubuntu-20.04.1-live-server-amd64.iso" rk,
"/dev/vhost-net" rw,
"/var/lib/libvirt/qemu/domain-17-playground/{,**}" rwk,
"/var/lib/libvirt/qemu/channel/target/domain-17-playground/{,**}" rwk,
"/var/lib/libvirt/qemu/domain-17-playground/master-key.aes" rwk,
"/dev/net/tun" rwk,
ISO は正しく追加されていますが、何らかの理由でディスクのパスがありません。でデフォルト プールのパスを確認できます/etc/apparmor.d/usr.lib.libvirt.virt-aa-helper
。
[...]
@{HOME}/ r,
@{HOME}/** r,
/var/lib/libvirt/images/ r,
/var/lib/libvirt/images/** r,
# nova base images (LP: #907269)
/var/lib/nova/images/** r,
[...]
ボリューム内のディスク ファイルへのエントリがあるはずです。なぜvirt-aa-helper
追加しないのですか?