Share Single Portage Instance Across Machines with NFS
This post documents the steps I took to share the Portage instance one Gentoo machine across the other Gentoo machines I have using NFSv4. One machine syncs portage, all the other machines benefit. For purposes of this post, server will refer to the machine which holds and automatically sync portage for the local network, and client will refer to all of the other local Gentoo machines which will look to the server for Portage.
Portage Directory Settings
In order for this to work, the following settings will be made consistent across machines by setting in each Gentoo machines /etc/portage/make.conf file. Any older settings to the contrary need to be replaced or commented out. These are the directories the server will share via NFS to the other machines.
Portage Server Setup
NFS will be the sharing mechanism I use to make Portage available over the network, so the first step will be to get it up and running on the server.
Enable NFS in Kernel on Server Hosting Portage
These are the kernel configuration settings I went with for the server. I am enabling NFS version 3 and $ support for both client and server. Only the server settings are needed on this machine to share Portage, but I will eventually be using this machine as an NFS client in the future, adding support to the kernel now. Settings below are for kernel 5.10.15.
Make kernel configuration changes needed to enable NFS server functions.
Recompile kernel to apply the configuration changes.
Update boot loader with new kernel.
Reboot machine to load kernel.
Details on updating kernel on Gentoo can be found on the Gentoo Wiki
The following steps should be were done after the server was rebooted using a kernel with NFS version 4 support.
Set Up Portage Export Using NFSv4
Install net-fs/nfs-utils package to make NFS client and server daemons available.
Create the directory structure to be used for exports from the server. In this cae, /export/gentoo, /export/distfiles, and /export/binpkgs is what NFS clients will mount form the server.
Bind actual directory I want to share to export mount point, in this case /var/db/repos/gentoo, /var/cache/distfiles, and /var/cache/binpkgs are what I will be sharing from the server.
Make the export mount happen automatically on boot by adding to existing /etc/fstab file.
Create or edit /etc/export to set access and other NFS options.
Enable and start nfs-server service using systemd.
Confirm what is being exported by NFS on server is as expected before moving on to the client setup.
Portage Client Set Up
Enable NFS in Kernel on Client
Like the server each client must have NFS support enabled in the kernel. My clients already have this enabled, but if they did not, I would add as I did above for the server, add to configuration, recompile kernel, add to boot loader and reboot. For clients only NFS client configuration settings matter, and I try to keep as much of the kernel configurations that make sense the same across machines. NFS settings are among the settings which make sense to me to keep the same across machines.
As my clients already have NFS support, and use NFS for things other than Portage, it it no surprise that nfs-utils is already installed, but if it was not, I would install in the usual way emerge -a nfs-utilsbefore making any changes to Portage on the machine.
Update Client fstab File to mount NFS Shares
In the below, 192.168.1.95 is the ip address of the server hosting portage and the NFS shares.
Replace Existing Portage Directories with NFS Shares
Next I backed up the existing portage directories on the client and then created new empty directories which will serve as the mount points to the Portage directories from the server.
Mount Portage NFS Shares from Server on Client
Below I mount each of the shares on the client manually. The changes to the fstab should handle this on reboot, but I want manual success first before I trust to automation. After mounting I list the mounts to make sure everything looks as I hoped.
Disable Portage Sync Mechanisms on Clients
For me this meant finding the cron setting which periodically synced Portage from the Internet. The server is set to update on a daily basis, so there is no longer a need for individual clients to also initiate a Portage sync.
Reboot client and confirm shares are mounted as expected.
This worked as expected. After rebooting I again listed the mounts and found the NFS shares from the server attached as desired.
Attempt to write file to each share.
As root I was able to touch a file to /var/cache/distfiles but not to either /var/db/repos/gentoo or /var/cache/binpkgs. This was expected behavior as only /var/cache/distfiles is mounted as read write (rw), the other locations are mounted as read only.
Update packages on client.
This went well, the client fount updates that needed to be applied and did sow without errors as below.
Update packages on multiple clients at same time.
This seems to work fine too. I updated server and two clients at the same with no issues. Everything seems in order and working properly.
Everything seems to have gone according to plan. Updates are working across all machines, though only the server is syncing with portage. In a few days I will go through all the clients and delete the backup directories which were created. As a side benefit of this effort, all my Gentoo boxes now have much more consistent Portage configurations regardless of when they were first built.
Chrls is currently a technology transformation leader at one of the oldest American investment banking services holding companies, headquartered in New York City. Previous roles at current employer include project manager, front office support, retail and enterprise global Windows server support. Currently residing in Tennessee on the Cumberland Plateau and enjoying life, family and open source.