Scripts for squashing portage tree.
Based on solution from https://www.brunsware.de/blog/gentoo/portage-tree-squashfs-overlayfs.html
It is important to read the article and prepare portage configuration.
Required kernel options:
File systems --->
[*] Miscellaneous filesystems --->
<*> SquashFS 4.0 - Squashed file system support
...
<*> Overlay filesystem support
Install squashfs-tools
emerge -av squashfs-tools
Make new DISTDIR folder outside $PORTDIR:
mkdir -p /var/lib/portage/distfiles
chown portage:portage /var/lib/portage/distfiles
Move $DISTDIR to new destination in /etc/portage/make.conf. For example:
DISTDIR="/var/lib/portage/distfiles"
Remove old $DISTDIR directory content
rm /usr/portage/distfiles/*
Make directory for lower overlayfs layer
mkdir /usr/portage-ro
Create squashfs portage file and remove $PORTDIR content:
mksquashfs /usr/portage /usr/portage.sqfs
rm -r /usr/portage/*
Symlink squash-portage.sh to /usr/local/bin:
ln -s squash-portage.sh /usr/local/bin/squash-portage
chmod u+x /usr/local/bin/squash-portage
For systemd, symlink service file to /etc/systemd/system/squash-portage.service
ln -s squash-portage.service /etc/systemd/system/squash-portage.service
systemctl enable squash-portage.service
Create a file in /etc/portage/postsync.d.
/etc/portage/postsync.d/squash-portage
#!/bin/bash
systemctl restart squash-portage