Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lee-pai-long/9656e35d39a8844331e3001e6b57eb00 to your computer and use it in GitHub Desktop.
Save lee-pai-long/9656e35d39a8844331e3001e6b57eb00 to your computer and use it in GitHub Desktop.

[LIBVIRT] Share directory with guest

Edit domain xml:

$ [sudo] virsh edit <mydomain>

And add a tag inside the one, like this:

<devices>
    <filesystem type='mount' accessmode='mapped'>
      <source dir='/host/source/direrectory'/>
      <target dir='mountlabel'/>
    </filesystem>
</devices>

According to the libvirt documentation, accessmode can be:

  • mapped: to have files created and accessed as the user running kvm/qemu. Uses extended attributes to store the original user credentials.
  • passthrough: to have files created and accessed as the user within kvm/qemu.
  • squash: like passthrough, except failures in privileged operations are ignored.

Then start the VM, and edit /etc/modules and add the following:

virtio
9p
9pnet
9pnet_virtio

Now edit /etc/fstab and add the following:

mountlabel          /guest/destination/directory        9p      trans=virtio        0      0

The directory /guest/destination/directory must exist for the mount to work

Finally you will need to shutdown and restart the domain:

$ [sudo] virsh shutdown <mydomain> \
>   && [sudo] virsh start <mydomain>

A simple virsh reboot doesn't seems to work, I don't really know why, probably cache kinda problem of something

source: http://rabexc.org/posts/p9-setup-in-libvirt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment