使用 libvirt 和 QEMU 的 9p 根文件系统

使用 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选项?

答案1

找到解决方案了。简单的配置错误。<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>

相关内容