In KVM virtualization you can share a filesystem directory from the host to the guest via 9p-virtio.
Since it’s not trivial to get working I’m going to share the few steps that you need to take.
- In virt-manager open the virtual machine that you want to access a directory.
- Click “Add hardware”
- If your guest machine is running while you are adding it you will have to shut down the guest before it works. (not restart! – the VM process has to be closed)
- You will likely hit the Read-only permissions problem (look at trouble shooting below)
- In your guest: test that it works (as root):
mount -t 9p -o trans=virtio,version=9p2000.L /commonshare /mnt/test
- In the unlikely event that you have character set problems, look in trouble shooting below.
- unmount it again after verifying:
- Making it permanent in /etc/fstab
/commonshare /mnt/commonshare 9p trans=virtio,version=9p2000.L,access=any 0 0
I have one problem (for my setup) that I’ve not solved yet: mounting the files with a given users file permissions UID/GID (hopefully to be solved soon, I’ve asked on the 9p-users list) such that my guest webserver can get write permissions without changing the permissions on the host. If you have a solution, please post it in the comments.
- Permisions: I had read-only access at first, make sure that the user running the qemu process (KVM, look in htop, “libvirt-qemu” i my case) has RW access to the files shared – e.g. by adding the user to the group who owns the files (/etc/group). Then shut down your VM and start it again (not restart – a restart will not give the qemu process the new group membership ).
- Character set: I had a problem with non-ascii characters looked wrong, e.g. “bøger” looked like “b??ger”. That was because my Guest machine was not properly configured with the locale (which I had noticed but ignored during dist-upgrade “Can’t set locale; make sure $LC_* and $LANG are correct!”). I solved it by running “dpkg-reconfigure locales” and selecting the right locale – don’t remember exactly what I selected.
- Ubuntu 13.10 or below: you will likely hit AppArmor problems: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/943680
- Which users should have access on guest VM: see slide 26 on http://www.slideshare.net/ericvh/9p-overview
- basic steps guide: http://www.linux-kvm.org/page/9p_virtio
- 9p options: http://wiki.qemu.org/Documentation/9psetup
- Documentation why a shared directory is better than a network mount: https://www.kernel.org/doc/ols/2010/ols2010-pages-109-120.pdf
For references my setup consists of:
- host: ubuntu 14.04 with KVM and libvirt
- guest: debian 7.8
- I control it with virt-manager which I run from my kubuntu desktop.