用9P文件系统在宿主机与QEMU虚拟机之间共享文件
发布于 2025-11-08 13:55:05
步骤
- 在主机中建立需要共享的目录(如
/data/shared),并设置适当的权限
mkdir -p /data/shared
chmod 777 /data/shared
- 在QEMU启动脚本中增加如下两个选项
-fsdev local,security_model=passthrough,id=fsdev0,path=/data/shared
-device virtio-9p-pci,fsdev=fsdev0,mount_tag=host_shared
注:其中,对于
-device选项,也可以使用virtio-9p-device这种类型的设备。
-fsdev: Defines the "backend" – the properties of the filesystem on the hostside.
-device: Defines the "frontend" – the virtual device that is presented to the guest.
- 在QEMU的Linux系统中
# 新建挂载点
mkdir -p /mnt/shared
# 将共享目录挂载到挂载点
mount -t 9p -o trans=virtio,version=9p2000.L host_shared /mnt/shared
参考
更新于 2025-11-09 11:18:41