Archive for the ‘Linux’ Category

RPi Munin Temperatures

Just two weeks ago I upgraded my raspberry pi from the original squeeze image to the newer wheezy based raspbian. Something I tried to do was to get temperature information in munin, but it didn’t seem possible

Today’s update from Eben indicated this was now simples. So, I updated and after reboot the temperature was available from /sys/class/thermal/thermal_zone0/temp.

I’ve put together a quick munin plugin to record this. The temperatures end up getting rounded to the nearest degree, but I think that’s ok.


if [ "$1" == "autoconf" ]; then
     if [ -e /sys/class/thermal/thermal_zone0/temp ]; then
         echo "yes"
         echo "no"
         exit 1
elif [ "$1" == "config" ]; then
     echo "graph_title Raspberry Pi Temperature"
     echo "graph_args --base 1000 -l 0"
     echo "graph_vlabel Temperature in Celsius"
     echo "graph_category Sensors"
     echo "temp.label temp"
     temp=$(cat /sys/class/thermal/thermal_zone0/temp)
     echo "temp.value $((temp/1000))"

Updated: Screenshots in LXDE

Back in 2010 I wrote about how to configure the gnome screenshot tool in lxde/openbox. Since then the advance of gnome3 has continued with 3.6 bringing changes that some don’t quite agree with.

I too have a new problem using gnome utilities since upgrading to Fedora 17 (with gnome 3.4). The behaviour of the screenshot tool has changed so that it no longer seems to ask where to save the screenshot (giving you an opportunity to choose a useful filename), but saves it with a timestamp in your homedir. While it is possible to force an interface it doesn’t seem possible to enable just the filename selection screen, having filename selection means you need to see the ugly set of all possible screenshot options first (how not very gnome).

Because of this I’ve decided to move to the xfce screenshot tool. It was an easy choice since I already brought in xfce utilities to replace other broken gnome ones (terminal, power-manager), and it’s pretty close to how the old gnome tool operated. My lxde-rc.xml how looks like:

<keybind key="Print">
<action name="Execute">
<command>xfce4-screenshooter -f</command>
<keybind key="A-Print">
<action name="Execute">
<command>xfce4-screenshooter -w</command>
<keybind key="C-Print">
<action name="Execute">
<command>xfce4-screenshooter -r</command>

As a bonus, I now have support for taking a screenshot of a selected region, which I’ve bound to Ctrl+Printscreen.

Persistent Synaptics Settings Outside Gnome

So far this is the best way I’ve found to have persistent touchpad settings when not using gnome. It feels quite hacky though, so I’m hoping there’s a better way I haven’t thought of yet

The problem seems to be that gpointing-device-settings relies on gnome-setting-daemon for persistent settings. Running gnome-settings-daemon plants an ugly power gauge in the notification area that I can’t seem to configure. [insert standard rant about gnome3 here]

Settings can be set manually with synclient, and using this in combination with gpointing-device-settings to work out what values you need to set is an approach that seems to work reliably, even if it is somewhat annoying

Here’s what to do

  1. In a terminal run ‘synclient -l’. This shows all the settings for the synaptics driver as currently applied. Save this output for later.
  2. Run gpointing-device-settings, make changes as appropiate
  3. Run ‘synclient -l’ again. Note the changed values from the first run, these are the ones to be set manually on startup
  4. Create a script to set these values when X starts. Mine is shown below

[andrew@apollo ~]$ cat /etc/X11/xinit/xinitrc.d/ 

synclient AccelFactor=0.0790378

Screenshots in LDXE

This is how I setup lxde (on Fedora 14) to take screenshots.

  • Install the gnome-utils package. This contains the gnome-screenshot program. It’s possible to avoid this by using imagemagick or scrot, but I couldn’t find a way to make them take shots of the active window (the usual alt+printscreen behaviour)
  • Insert the lines below into the keybind section of ~/.config/openbox/lxde-rc.xml

    <keybind key="Print">
      <action name="Execute">
    <keybind key="A-Print">
      <action name="Execute">
        <command>gnome-screenshot -w </command>

Simples 😀

Lucid, Upstart & Bridge Networking

New server arrived last week. Installed lucid (Ubuntu 10.04) and planned to run some VMs there with werdz‘s awesome rbvm.

Spent my first few hours at the machine tripping up over this nasty bug, but I’ll save that for a separate rant, this is a rant just about upstart.

Upstart is the kind of thing that’s great for laptops, they boot often, and you want them to boot quickly. Servers don’t boot quickly, they have network cards, remote access cards, raid controllers and other junk to initalize when they start. Because of this, trying to start everything on a system in parallel adds massive complexity without having anywhere near the same effect on the overall boot time.

Apart from this upstart, as it is, is half baked. It’s not ready to be included for a server distribution to go into production for 5 years. Most of the important services I have running here (bind, exim, apache, nginx) don’t even come with upstart configs, so half the system is still relying on old init scripts anyway.

The man page for mountall(8) sums it up pretty well:

This is a temporary tool until init(8) itself gains the necessary flexibility to perform this processing; you should not rely on its behaviour.

I noticed that after enabling bridge networking (for rbvm) on Monday that the dhcp server was no longer starting. After some investigation I concluded this was because of the delay between upstart finishing bringing up the network, and br0 actually being ready (about 15 seconds).

Writing an upstart config for dhcp didn’t help, it still ran before br0 was up, even though it was dependent on ‘started networking’. The only solution I could come up with was to add a prestart script to force upstart to wait before starting the dhcp server. This is what I came up with.

# dhcp3-server

description “DHCP Server”

start on (started networking and started dbus)
stop on (stopping networking)

expect fork

pre-start script

brstat() {
ifconfig |grep -c $BR_INTERFACE
return 0


while [ $BRSTAT -lt 1 ]; do
sleep 2

# allow dhcp server to write lease and pid file
mkdir -p /var/run/dhcp3-server
chown dhcpd:dhcpd /var/run/dhcp3-server
if [ ! -e /var/lib/dhcp3/dhcpd.leases ]; then
touch /var/lib/dhcp3/dhcpd.leases
chown dhcpd:dhcpd /var/lib/dhcp3 /var/lib/dhcp3/dhcpd.leases
if [ -e /var/lib/dhcp3/dhcpd.leases~ ]; then
chown dhcpd:dhcpd /var/lib/dhcp3/dhcpd.leases~

end script

exec /usr/sbin/dhcpd3 -q -cf /etc/dhcp3/dhcpd.conf

Why the need for the brstat() function? Upstart executes all it’s scripts with ‘/bin/sh -e’, so grep returning 1 caused the script to fail. The documentation didn’t indicate any way to change that behaviour.

After all that effort, I noticed the same problem was affecting ircd-hybrid this morning, so I’ve set a similar hack to run from /etc/rc2.d before anything else, to ensure none of the init scripts will run without the interface being up.

LXDE Part 2

So, I’ve been using it for a few days, and it’s working nicely now.

Power Management

The battery applet on LXPanel seemed to eh, not work for me. I decided to try loading in gnome-power-manager for this. Not only does this put an accurate power gauge on the panel (in the tray area), but controls things like brightness when on power/battery. Best of all, the brightness control buttons on the keyboard now work. Created an autostart entry to start this on login.

Note (October 2012): Updating to gnome3 broke using the power manager like this, I now use the xfce power manager. I have updated the autostart entry below to reflect this. (Thanks to @lil_cain for pointing this out)

[andrew@Callandra ~]$ cat .config/autostart/power.desktop
[Desktop Entry]
Name=Power Manager
Comment=XFCE4 Power Manager

Keyboard Indicators

For some reason this laptop comes with no indicator lights for the keyboard. I don’t understand why something would be designed like this, but there is an indicator available on LXPanel, which mostly works.

It seems to work fine when started, but, if it’s set to show only caps lock (the only one I really needed) it loads up on next login only indicating scroll lock. Only solution to this I’ve found is to keep all three indicators enabled.

Fedora, LXDE and the Dell Mini 10

So, last night I won a Dell Mini 10, and decided to try out LXDE rather than XFCE for a change (using the LXCD spin), so it’s been a little more fun to get working than it otherwise would have been 😀


This seems pretty light and cool. The default applications are very light, but most are functional enough to use. The panel comes with just the right amount of gadgets and configurations to do everything I need in the smallest possible amount of screen space.



The default web browser Midori seems cool, but just doesn’t have enough functionality to use as a firefox/chrome replacement, so I installed chrome. This mostly worked fairly well, but, it couldn’t open downloads because of xdg-open not being at all LXDE friendly.

Hacking up the terrible default path to be sensible and putting a new xdg-open in /usr/local/bin got around this though.

[andrew@Callandra ~]$ cat /usr/local/bin/xdg-open

[ -z "$1" ] && exit 1

if echo "${1}" | egrep -q "^(https?://|www.)"; then
    exec google-chrome "${1}"
    exit 0

pcmanfm "${1}"


My biggest criticism of the LXDE terminal is that it was clearly designed by someone who didn’t love terminals like I do. It’s functional, but I can’t live without clickable links.

I tried installing the gnome-terminal, but, it too seemed to fail at opening links. Luckily the xfce terminal worked perfectly 🙂

For some reason though, F11 is mapped to FullScreen by OpenBox, which is a real pain cause I use that for screen. Eventually I found to disable that in ~/.config/openbox/config


The hardware seems mostly good, the screen and keyboard size are most excellent (though, there’s enough room here that there could have been a Page Up/Page down button). The wireless (Broadcom 4312 *shudder*) works fine with kmod-wl from rpmfusion, and the network manager applet works great in LXDE.

Biggest problem with the hardware is the trackpad, which has the buttons integrated (like the ones on the new Mac). This is at best ‘tricky’ to use, it’s possible better drivers would help, I’m still looking.

Fedora: Please get your default paths right

Just noticed this on a clean Fedora 12 install (that I’ll talk about later).

[andrew@Callandra ~]$ echo $PATH

Compare that to the default Ubuntu paths:

home@racetrack:~$ echo $PATH

Ubuntu are right here, and Fedora is very wrong (much as it hurts me to have to say that). The point of the path is that default applications can be overridden at every level. Start from the back end, /bin. I may as the network administrator put a program of the same name (packaged) into /usr/bin to make it the default for system users. Similarly, as a local administrator I may want to put custom software, wrappers etc., into /usr/local/bin so they appear before the packaged defaults. As an end user, I might want to use my homedir to do similar

Requirements For A Usable Package Manager

Jeff writes:

What I would like to explain is why the impedance mismatch between Linux and Solaris packaging is not so much a technological divide as it is a philosophical one.

Philosophical differences are fine. Infinite diversity in infinite combinations, etc., however, regardless of the philosophy the goal of the package manager should be to make the life of the sysadmin easier, otherwise it’s not much use.

For a change this won’t be a rant about how the package set is an ancient pile of crap, we’ll assume for the sake of this discussion that you’re so concerned about stability you’re willing to live with a 6 year old version of bash. We won’t discuss how incompatible 3rd party sites are a poor substitute for the ports tree, because maybe you’re happy with a 5 year old version of nano.

The point is the tools should be independent of the packaging philosophy. They should minimise the amount of effort required to manage the system – automation is a good thing ™. On that basis, I propose that there is a minimum set of functions these tools should provide.

  • Automatic Dependency Resolution. Pretty obvious, you can’t call anything a package manager if it can’t do this.
  • Simple Upgrade. All upgrades to the packages should of course be available as packages, and there should be a simple command to upgrade all packages for which there is a new version (thanks Cian for reminding me of this one)
  • Remote Repo Support. HTTP is preferable for this, because, everyone has a http server. I don’t want to carry the Solaris 10 DVD in my pocket everywhere, and I don’t want to go around mounting NFS directories. The vendor doesn’t have to provide the package server, just support in the tools for a package server so I’m free to make my own (and, so are others)
  • Support For Multiple Repos. Blastwave has it’s own tools (yes, multiple) to actually install it’s packages. SunFreeWare relies on you doing your own manual dependency resolution (*shudder*). This is a load of shite. The package tools supplied by the operating system should allow me to define multiple sources, and rules for which source should be used. I should be free to build custom packages with dependencies against base packages if that’s what I choose (and, there’s lots of reasons to want to do this), or to maintain a separate hierarchy of independent software (like blastwave etc.) if that’s what the situation requires.
  • Simple tools to query packages, search for packages, query files. We don’t need all the bells and whistles of apt, but, we do need equivalents for ‘apt-cache search’, ‘yum info’, and ‘dpkg -S’.

Regardless of the philosophy, the point of a package manager should be to manage all the software on the system. I don’t have time to compile things, and I don’t enjoy patching things. There is no reason that you can not achieve separation of components, (eg, base and ports) while still providing binary packages for everything. The whole system should be package managed, apart from the handful of shell scripts I have sitting in /usr/local/bin ( the one place the package manager should never touch. /usr/local/ is for me to manage. This is what both FHS and the debian package policy says)

WTF did I change?

So, it’s been a while since I posted, I thought I’d share my latest heap of hacky shell up here.

Last week we were having a discussion following on from Chris Siebenmann’s post on restoring files from a package, to see what changes had been made. Anyway, we decided that such a feature could be useful, so I promised to hack one together.

It took a week to finish this, because I spent most of my time confused about how apt-get couldn’t just download package without being root. I now know that it defiantly can’t do this. I also know that aptitude can.

# Check we have an argument
if [ -z "$1" ]; then
    echo "Usage $0 /path/to/file"
exit 1
# Check this is actually a text file, if
# not we drop out straight away
if [ `file $1|grep -c text ` -lt 1 ]; then
    echo "The file $1 is not a text file"
    exit 2
# Work out the package name
PACKAGE=`dpkg -S $1| awk -F: '{print $1}'`
# If there's no matching package then
# just exit with an error
if [ $? -gt 0 ]; then
    echo "No package provides this file"
    exit 3
# Download the package
echo "File $1 is provided by $PACKAGE. Downloading to /tmp/$$"
mkdir /tmp/$$
cd /tmp/$$
aptitude download $PACKAGE > /dev/null
# Extract the package
PKGNAME=`find /tmp/$$ -maxdepth 1 -type f -name "*.deb"`
dpkg -x $PKGNAME /tmp/$$
# Diff shit
diff -us /tmp/$$/$1 $1
# If there's a difference then offer to save the diff
if [ `diff -qs $1 /tmp/$$/$1|grep -c identical` -ne 1 ]; then
    echo -n "Save this diff? [yes] "
    read answer
    if [ -n "$answer" ]; then
    if [ "$ANSWER" = "yes" ]; then
        diff -us /tmp/$$/$1 $1 > /tmp/$PACKAGE.$$.diff
        File saved to /tmp/$PACKAGE.$$.diff
# We should be nice and offer to clean up
echo -n "Delete the temporary package files from /tmp/$$? [yes] "
read answer
if [ -n "$answer" ]; then
if [ "$ANSWER" = "yes" ]; then
    rm -fr /tmp/$$/

This script is also available from the RedBrick package repo