Date Tags Gentoo

Introduction

The Gentoo package manager, Portage, uses a lot of disk space mostly due to a high number of small files. By storing the tree in a SquashFS file the used disk space goes down from about 740MB to 70MB !! It is also a lot faster due less number of times the disk is accessed.

Another nice side effect is that distributing portage locally by copying the squashfs file or even exporting the SquashFS file via NFS (read-only) is now much faster and efficient.

Some personal choices first:
I use a dedicated volume to store all portage related things mounted under /mnt/portage. Therefore I chose the default path to store the squashFS backing files to be /mnt/portage/portage.sqfs.
The squashed tree will be mounted at the portage default location /usr/portage.
If your setup differs from that layout please adjust various commands below accordingly.

Requirements

  • Kernel support for Squash and Overlay file systems:
File systems -> Miscellaneous filesystems -> SquashFS 4.0 - Squashed file system support 
File systems -> Overlay filesystem support
  • Installed sys-fs/squashfs-tools

  • Distfiles and if used also PKGDIR moved outside of the portage tree, e.g. in /etc/portage/make.conf:
DISTDIR="/mnt/portage/distfiles"
PKGDIR="/mnt/portage/packages"

 

Preparation

  • required kernel modules are loaded, if not compiled in statically:
# modprobe loop squashfs overlay

in case you are use OpenRC make sure /etc/conf.d/modules contains contains:

modules="loop squashfs overlay"

  • /etc/fstab entry for squashfs portage tree:
/mnt/portage/portage.sqfs /usr/portage squashfs ro,defaults,nosuid,nodev,noexec 0 0

 

Squash it

To create the initial squashed portage tree:

# update_portage.sh -p <portage tree> -s <squashfs file>

In case your portage location is NOT /usr/portage, make sure your portage file system location matches the entry in /etc/portage/repos.conf/gentoo.conf and matches the -p option calling update_portage.sh !

 

Updating portage

Either manually execute the script or to update daily via cron:

# ln -s /usr/local/sbin/update_portage.sh /etc/cron.daily/update_portage.sh


Update:

Added proper cleanup in case the script gets interrupted!