20080611

How-To: The Full Portage Tree on the EEE PC




Gentoo is often considered to be 'bloated' because the Portage tree takes up at least 500 MB on disk. Depending on the filesystem, that could mean that the usage can be sometimes up to 750 MB!

On a UMPC such as the EEE, with only very limited hard-disk space, 750 MB is far over the limit of acceptibility.

My first solution was simply to use a binary Gentoo system. The portage tree was not necessary as long as an internet connection was available and a suitable binary package repository was configured. That has actually been working incredibly well and I have no complaints yet whatsoever. However, I do occasionally like to look into the portage tree for examples on creating ebuilds when I'm doing custom software packaging, so i thought it would be nice to have it wherever I can take my EEE.

Then someone on EEE-User mentioned using SquashFS for the Portage tree. This made absolute sense, because the Portage tree did not need to be updated frequently at all, and could easily be made read only. SquashFS enabled me to have the benefits of a source-based Gentoo distribution on my EEE but compressed the Portage tree from 700 MB to 42 MB !!!

The following 5 steps will demonstrate how easy it is to use Gentoo - even with it's "bloated" Portage tree - on the EEE PC.

Note: I performed these steps on a modified EEE PC with 2GB of physical RAM, which explains how I could mount 768MB of RAM as tmpfs. If you have less than 2GB of physical RAM, then I would suggest making the SquashFS Portage image on a regular desktop computer running Gentoo Linux.

Step 1: Find a portage mirror
You can find all of the Gentoo mirrors on the official Gentoo mirror list. I use


MIRROR="http://gentoo.mirrors.tera-byte.com"


Step 2: Install squashfs-tools


emerge -av1 squashfs-tools


Step 3: Download and Extract the Latest Portage Snapshot

mkdir -p /tmp/tmp2
mount -o size=768m -t tmpfs none /tmp/tmp2
wget -O - "${MIRROR}"/snapshots/portage-latest.tar.bz2 | tar xpvjf - -C /tmp/tmp2

Step 4: Create the SquashFS Image


mksquashfs /tmp/tmp2/portage /tmp/tmp2/portage.sqfs
mv /tmp/tmp2/portage.sqfs /usr

umount /tmp/tmp2
rmdir /tmp/tmp2

Step 5: Create init.d and conf.d entries to simplify or automate mounting

/etc/init.d/portage-squashfs:

#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

depend() {
need localmount
}

checkopts() {
for var in "${MTPNT}"x "${PSQFS}"x; do
if [ "${var}" = "x" ]; then
eerror "one of the necessary variables was not defined"
return 1
fi
done

if [ "$(grep "squashfs" /proc/filesystems)" = "" ]; then
eerror "SquashFS is not supported by your kernel"
return 1
fi
if [ ! -e "${PSQFS}" ]; then
eerror "${PSQFS}: No such file or directory"
return 1
fi
if [ ! -d "${MTPNT}" ]; then
eerror "${MTPNT}: No such file or directory"
return 1
fi
}

start() {
local mtopts="-t squashfs -o loop,ro"

einfo "mounting ${PSQFS} at ${MTPNT}"
checkopts || ( eend 1; return 1 )
mount ${mtopts} ${PSQFS} ${MTPNT}
eend $?
}

stop() {
einfo "unmounting ${MTPNT}"
umount ${MTPNT}
}

# vim:ts=4


/etc/conf.d/portage-squashfs:

MTPNT=/usr/portage
PSQFS=/usr/portage.sqfs
Lastly, don't forget to make the init script runnable:

chmod +x /etc/init.d/portage-squashfs


Notes:

Extracting the portage tree and creating the SquashFS image in /tmp will work only if you have >= 1GB of RAM, approximately. I was using the EEE PC 8G, which comes with 1GB of RAM and there were no problems at all. Alternatively, if you have >= 800MB on your root device, then you could perform the operation there, but it would be much slower. If another desktop or laptop PC is available, a better alternative is to build the portage.sqfs file on the other machine and then copy it on to your EEE.

Also, it should go without saying that you will need to have root permissions to do this - use 'sudo -s'

You should also be aware, that this will make /usr/portage read-only. Therefore, in /etc/make.conf, set DISTDIR="/tmp/distdir" and PKGDIR="/tmp/binpkgs", or something similar.

3 comments:

Deikensentsu said...

Hi Chris, haven't tried your portage method yet, but just wanted to say thanks a ton for posting it, I'm working on installing Gentoo to a 16gb CF card in my CX210X tablet PC to cut down on the heat and power consumption, and I knew Gentoo was my best bet, you've just affirmed that even more. Thanks. If you have any tips on utilizing ram disks to run more of the system from I'm all ears, I've 4gb of RAM and loads of patience.

Unknown said...

Hi Ethan, thanks for the feedback ;-)

I also have the following variables in /etc/make.conf:
PKGDIR="/tmp/binpkgs"
PORTAGE_TMPDIR="/tmp"
DISTDIR="/tmp/distdir"

in fstab:
tmpfs /tmp tmpfs nodev 0 0

===== /etc/init.d/postbootmisc =====
depend() {
need localmount
before logger
after bootmisc
after acpid
}
start() {
ebegin "Starting postbootmisc"
if [[ -e /etc/conf.d/postbootmisc.start ]] ; then
source /etc/conf.d/postbootmisc.start
fi
eend $? "Failed to start postbootmisc"
}
stop() {
ebegin "Stopping postbootmisc"
if [[ -e /etc/conf.d/postbootmisc.stop ]] ; then
source /etc/conf.d/postbootmisc.stop
fi
eend $? "Failed to stop postbootmisc"
}
=========================

===== /etc/conf.d/postbootmisc.start =====
mkdir -p /tmp/run
if [ ! -h /var/run ]; then
cd /var && tar cpvjf /var/run.tar.bz2 run
rm -Rf /var/run && cd /var && ln -sf ../tmp/run run
fi
mkdir -p /var/run/{cups,dbus,dhcp,hald,openldap,pm-utils,pulse,samba,screen,sepermit,sudo}
chmod 777 /var/run/screen
mkdir -p /tmp/cache/edb
if [ ! -h /var/cache/edb ]; then
rm -Rf /var/cache/edb && cd /var/cache && ln -sf ../../tmp/cache/edb edb
fi
mkdir -p /tmp/{portage,binpkgs,distdir}
if [ ! -h /var/log ]; then
rm -Rf /var/log && cd /var && ln -sf ../tmp/log log
fi
mkdir -p /tmp/{lib/dhcpcd,run,log/{gdm,samba,sandbox,news,cups,wicd}}
=========================

Unknown said...

The system as a whole still needs some touch-ups, but I rarely write anything to flash and my performance is lightning-fast.

It should also be possible to use unionfs + tmpfs + squashfs for /usr/portage, but that introduces slightly more complexity.