In the previous recipe, we saw two examples on how to attach disks to a running KVM instance. In this recipe, we are going to share a directory from the host OS and make it available in the virtual machine. We can only perform this action on a stopped instance however. If you've been following along, you should already have a libvirt KVM instance that you can use.
The prerequisites for this recipe are as follows:
- Stopped libvirt KVM instance with console access
- A guest OS with the
9p
andvirtio
kernel modules (available on most Linux distributions by default)
To share a directory from the host OS to the KVM guest, execute the following:
- Create a new directory on the host OS and add a file to it:
root@kvm:~# mkdir /tmp/shared root@kvm:~# touch /tmp/shared/file root@kvm:~#
- Add the following definition to the stopped KVM instance:
root@kvm:~# virsh edit kvm1 ... <devices> ... <filesystem type='mount...