9

I'd like to share a folder between a KVM guest and host. I want the data to be stored only on the host. What's the best solution for that?

thanks mat

mat3001
  • 305
  • 2
  • 3
  • 8

4 Answers4

8

Here's a 9p virtio example from the official wiki. (Further reading.)

The virt-manager GUI virtual machine editor calls it "filesystem passthrough".

ignis
  • 411
  • 3
  • 4
7

You could do this by treating host and guest as completely separate computers. Make the shared folder available on the host, e.g. by exporting it through NFS or by creating a samba share. Then connect to it from the guest just in the normal manner.

Since the guest has its own IP address, this should not present any problems. With NFS you can also easily limit the exported share to only accept connections from the guest (if that is what you want). All the other rules about NFS shares and samba shares still apply.

If either guest or host are Windows machines, then you are probably better of with a samba share.

wolfgangsz
  • 8,767
  • 3
  • 29
  • 34
  • 1
    @aleroot provided an important pointer with his question. In order for this to work properly, you have to use bridged networking. – wolfgangsz Sep 05 '10 at 10:34
  • I like this option, but I'm having problems with `ksoftirqd/0`, in debian. Similar to what I see here. https://bugzilla.redhat.com/show_bug.cgi?id=870573 I wonder if a shared disk of some kind, or 9pvirto is better to minimize load. – isaaclw Jan 29 '14 at 01:17
  • 1
    be aware that at least in my experiance samba comes with broken defaults for this usecase. You need to either turn off "oplocks" completely or enable "kernel oplocks" for things to work properly. – Peter Green Apr 09 '18 at 17:06
5

I usually use sshfs to mount a [folder on the host machine] on the VM guest, e.g.:

sshfs magnus@10.42.43.1:/home/magnus/development /path/to/dev/dir/on/guest

Were 10.42.43.1 is the gateway and VM host. -- This works also with NAT (need not be a bridged networking setup).

(And I suppose Samba or NFS are better to use once you have them set up, since you need run no more commands, no sshfs ....)

KajMagnus
  • 375
  • 1
  • 4
  • 14
0

With NAT you may be able to get back to the host via the NAT gateway IP.

user48838
  • 7,393
  • 2
  • 17
  • 14