Gnome-boxes: communication between guest and host

Mounting host filesystems

Mounting a Remote Directory with SSHFS:

sshfs needs to be installed in both the host and guest systems.
In Debian based systems install with

sudo apt-get install sshfs

Using sshfs:

  • create a local mount point in the VM

mkdir ~/fusessh

  • mount a remote directory from your host

sshfs username@host_ip_address:/remote_directory /local_mount_point

Of course replace username, host_ip_address, /remote_directory, and /local_mount_point with the appropriate values again.

Username can be omitted if it is the same in both guest and host.

example:

arch@archlinux ~> sshfs rosika@192.168.8.102:/home/rosika/Videos/  ~/fusessh
rosika@192.168.8.102's password:
arch@archlinux ~>

Now you can see in the VM´s file manager (e.g. thunar) that fusessh is mounted and have a look at its contents.
Also:

arch@archlinux ~> ll /home/arch/fusessh/
total 12K
drwxrwxr-x 1 arch arch 4.0K Feb 28 18:17 kgw/
-rw-rw-r-- 1 arch arch    6 May  8  2023 test4.txt
drwxr-xr-x 1 arch arch 4.0K Aug 27  2023 vlc_logs/

Unmounting can be done with:

arch@archlinux ~> fusermount3 -u ~/fusessh

Making an NFS mount of a host filesystem

1 . In the host system install the following packages

nfs-kernel-server
nfs-common
libnfs13
libnfsidmap1

Those are Debian package names
and
make sure the daemons nfsd, rpc.mountd, rpcbind, rpc.idmapd, and rpc.statd are running

2 . In the host system edit the file /etc/exports and add a line

/common *(ro,sync,no_subtree_check,no_root_squash,insecure)

of course, replace my /common with the directory you wish to export.
This exports to all hosts, the * is a wildcard for hostname.
It can be ro or rw.

Then follow this with
exportfs -a
and check the setup with
showmount -e

3 . In the guest system install the following

nfs-common
libnfsidmap1

Those are Debian package names,
and make sure the daemons rpcbind, rpc.idmapd, and rpc.statd are running
You can check that the guest can see the exported filesystem
with

showmount -e trinity

in the guest. It should report the same exported filesystems
as it does in the host.

4 . Configure the /etc/hosts file in host and guest.
This is non-essential, but it allows use of hostname.
Add the hostname and IP number of host and guest to each hosts file.

5 . Make a mount point in the guest
mkdir /mnt/hostcommon
subsitiute you own mount name

6 . Do the mount
mount -t nfs trinity:/common /mnt/hostcommon
that is using the hostname trinity
or
mount -t nfs 192.168.32.6:/common /mnt/hostcommon
that is using the host’s IP number. It can be a static IP number or the DHCP port used
for internet connection.
or
mount -t nfs 10.0.2.2:/common /mnt/hostcommon
that is using the gnome-boxes gateway IP number

7 . Check the mount is present using df

# df
Filesystem       1K-blocks      Used Available Use% Mounted on
....
trinity:/common 1116210176 108697600 950785024  11% /mnt/hostcommon

Permanent mounts

If you require an nfs mount every time you start the guest VM,
put the following in /etc/fstab in the guest system

192.168.32.6:/common /mnt/common nfs rw,hard 0 0

of course substitute your IP number or hostname and your filename and mount point.

Some points to consider

  • NFS works over a NAT connection. There is no need for a bridge to use NFS.
  • Not sure why it was necessary to use ‘*’ in /etc/exports in the host.
    I tried a specific IP address ( 10.0.2.15 ) and it gives the message
mount.nfs: access denied by server while mounting trinity:/common

I think that is because 10.0.2.15 is behind NAT… although NFS works over NAT, exportfs
seems not to work?
Theoretically one should only need to export a filesystem to a specific guest,
not to everyone, which is what ‘*’ implies.

  • There is no setting in the gnome-boxes preferences menu which helps with this.
    It has to be setup from the CLI outside of gnome-boxes.
  • Because of the amount of trial and error involved in working out how to do this,
    there may be other requirements which have been overlooked in the writeup, particularly
    for non-Debian-based distros in host or guest. Please advise if you discover extra
    requirements.
  • If you have problems with the mount try

mount -t nfs -vvvv trinity:/common /mnt/hostcommon

to get more information.

  • In some guests the routing table is not correct. For example in a Devuan5 guest I
    had no default route. After consulting what Antix had in its routing table, I made the following
    modificatiuons in Devuan5
ip route add default via 10.0.2.2 dev eth0
ip route add 10.0.2.2 dev eth0 scopr link

Antix used 10.0.2.2, the gateway to the host in gnome-boxes’ virtual network.
I can now do the nfs mount in a Devuan5 guest.
Its route table looks a follows

$ ip r
default via 10.0.2.2 dev eth0 
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100 
10.0.2.0/24 via 10.0.2.0 dev eth0 proto static metric 100 
10.0.2.2 dev eth0 scope link 
169.254.0.0/16 dev eth0 scope link metric 1000 

Using the gnome-boxers shared file facility

There is , under Preferences in the gnome-boxes menu of a running guest, an
option to define a ‘Folder’ (ie a directory) that is to be shared between guest and host.
Unfortunately we were unable to get this to work. There is a reference

and one of the requirements it mentions is the package spice-webdavd.
That package seems to be only available under Debian, and when we used it
in a Debian guest, it did not function.

So while a GUI method of sharing a ‘Folder’ exists in gnome-boxes, the fact that it does not function means that one has to make mounts at the CLI using either sshfs or nfs.
Both CLI methods are , however , more flexible, you can make multiple mounts, and, in the case of ‘nfs’ you can make the mount happen at every boot by including it in /etc/fstab.