Canonical Voices

Posts tagged with 'tmpfs'

pitti

When writing system integration tests it often happens that I want to mount some tmpfses over directories like /etc/postgresql/ or /home, and run the whole script with an unshared mount namespace so that (1) it does not interfere with the real system, and (2) is guaranteed to clean up after itself (unmounting etc.) after it ends in any possible way (including SIGKILL, which breaks usual cleanup methods like “trap”, “finally”, “def tearDown()”, “atexit()” and so on).

In gvfs’ and postgresql-common’s tests, which both have been around for a while, I prepare a set of shell commands in a variable and pipe that into unshare -m sh, but that has some major problems: It doesn’t scale well to large programs, looks rather ugly, breaks syntax highlighting in editors, and it destroys the real stdin, so you cannot e. g. call a “bash -i” in your test for interactively debugging a failed test.

I just changed postgresql-common’s test runner to use unshare/tmpfses as well, and needed a better approach. What I eventually figured out preserves stdin, $0, and $@, and still looks like a normal script (i. e. not just a single big string). It still looks a bit hackish, but I can live with that:

#!/bin/sh
set -e
# call ourselves through unshare in a way that keeps normal stdin, $0, and CLI args
unshare -uim sh -- -c "`tail -n +7 $0`" "$0" "$@"
exit $?

# unshared program starts here
set -e
echo "args: $@"
echo "mounting tmpfs"
mount -n -t tmpfs tmpfs /etc
grep /etc /proc/mounts
echo "done"

As Unix/Linux’ shebang parsing is rather limited, I didn’t find a way to do something like

#!/usr/bin/env unshare -m sh

If anyone knows a trick which avoids the “tail -n +7″ hack and having to pay attention to passing around “$@”, I’d appreciate a comment how to simplify this.

Read more
sfmadmax

So looking for new ways to extend your laptop battery life??  Just recently I found a great combo that involves using a very cool application called “Jupiter

You can grab Jupiter from the launchpad PPA @ https://launchpad.net/~webupd8team/+archive/jupiter

I have yet to find a good application that handles “On Demand” mode relatively well. This app clocks down your processors when on battery to their lowest setting and kicks them back up once A/C power is restored. I have used other linux power mgmt tools but haven’t had a great experience. I have a system76 Pangolin and it’s pretty power hungry, it’s pretty much a mobile desktop and during the Natty / Oneiric releases of Ubuntu I was lucky to get 40 minutes on the beast. But that was because everything was running full power, After installing Jupiter and making some additional changes I managed to turn 40 minutes into 2 hours. Not bad eh?

Some of the additional changes I made involved the following:

Taking /var/log and completely mounting it to tmpfs. This way we are writing straight to memory, not needing to bother the disk constant reads/writes. Take note that this causes your logs to clear out at the end of every reboot/shutdown, but I’ve seen improvement.

So first we need to make some modifications in /etc/fstab

tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0

Save that off

Then lets carry out the following.

$ sudo service rsyslog status // to check if it’s up and running
$ sudo service rsyslog stop
$ sudo rm -rf /tmp/*
$ sudo rm -rf /var/log/*
$ sudo rm -rf /var/tmp/*
$ sudo mount -a
$ sudo service rsyslog start

Now you will notice all system logs will be directed to /tmp. Give it a try for a week or two and see if you notice any difference in your battery life.


Read more