Libvirt
使用 libvirt 和 QEMU 的 9p 根文件系統
我正在嘗試使用 libvirt 啟動具有 9p 根文件系統的 Linux VM。當使用以下命令直接呼叫 QEMU 時,這非常有效:
qemu-system-x86_64 -enable-kvm \ -kernel /vmroot/trusty/boot/vmlinuz-3.13.0-24-generic \ -initrd /vmroot/trusty/boot/initrd.img-3.13.0-24-generic \ -fsdev local,id=root9p,path=/vmroot/trusty,security_model=mapped \ -device virtio-9p-pci,fsdev=root9p,mount_tag=root9p \ -nographic \ -append 'root=root9p rw rootfstype=9p rootflags=trans=virtio console=ttyS0'
現在,我試圖通過使用 XML 配置的 libvirt 獲得相同的效果。我的 XML 配置如下:
<?xml version="1.0"?> <domain type='kvm'> <name>trusty</name> <uuid>618237b9-2f17-4dfc-ba46-dec508d31e4e</uuid> <os> <type>hvm</type> <kernel>/vmroot/trusty/boot/vmlinuz-3.13.0-45-generic</kernel> <initrd>/vmroot/trusty/boot/initrd.img-3.13.0-45-generic</initrd> <cmdline>root=root9p rw rootfstype=9p rootflags=trans=virtio console=ttyS0</cmdline> </os> <vcpu>2</vcpu> <memory unit='KiB'>524288</memory> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <features> <pae/> <acpi/> <hap/> </features> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> <serial type='pty'> <target port='0'/> </serial> </devices> <filesystem type='mount' accessmode='mapped'> <source dir='/vmroot/trusty'/> <target dir='root9p'/> </filesystem> </domain>
現在,從 XML 生成的本機 QEMU 命令行不包含啟用此功能的必要選項。生成的命令行是:
qemu-system-x86_64 -name trusty -machine pc,accel=kvm,usb=off -m 512 \ -realtime mlock=off -smp 2,sockets=2,cores=1,threads=1 \ -uuid 618237b9-2f17-4dfc-ba46-dec508d31e4e -nographic -no-user-config \ -nodefaults -chardev socket,id=charmonitor,path=/home/user/.config/libvirt/qemu/lib/trusty.monitor,server,nowait \ -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc \ -no-shutdown -boot strict=on \ -kernel /vmroot/trusty/boot/vmlinuz-3.13.0-45-generic \ -initrd /vmroot/trusty/boot/initrd.img-3.13.0-45-generic \ -append 'root=root9p rw rootfstype=9p rootflags=trans=virtio console=ttyS0' \ -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ -chardev pty,id=charserial0 \ -device isa-serial,chardev=charserial0,id=serial0 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \ -msg timestamp=on
那麼,我怎樣才能讓 libvirt 包含
-fsdev
和附加-device
選項?
找到了解決方案。簡單的配置錯誤。
<filesystem>
元素需要在元素內部<devices>
,因此 XML 變為:<?xml version="1.0"?> <domain type='kvm'> <name>trusty</name> <uuid>618237b9-2f17-4dfc-ba46-dec508d31e4e</uuid> <os> <type>hvm</type> <kernel>/vmroot/trusty/boot/vmlinuz-3.13.0-45-generic</kernel> <initrd>/vmroot/trusty/boot/initrd.img-3.13.0-45-generic</initrd> <cmdline>root=root9p rw rootfstype=9p rootflags=trans=virtio console=ttyS0</cmdline> </os> <vcpu>2</vcpu> <memory unit='KiB'>524288</memory> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <features> <pae/> <acpi/> <hap/> </features> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> <serial type='pty'> <target port='0'/> </serial> <filesystem type='mount' accessmode='mapped'> <source dir='/vmroot/trusty'/> <target dir='root9p'/> </filesystem> </devices> </domain>