Showing posts with label ramfs. Show all posts
Showing posts with label ramfs. Show all posts

20080708

Prebootmisc for the EEE

I thought I would share a few more of my tricks for utilizing as much of the RAM on my EEE as possible in order to spare the flash memory from excessive write cycles.

So here they are!

In order to minimize writes to flash I would advise adding this line to your /etc/fstab:
tmpfs /tmp tmpfs nodev,nosuid,noexec 0 0
Accordingly, to utilize the ram-based filesystem in /tmp, you can also make some adjustments to portage in /etc/make.conf:
PKGDIR="/tmp/binpkgs"
PORTAGE_TMPDIR="/tmp"
DISTDIR="/tmp/distdir"
Now, in order to prevent certain daemons and applications from vomiting all over you on boot, it's necessary to build a bit of structure in /tmp that such apps expect to find. For that we'll need an init.d entry that starts right after the local filesystems are mounted, but before anything else!

/etc/init.d/prebootmisc:
#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

depend() {
need localmount
before logger
before bootmisc
}

start() {
ebegin "Starting prebootmisc"

if [[ -e /etc/conf.d/prebootmisc.start ]] ; then
source /etc/conf.d/prebootmisc.start
fi

eend $? "Failed to start prebootmisc"
}

stop() {
ebegin "Stopping prebootmisc"

if [[ -e /etc/conf.d/prebootmisc.stop ]] ; then
source /etc/conf.d/prebootmisc.stop
fi

eend $? "Failed to stop prebootmisc"
}


# vim:ts=4
/etc/conf.d/prebootmisc.start:
if [ ! -h /var/cache/edb ]; then
rm -Rf /var/cache/edb && cd /var/cache && ln -sf ../../tmp/cache/edb edb
fi
mkdir -p /tmp/cache/edb
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/log/{gdm,samba,sandbox,news,cups}
Now just run the following commands to add prebootmisc to the boot runlevel
chmod +x /etc/init.d/prebootmisc
rc-update add prebootmisc boot
There is 1 catch that I've found after months of use - if your bootmisc is set to WIPE_TMP (wipe_tmp for openrc users), then it will destroy the directory structure that prebootmisc created. My suggestions are 1) disable wipe_tmp which is useless anyway if /tmp is a ram filesystem, 2) rename the service postbootmisc and change depends to have after bootmisc, if you really want /tmp to be wiped before it is mounted tmpfs.

After rebooting the machine you should find that many applications run faster and do much fewer write cycles to flash, preserving the longevity of your flash root filesystem.

To get Firefox to utilize /tmp as your cache (you will lose your cache after /tmp is unmounted), open firefox, navigate to about:config, and set this line:
browser.cache.disk.parent_directory /tmp
If you're a gnome user, you might also find it helpful to add the System Monitor applet to your panel and activate the disk monitor utility. I've changed my read indicator to a safe green colour and my write indicator to red. That way, whenever I'm using an application that is abusing my flash filesystem I'll see a red spike in the System monitor and I'll I know that I'll have to adjust the preferences for that app to use /tmp.

I hope this has helped speed up applications and spare the life of your flash and speed up your EEE!