编译自源码的QEMU提示virtio-9p-pci非有效设备模型名问题求助
The Problem
I'm trying to launch a Debian-based VM using a custom-compiled QEMU from the harddoom branch with this command:
qemu-system-x86_64 \ -drive file=zso_cow.img,if=virtio \ -enable-kvm \ -smp 2 \ -net nic,model=virtio -net user \ -m 1G -balloon virtio \ -fsdev local,id=hshare,path=hshare/,security_model=none -device virtio-9p-pci,fsdev=hshare,mount_tag=hshare \ -chardev stdio,id=cons,signal=off -device virtio-serial-pci -device virtconsole,chardev=cons \ -device harddoom
The VM image zso_cow.img was created with:
qemu-img create -f qcow2 -o backing_file=zso.img zso_cow.img
But I hit this error:
qemu-system-x86_64: -device virtio-9p-pci,fsdev=hshare,mount_tag=hshare: 'virtio-9p-pci' is not a valid device model name
Ubuntu's repo-installed QEMU runs this command fine, but I need to use the harddoom-compiled version. Removing the virtio-9p-pci device breaks my shared folder setup.
My configure flags for compiling QEMU were:
--target-list=i386-softmmu,x86_64-softmmu --python=$(which python2) --audio-drv-list=alsa,pa
The Solution
1. Recompile QEMU with VirtFS Enabled
The root issue is that your custom build didn't include support for the 9p virtio filesystem device. You need to explicitly enable this feature during configuration:
- Clean your existing build (optional but recommended):
make clean - Re-run the configure script with the
--enable-virtfsflag:./configure --target-list=i386-softmmu,x86_64-softmmu --python=$(which python2) --audio-drv-list=alsa,pa --enable-virtfs - Recompile and install:
make -j$(nproc) # Use all CPU cores for faster build sudo make install
2. Verify the Device is Now Available
After recompiling, check if virtio-9p-pci is listed in QEMU's supported devices:
qemu-system-x86_64 -device help | grep virtio-9p
If you see virtio-9p-pci in the output, your build now includes the necessary support.
3. Fallback: Try the Legacy Device Name
If for some reason --enable-virtfs doesn't add virtio-9p-pci, you can try the older device name virtio-9p-device as a replacement in your launch command:
-fsdev local,id=hshare,path=hshare/,security_model=none -device virtio-9p-device,fsdev=hshare,mount_tag=hshare
This is less ideal, but works with some older QEMU configurations.
Why This Works
Ubuntu's pre-built QEMU packages include VirtFS support by default, but when compiling from source, you have to enable it explicitly. The --enable-virtfs flag tells the build system to include the 9p virtio device drivers, which adds the virtio-9p-pci device you need for shared folders.
内容的提问来源于stack exchange,提问作者Michał Piotr Stankiewicz




