Portage with autofs

Introduction
Portage can be a resource hog and disk eating fiend. Using tmpfs with portage can speed up compile times if you have enough RAM and sqlite can speed up emerge times significantly by caching metadata (instead of in flat files). With these speed improvements it can be advantageous to unmount tmpfs mounts to free up that RAM for application and disk cache. In larger deployments of Gentoo it is common to use NFS to mount the portage tree and related directories. For these types of deployments, it doesn't make sense to keep portage and some related directories mounted if they are not in use. This article outlines some good practices with portage and autofs.

Install autofs
Autofs requires its own empty directory to mount over. Autofs has it's own filesystem know as. This FS intercepts and relays stat64 calls to the daemon which handles mounting the file systems on top of itself.

Make the container directory

If you haven't already, then emerge autofs. You should not need or  for this tutorial.

Configuring autofs
Create and include any of the hacks below.

Edit to include the new autofs file

Start autofs once you are done and if everything works as expected add it to start up.

With tmpfs
This file will include the tmpfs hack to speed up the build process.

Edit/Change to point to  in

With NFS distfiles
In large deployments it is handy to host the on a central server. There are two methods for this: shared distfiles and read-only dist files. read-only distfiles are used in the event that the distfile does not exist in. In this example, the rw-distfiles are hosted on a local LVM LV.

Edit/Change and/or  in  to point to

PKGDIR
As with NFS distfiles it can be advantages to use a central file server for common binary packages.

Edit/Change in  to point to

PORTDIR
Even portage can be moved to a volume for itself removing the need for it to be mounted all the time, or even from a bin host. This should be taken with care. Please read Sharing Portage over NFS to fully understand the effort involved before proceeding.

Edit/Change in  to point to

If you decide to go this method, you will need to make sure to run to rebuild the cache files.