Way (non network-based) to share host (ubuntu) file system with guest (centos 7) using libvirt

centos7filesystemskvm-virtualizationlibvirtqemu

I am trying to use virsh and domain xml to launch a Centos 7 guest from ubuntu 16.04 LTS host. The "filesystem" node that i am using in domain xml is as below:

<filesystem type='mount' accessmode='passthrough'>
    <driver type='path' wrpolicy='immediate'/>
     <source dir='/opt/test'/>
     <target dir='testlabel'/>
</filesystem>

With the above config, "testlabel" is not visible in the guest and hence i am not able to mount it. Is there anything that i am missing?

I tried to have 9p modules in guest but they don't seem to be available in centos 7 readily. Needs kernel re-compilation [trying it now].
I learnt that virtio-vsock is going to be available in the future. So, it is not an option for now.

I do not want to use network based file sharing like SSHFS, NFS or glusterfs either.

Is there any other filesystem driver that can work with the "filesystem" option of domain xml with libvirt?

Best Answer

According to the libvirt documentation, you might simply need to adjust your target.

The docs provide the following examples:

  <filesystem type='mount' accessmode='passthrough'>
    <driver type='path' wrpolicy='immediate'/>
    <source dir='/export/to/guest'/>
    <target dir='/import/from/host'/>
    <readonly/>
  </filesystem>
  <filesystem type='file' accessmode='passthrough'>
    <driver name='loop' type='raw'/>
    <driver type='path' wrpolicy='immediate'/>
    <source file='/export/to/guest.img'/>
    <target dir='/import/from/host'/>
    <readonly/>
  </filesystem>

That seems to work without the need for 9p.

However, for centos, there is in fact a readily available 9p helper:

Available Packages
Name        : nfs-ganesha-mount-9P
Arch        : x86_64
Version     : 2.3.2
Release     : 1.el7
Size        : 11 k
Repo        : epel/x86_64
Summary     : a 9p mount helper
URL         : https://github.com/nfs-ganesha/nfs-ganesha/wiki
Licence     : LGPLv3+
Description : This package contains the mount.9P script that clients can use
            : to simplify mounting to NFS-GANESHA. This is a 9p mount helper.