How to share folder between host and guest VM

Today, I had to quickly share some files between my guest VM and host OS1 to troubleshoot a problem1. Because I’m using the virt-manager GUI, the instructions on these pages were enough to accomplish the task.

I’m documenting steps2 here for future self who definitely will have forgotten all this:

1) Create 9pvirtio filesystem device in VM configuration

Option A: qemu-kvm CLI

I didn’t use this option. See 9p virtio doc for more details.

Option B: virt-manager GUI

  1. Open virt-manager.
  2. Click Add Hardware.
  3. Choose Filesystem.
  4. Set option values:
ModeSquashSee qemu wiki for more values and details.
Source path/share/folderPath to share folder on host.
Target path/host_shareNot an actual fs “path”, simply a name to identify mountpoint.
  1. Confirm and Apply Settings.

2) Mount 9p host filesystem in VM

  1. Start up VM.
  2. Make share folder and mount the filesystem from the host:
mkdir /tmp/share
mount -t 9p -o trans=virtio,version=9p2000.L /host_share /tmp/share

And that’s it. Now we can start reading/writing3 files between guest and host in /tmp/share.

  1. I couldn’t execute a binary in nixOS; probably will document learnings from that experience in a future post. ↩︎

  2. Steps assume both guest and host OS are linux-based. ↩︎

  3. Might need to chown and sudo files in the folder.* ↩︎