lapisnev

Don't squeeze me, I fart

Things that make you go 🤌. Weird computer stuff. Artist and general creative type. Occasionally funny. Gentoo on main. I play rhythm games!

Inkscape Monofur font Cohost PLUS!

You can post SVG files like photos on this website! Spread the word!


I have a machine with lots of RAM that I use as my main Gentoo workstation, and for the majority of packages I can set my PORTAGE_TMPDIR to a tmpfs partition to use RAM as scratch space and avoid wearing out my SSDs. Unfortunately, when I update my system, Portage tries to compile multiple very large packages at the same time, like Firefox, Thunderbird, three versions of the OpenJDK (I play Minecraft), LibreOffice... and this can fill the tmpfs and possibly run the system entirely out of RAM.

This is the solution I've been using to programmatically catch most of the largest packages I might want to install and divert them to use physical storage again. The sheer number of smaller packages on my system that can continue to use tmpfs still add up to a ton of avoided write wear on my SSDs.


First, save the following script as /etc/portage/postsync.d/detect-notmpfs:

#!/bin/sh
echo "# This file was generated by a script. DO NOT EDIT! Your changes will be lost next emerge --sync!" > /etc/portage/package.env/no-tmpfs
grep -rlE 'CHECKREQS_MEMORY|CHECKREQS_DISK_BUILD' /var/db/repos/ | awk -F/ '{print $6 "/" $7 " no-tmpfs.conf"}' | sort | uniq | sed '/eclass\//d' >> /etc/portage/package.env/no-tmpfs

Don't forget to make it executable! This scans all of the ebuilds on your system looking for ones that check for a minimum required amount of disk space or RAM, then saves a specially formatted list in /etc/portage/package.env/no-tmpfs that tells Portage to include extra environment variables from another file we'll create in a minute.

/etc/portage/postsync.d/ is used to run scripts automatically after an emerge --sync, so this would be the place to symlink eix-update and other stuff you want to run whenever you sync.

Next, save the following as /etc/portage/env/no-tmpfs.conf:

PORTAGE_TMPDIR="/tmp/"

You can change this to point to whatever directory you feel like, but it should be backed by physical storage and not a tmpfs. (That's literally what we're trying to do!) Everything else will use your default PORTAGE_TMPDIR which you've presumably already set to a tmpfs directory if you're following this guide.

... Anyway, that's it. You can now sync and update, and this script will be run in the process, and the largest packages on your system will use physical storage while smaller ones continue to use tmpfs.


You must log in to comment.