Example Sharing Host files with the Guest — 9p — qemu-kvm
2016-07-07 21:39
459 查看
http://www.linux-kvm.org/page/9p_virtio
In both cases we'll share files in /tmp/share on the host. In the guest, they'll show up in /tmp/host_files.
QEMU wiki describing this, so this section will be quite short. To share host files w/ the guest, we use 9p over virtio in conjunction w/ a filesystem device exporting the portion of the host filesystem that we'd like to share with the guest.
This tells qemu to create a 9pvirtio device exposing the mount_tag
QEMU wiki for details on the security models).
Now, in the guest we need to mount the 9p filesystem from the host using the virtio transport. The mount_tag is used to identify the host's share.
That's it...now we can read/write files in that directory from either the host or the guest.
Start virt-manager, and open your VM by double clicking on it. Click the virtual hardware details (lightbulb). Click Add Hardware, and choose a Filesystem. Chose the mode, we chose squash which translates to none (see
QEMU wiki for details on the security models), the source (we are sharing /tmp/share), and the target (we called this /hostshare).
Now, start the VM. In the guest we need to mount the 9p filesystem from the host using the virtio transport. The mount_tag is used to identify the host's share.
That's it...now we can read/write files in that directory from either the host or the guest. (Note: likely to hit some issues w/ privileges since Fedora libvirt runs guests unprivileged and with SELinux confinement...careful use of chown, chmod and chcon
should get it working).
Example Sharing Host files with the Guest
This example is based on qemu-kvm (0.15.0) as installed in Fedora 15.Will first show how to do this manually, and second how to do it using the virt-manager tool. This HOWTO is documenting 9p virtio as the transport for sharing files.In both cases we'll share files in /tmp/share on the host. In the guest, they'll show up in /tmp/host_files.
Manually, using qemu-kvm command line
There are a nice set of details on theQEMU wiki describing this, so this section will be quite short. To share host files w/ the guest, we use 9p over virtio in conjunction w/ a filesystem device exporting the portion of the host filesystem that we'd like to share with the guest.
# /usr/bin/qemu-kvm -m 1024 -name f15 -drive file=/images/f15.img,if=virtio -fsdev local,security_model=passthrough,id=fsdev0,path=/tmp/share -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare
This tells qemu to create a 9pvirtio device exposing the mount_tag
hostshare(just a name to identify the mount point). That device is coupled to an fsdev named
fsdev0, which specifies which portion of the host filesystem we are sharing, and in which mode (see
QEMU wiki for details on the security models).
Now, in the guest we need to mount the 9p filesystem from the host using the virtio transport. The mount_tag is used to identify the host's share.
# mkdir /tmp/host_files # mount -t 9p -o trans=virtio,version=9p2000.L hostshare /tmp/host_files
That's it...now we can read/write files in that directory from either the host or the guest.
Managed, using virt-manager
This assumes you've already installed a guest with virt-manager or virt-install and it's shut off.Start virt-manager, and open your VM by double clicking on it. Click the virtual hardware details (lightbulb). Click Add Hardware, and choose a Filesystem. Chose the mode, we chose squash which translates to none (see
QEMU wiki for details on the security models), the source (we are sharing /tmp/share), and the target (we called this /hostshare).
Now, start the VM. In the guest we need to mount the 9p filesystem from the host using the virtio transport. The mount_tag is used to identify the host's share.
# mkdir /tmp/host_files # mount -t 9p -o trans=virtio,version=9p2000.L /hostshare /tmp/host_files
That's it...now we can read/write files in that directory from either the host or the guest. (Note: likely to hit some issues w/ privileges since Fedora libvirt runs guests unprivileged and with SELinux confinement...careful use of chown, chmod and chcon
should get it working).
相关文章推荐
- 一步一步学Qt(QtQuick)/qml开发第六篇
- Codeforces Round #361 (Div. 2) D Friends and Subsequences
- Codeforces Round #361 (Div. 2)D. Friends and Subsequences
- java基础学习总结——GUI编程(一)
- java基础学习总结——GUI编程(二)
- How to Build RecastNavigation with VC2015
- Reac Native-UI组件的封装
- query相关搜索词&推荐
- iOS全新的联系人与联系人UI框架
- Codeforces Round #361 (Div. 2) D. Friends and Subsequences 二分
- [Android]android stuido优化启动/编译/运行速度
- Codeforces Round #361 (Div. 2) D. Friends and Subsequences
- query纠错
- Unique Characters of a String
- Android界面编程——Android高级UI组件(三)
- iOS SDWebImage 淡入 UITableViewCell
- UIButton 的图文混排
- UIBezierPath画图
- Segue 类型介绍
- UnderStand Perspective Rasterization, SV_POSITION(gl_FragCoord) to Pixel, SV mean Systems Value