ILD

qemu share directory with host
作者:Yuan Jianpeng 邮箱:yuanjp89@163.com
发布时间:2026-2-2 站点:Inside Linux Development

使用qemu的9pfs,可以将一个host中的目录共享给qemu guest。


底层设备是:virtio-9p

传输协议是:9P network protocol。


开启的内核选项:

CONFIG_NET_9P

CONFIG_NET_9P_VIRTIO

CONFIG_9P_FS


启动qemu,添加:

-virtfs local,path=.,mount_tag=host0,security_model=none


在guest里面,安装模块,挂载9p文件系统:

modprobe 9p

modprobe 9pnet_virtio

 mount -t 9p -o trans=virtio host0 /mnt/host0


可以看到host里面的文件内容了:

# ls /mnt/host0/

Image              initramfs.cpio     mtd

disk0              initramfs.cpio.xz  run_qemu.sh


参考:

https://superuser.com/questions/628169/how-to-share-a-directory-with-the-host-without-networking-in-qemu


https://wiki.qemu.org/Documentation/9psetup


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.