Ubuntu: Using file system passthrough with KVM guests



Question:

With a 16.04 hypervisor and 16.04 guest I would like direct access to my host filesystem from my guests. I have created the following element inside the section:

<filesystem type='mount' accessmode='passthrough'>    <source dir='/mnt/gsystem/fs'/>    <target dir='/mnt/fs'/>    <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>  </filesystem>  

After rebooting the guest, the PCI device at slot #3 shows up and I can see it as follows (I have edited out other PCI devices for clarity):

# lspci  ...  00:03.0 Unclassified device [0002]: Red Hat, Inc Virtio filesystem  ...  

But the file system isn't mounted and the target directory stays local to the guest.

Is there a next step to take or is thee a driver in my VM that I am missing?


Solution:1

You syntax is mostly used for LXC guest, KVM is a bit different. Update your XML like bellow:

<filesystem type='mount' accessmode='passthrough'>   <source dir='/mnt/gsystem/fs'/>   <target dir='mymount'/>  </filesystem>  

Start you guest and manually add modules to guest boot.

cat >>/etc/modules <<EOF  loop  virtio  9p  9pnet  9pnet_virtio  EOF  

Manually insert all those modules with

service kmod start  

And finally try to mount the shared folder

mount mymount /mnt/fs -t 9p -o trans=virtio  

If it's working, umount and add the following line into your /etc/fstab to make the mount persistant.

 mymount /mnt/fs            9p             trans=virtio    0       0  

Finally try to mount it again with

mount -a  

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »