Table of Contents

About

Plan 9 can be used to mount a host folder inside a virtual machine using libvirt, however there are very few solutions to mount the entire guest filesystem on the host machine. Scenarios could potentially include batch-editing configuration files.

In order to accomplish the former plain old NFSv3 can be used alongside autofs. The result will be that all guest virtual machines will be mapped by hostname under a subdirectory on the host machine that can be then used conventionally on the command line in order to access the guest filesystem.

Requirements

The setup requires both the server and client component to be configured - the guests will act as NFS servers and the client will be the host.

Host / Server

Under Debian, the required packages for the host are the following:

that can be installed by issuing:

aptitude install autofs nfs-common

Guest / Server

The client machine requires the nfs-server package to be installed:

aptitude install nfs-server

The rest of the tutorial assumes that each guest virtual machine has at least a locally accessible hostname (or IP address).

Setting Up the NFS Server Inside the Guest Machine

In order to configure the NFS server, edit /etc/exports and append the line:

/    HOST(rw,sync,no_subtree_check,no_root_squash)

where:

and then issue:

exportfs -arv

which should indicate that the entire root filesystem has been exported to the specified hostname.

Setting Up AutoFS on the Host Machine

Under Debian, with the autofs package installed, create a file at /etc/auto.master.d/nfs.autofs with the following contents:

/media/nfs  /etc/auto.net --timeout=300 --ghost

where:

With the configuration in place, restart autofs with:

/etc/init.d/autofs restart

Testing

With the guest NFS export and AutoFS configured on the host, the guest filesystem can be mounted just by accessing the path:

/media/nfs/HOST

where:

For instance, issuing:

vi /media/nfs/machine.home/etc/issue

will open the file /etc/issue on the guest machine.

Security

Well, with no_root_squash, the entire guest filesystem will be exported under the designated mount point (in this case, /media/nfs/HOST) such that any user on the host will have read-write access to the entire guest filesystem. Perhaps the best options is to use NFSv4 and OpenLDAP to map users instead of using the no_root_squash option.

Using OpenLDAP to Map Users

NFS can be configured to use UID and GID to map users, respectively groups such that exported filesystems will be modifiable by the local users in case they are the same. This allows for a secure and more fluent administration where additional and superfluous users do not have to be created on every machine to be configured.

To use OpenLDAP, the host machine will have to be configured to host an LDAP server which can be done by following the OpenLDAP tutorial.

Once the OpenLDAP server is configured on the host and the guest is configured to allow authentication of LDAP users (make sure to check that LDAP users are able to log in), NFS can be configured to use LDAP to map users.

Edit /etc/idmapd.conf and instruct NFS to use nsswitch to map users by adding the following lines:

[Translation]

Method = nsswitch

The configuration will make NFS query the methods detailed in /etc/nsswitch.conf to authenticate and map users - which was one of the points of the OpenLDAP tutorial.