qemu中使用9p,支持host和guest中共享目录【转】

转自:https://blog.csdn.net/ayu_ag/article/details/52956351

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ayu_ag/article/details/52956351
9p是啥,网络文件系统,用于共享目录。当然,qemu中使用9p是用于host和guest中共享目录,也不需要网络的支持,而是需要virtio的支持。

qemu启动参数需要添加:

-fsdev local,security_model=passthrough,id=fsdev0,path=/tmp/share -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare


然后提示:
'virtio-9p-pci' is not a valid device model name


需要重新编译qemu,编译时添加额外的configure参数:
--enable-virtfs

编译安装qemu后,再运行,可以了。


在guest中挂载host共享的目录:

mkdir /tmp/host_files
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /tmp/host_files

提示:
mount: unknown filesystem type '9p'

需要在kernel中添加9p的支持:
CONFIG_NET_9P=y
CONFIG_NET_9P_VIRTIO=y
CONFIG_NET_9P_DEBUG=y (Optional)
CONFIG_9P_FS=y
CONFIG_9P_FS_POSIX_ACL=y


然后就可以使用了,如果再加上virtio console的支持,那么既有shell,又可以传输文件,基本可以代替adb的常用功能了。

参考:

qemu启动命令:http://www.linux-kvm.org/page/9p_virtio

kernel配置:http://wiki.qemu.org/Documentation/9psetup

qemu添加configure选项:https://groups.google.com/forum/#!topic/coreos-dev/MjhL3tOOAVM
---------------------
作者:ayu_ag
来源:CSDN
原文:https://blog.csdn.net/ayu_ag/article/details/52956351
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/sky-heaven/p/10107519.html