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!

2 comments:

uh-huh said...

Hi, I uncovered your site while struggling to get gentoo linux on my 900A EEE w/4G SSD and 8G SD card. Using the 2.6.29-r5 sources. I set up LVM to span the two media following the gentoo LVM2 doc. So I have a tiny /boot partition, a small / partition and /usr /home /tmp /opt /var are spread out across the LVM. Now I'm stuck writing fstab.


You recommend:

tmpfs /tmp tmpfs nodev,nosuid,noexec

Is that in addition to or in place of

shm /dev/shm tmpfs nodev,nosuid,noexec 0 0

which is in the default fstab?

Then you go on to say:

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.

What is this bootmisc and how would I know what it is set to? If /tmp is mounted as a partition in the LVM does that mean it's not in RAM. Could you explain what you mean by "change depends to have after bootmisc"? Are you saying to change a word or that change depends on something else?

I belong to the gentoo-user list and you can reach me a maxim.wexler@gmail.com

Hope you're still reading your old comments ;)

Rgrds,

Maxim Wexler

Christopher Friedt said...

Hi Maxim,

In response to your questions:

1) you can have as many tmpfs mounts as you like - so use /tmp and /dev/shm.

2) most scripts in /etc/init.d have a function called depend(), which has a special syntax. My postbootmisc looks like this:

#!/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
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"
}


# vim:ts=4


and my /etc/conf.d/postbootmisc.start looks like this:


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 ]; then
rm -Rf /var/cache && cd /var && ln -sf ../../tmp/cache cache
fi
mkdir -p /tmp/cache/hald
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}}