[ Content | Sidebar ]

Archives for linux

Conky BBC weather

April 17th, 2011

I’ve written a Ruby script called bbc-weather.rb that parses the BBC weather RSS for a particular location and formats the data for conky. Here’s an example:

To use it insert the following in your .conkyrc:

${execpi 600 ruby /path/to/bbc-weather.rb 4197}

This will refresh every hour. Replace 4197 with the number of your local weather station. You can find this by looking at the BBC weather URL which is of the form weather/forecast/XXXX. You also need to define two colours for the script to use, in the options section before TEXT, like so:

color1 white
color2 grey

You might also need the following, as conky limits the about of text it will read from a sub-process:

text_buffer_size 2048

UPDATE: apparently this script no longer works with recent BBC Weather updates. Check out the comments for an improved version.

Reducing DVD drive noise

September 25th, 2010

Fan noise from CD/DVD drives can be very loud. It probably doesn’t matter if you’re just reading something off it but if you’re watching a DVD for example, it can get annoying. The fans are required in modern drives when the disc is spinning very fast – e.g. 16x – and by default it spins as fast as it can. So there is a simple solution: slow down your drive! This is easy enough in Linux, but oddly the command you need is eject. For example, to reduce your drive to 4x speed:

eject -x 4 /dev/dvd

The parameter -x is simply the multiplier: pick a low value (except 0, which means full speed). 4x seems sufficient on my device to completely disable the fans.

Filed in linux - Comments closed

Samsung Q320 Fn-keys in Linux 2.6.32

February 20th, 2010

If you’ve been following my attempts to get the brightness up/down and other fn-keys on my Samsung Q320 laptop to work in Linux, you might like to know the saga has reached a happy conclusion. Previously I published a hack to the atkbd kernel driver to get these problematic keys to send key release events. My attempt to get this included in the kernel failed, but I was told the 2.6.32 kernel would contain a new mechanism for fixing this from userspace.

Well, 2.6.32 is here so how can we fix the fn-key release problem? Documentation for the new sysfs attribute is a bit scanty as it’s intended to be used only by udev/HAL/DeviceKit, but you can set it yourself quite easily. The relevant file is /sys/devices/platform/i8042/serio0/force_release – this lets you manipulate a bitmap in atkbd.c indicating which scancodes don’t send key release events.

echo 130-132,134,136,137,179,247,249 \
    > /sys/devices/platform/i8042/serio0/force_release

The bitmap editing syntax is quite nice – done in lib/bitmap.c rather than the atkbd driver itself. I got those scancodes from the array atkbd_samsung_forced_release_keys in atkbd.c. They were originally intended for the NC20 but the Q320 keyboard seems to be the same. It works for me anyway.

You still need to map the brightness up/down keys to the correct X11 codes, which you can do like this:

setkeycodes e008 225 e009 224

Job’s a good’un.

All my Samsung Q320 coverage is here.

Getting GRUB2 to dual boot Debian and FreeBSD

November 27th, 2009

Just installed FreeBSD 8 on a spare partition of my computer. Was planning to use the Debian-installed GRUB to boot it, but when I went to edit GRUB config files they had changed beyond recognition. GRUB 2, it seems, is very different to GRUB 1. For the benefit of anyone else who has a similar setup, edit /etc/grub.d/40_custom and add the following:

menuentry "FreeBSD" {
   set root=(hd0,1,a)
   chainloader +1
}

Make sure you edit the root parameter to the partition where you installed FreeBSD. Remember that “real” partitions are numbered 0,1.. and UFS partitions go a,b.. and you need both.

Now run update-grub2 and /boot/grub/grub.cfg should be generated from the config files in /etc/grub.d. Verify that FreeBSD menu item has been added and reboot.

Samsung Q320 Fn-key release hack update

September 19th, 2009

Earlier I posted a hack to get the Linux kernel to send synthetic key release events for the Fn-keys on a Samsung Q320. But I forgot about actually submitting the patch to the kernel developers until today. However, it looks like this hack will be unnecessary as of 2.6.32:

Hi Nick,

On Sep 19, 2009, at 12:20 AM, Nick Gasson wrote:

> This adds a workaround for the missing fn-key release
> events on Samsung Q320 and similar laptops.
>
> Tested extensively on my own laptop.
>
> Signed-off-by: Nick Gasson

Thank you very much for your patch, hovewer I will not be accepting any more patches for the force release quirk in the kernel. 2.6.32 will have ‘force_release’ sysfs attribute allowing to apply the quirk from userspace.


Dmitry

Which is good, because either way I won’t have to use a custom kernel. I wonder how long this will take to propagate to Debian though…

Self-signed certificates on Nokia S40 phones

August 19th, 2009

I’ve been having a problem for a while with my Nokia 6300 phone not accepting the self-signed SSL certificate I use on my IMAP server (dovecot). This is a bit annoying because I can’t read emails on my phone.

Various Nokia forums suggest that you need to download the certificate over HTTP to install it. This is true, but there is an extra key step: the certificate needs to be in the DER format rather than PEM, which the phone doesn’t like. To convert, just use OpenSSL like this:

openssl x509 -in dovecot.pem -inform PEM -out dovecot.crt -outform DER

Place this somewhere you can access over HTTP and navigate to it using the phone. You’ll be asked if you want to save it, say yes and the certificate will be permanently installed in the phone. Now try accessing your mail over IMAPS and everything should work.

This trick should also work for other SSL applications (e.g. HTTPS), but I haven’t tried it.

Linux on a Samsung Q320: Part 7

July 13th, 2009

Argh! Another problem! Over the last couple of days I’ve being trying to figure out why the brightness fn-keys on my laptop don’t seem to work: they either set the brightness to maximum-bright or maximum-dim. (Although they inexplicably sometimes work.) At first I thought it was a problem with my earlier HAL hackery, but this isn’t the case as the HAL brightness scripts work fine when not using the fn-keys.

After a while I discovered the problem was that some of the fn-keys weren’t sending key release events (easy to see in xev or with lshal -m). Turns out this is a problem with lots of laptop keyboards: look at the thousands of lines of hacks in drivers/input/keyboard/atkbd.c in the Linux kernel source. The good news is that this is easy to fix: the Q320 uses exactly the same scancodes as an earlier Samsung laptop. The bad news is that you have to compile your own kernel. Ho hum.

Apply this patch to a 2.6.30 kernel and rebuild. Voila! And the problem is gone!

--- drivers/input/keyboard/atkbd.c.old  2009-07-13 00:34:14.000000000 +0100
+++ drivers/input/keyboard/atkbd.c      2009-07-13 00:35:19.000000000 +0100
@@ -1550,6 +1550,15 @@
                .driver_data = atkbd_samsung_forced_release_keys,
        },
        {
+               .ident = "Samsung Q320/P320",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "Q320/P320"),
+               },
+               .callback = atkbd_setup_forced_release,
+               .driver_data = atkbd_samsung_forced_release_keys,
+       },
+       {
                .ident = "Samsung SQ45S70S",
                .matches = {
                        DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),

I found the DMI_PRODUCT_NAME using dmidecode if you were wondering.

Will test it for a few days and if nothing is borked maybe I shall try to get it merged into the kernel. It would certainly be annoying to have to compile my own kernel for every release.

Shutting down and rebooting via HAL

July 12th, 2009

You know how GNOME/KDE have “shutdown” and “reboot” buttons that normal users can use to turn off the computer? Rather than using sudo or making /sbin/shutdown setuid, they use HAL which provides a nice power management interface. Turns out this is pretty easy to call from the command line so you can use it in Fluxbox, etc.

The DBus object is /org/freedesktop/Hal/devices/computer which has lots of interesting methods including Shutdown(), Reboot(), and Suspend(). For example, you can reboot the computer using:

qdbus --system org.freedesktop.Hal /org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Reboot

This is using the qdbus tool which is distributed with QT. If you get permission errors you may have to configure PolicyKit to let you call this interface. Here’s my PolicyKit.conf which works for me on Arch Linux. (You’ll also need to add your user to the power group.)

Here’s a simple script to wrap this up: hal-power. Usage example: hal-power reboot to reboot the computer.

Linux on a Samsung Q320: Part 6

July 9th, 2009

I’ve been playing around with powertop trying to reduce power usage. I’m using laptop-mode to spin down the disk when its not needed (it automatically activates when on battery power). I’ve also added these two powertop suggestions to /etc/rc.local

# Reduce the frequency of disk flushes
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
 
# Turn off the SATA link whenever possible
echo min_power > /sys/class/scsi_host/host0/link_power_management_policy

I’ve also enabled CPU frequency scaling. If I dim the brightness, the laptop uses around 16W of power under light usage: amarok playing in the background and browsing the tubes. It guesses this will give around 3 hours battery life. Not sure if I can make it better…

Addictive game

July 9th, 2009

I wasted today playing UFO: Alien Invasion. It’s unusually polished for an open source game. The graphics are very nice, especially in the battle mode. The storyline is also quite engrossing and surprisingly well written – I like the non-linearity of it too. Recommended.

Going to stop now and do something useful like add scenery to Train Game.