Skip to content

Moving Portage temporary build directory to an external disk

Recently, I ran into an issue where Portage required more temporary disk space than was available on my 120 GB SSD. To solve this, I moved Portage’s temporary build directory to a 16 TB external USB 3.0 drive.

This approach is clean, safe, and recommended for building very large packages such as Android Studio.

This is what we want to avoid with a small ssd drive

Screenshot

Prepare the directory (correct ownership and permissions)

mkdir -vp /mnt/usb/.gentoo.tmp
chown root:portage /mnt/usb/.gentoo.tmp
chmod 775 /mnt/usb/.gentoo.tmp

Verify that the directory exists

$ ls -ld /mnt/usb/.gentoo.tmp
drwxrwxr-x 2 root portage 4096 Jan 28 22:43 /mnt/usb/.gentoo.tmp

Ensure the disk is always mounted

Portage must not start if /mnt/usb is not mounted.
If the disk is unavailable, builds will fail immediately  which is intentional and acts as a safety mechanism.

Check mount status

mount | grep /mnt/usb
/dev/mapper/usb on /mnt/usb type ext4 (rw,relatime)

If the disk is mounted via /etc/fstab, ensure it is not marked as noauto.

UUID=xxxx-xxxx  /mnt/usb  ext4  defaults,noatime  0  2

If the disk is not mounted, emerge will fail hard — which is good protection against incomplete or broken builds.

Configure PORTAGE_TMPDIR

Now configure Portage to use the new temporary directory.

Edit /etc/portage/make.conf

vim /etc/portage/make.conf

Add PORTAGE_TMPDIR to make.conf

PORTAGE_TMPDIR="/mnt/usb/.gentoo.tmp"

Verify that PORTAGE_TMPDIR is set correctly

portageq envvar PORTAGE_TMPDIR
/mnt/usb/.gentoo.tmp

Clean up old temporary files (optional but recommended)

rm -rf /var/tmp/portage/*

This frees up disk space on my 120 GB ssd drive

Test with a small package first

  • Before building very large packages, it is recommended to test the setup using a small and fast package.
emerge -1 sys-libs/zlib

Verify that Portage uses the new directory

$ ls /mnt/usb/.gentoo.tmp
portage

You should see a portage/ directory appear while the build is running, confirming that portage is using the external disk for temporary build files.

Result

  • After this setup:
  • Portage no longer consumes large amounts of space on the root filesystem
  • Large packages (e.g. Android Studio) build reliably
  • Disk space warnings and build freezes caused by insufficient temporary storage are eliminated
  • This configuration is best practice for Gentoo systems with limited root disk space and large secondary storage.