Add new harddisk on the fly

So you have this linux box and you want to add an extra harddrive without having to reboot it. The key command we’re looking for, is a way to rescan the scsi bus. This can be achived by rewriting some values in the /sys synthetic filesystem:

echo "- - -" > /sys/class/scsi_host/host#/scan

Replace the digit for the scsi host as appropiate.

If everything went well, you should get output on the console indicating it detected a new hard drive.

Android USB debugging on openSUSE 11.4

Debugging your android app using a hardware device has several advantages, ie faster and more testing possibilities. On windows you have to install a custom USB driver, on linux it’s a matter of configuring your udev rules:

  • add a rules files in /etc/udev/rules.d , ie 44-android.rules
  • enter a line like this:
    SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="users"

    and adapt the vendor id using this table.

  • Reload udev rules: udevadm control --reload-rules

When you run adb devices, it should now list your device:

List of devices attached 
emulator-5554   device
SH14FPL06953    device

Before, you would rather have something like this:

List of devices attached 
emulator-5554   device
????????????    no permissions

On succesful connection, the system log shows something like:

kernel: [11172.551464] usb 2-1: USB disconnect, address 4
kernel: [11178.813044] usb 2-1: new high speed USB device using ehci_hcd and address 5
kernel: [11178.942137] usb 2-1: New USB device found, idVendor=0bb4, idProduct=0c87
kernel: [11178.942150] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
kernel: [11178.942157] usb 2-1: Product: Android Phone
kernel: [11178.942162] usb 2-1: Manufacturer: HTC
kernel: [11178.942166] usb 2-1: SerialNumber: SH14FPL06953
kernel: [11178.943867] scsi8 : usb-storage 2-1:1.0
mtp-probe: checking bus 2, device 5: "/sys/devices/pci0000:00/0000:00:04.1/usb2/2-1"
mtp-probe: bus: 2, device: 5 was not an MTP device
kernel: [11179.953172] scsi 8:0:0:0: Direct-Access     HTC      Android Phone    0100 PQ: 0 ANSI: 2
kernel: [11179.953375] sd 8:0:0:0: Attached scsi generic sg4 type 0
kernel: [11179.961631] sd 8:0:0:0: [sdd] Attached SCSI removable disk

Note that it seems normal that a usb storage device is detected, although I did not have it enabled on the phone.

Mouse locating kwin effects

Ever felt lost on your desktop? Or more precisely: unable to find your mouse pointer within a (few) second(s)? I know I have, and nowadays on 2 monitors or more (or a huge 48″ tv), this isn’t an exception.

In KDE, we always had the track mouse effect which draws circling yellow stars around your pointer. Unfortunately, this is not adequate anymore. That’s why I thought it would be fun to write my own effect which would do a better job. The key to success seems to me that it should be a full screen effect drawing the attention to the right spot no matter where at the screen you’re looking.

For now, I’ve devised 3 effects:

  1. Looney tunes zoom: fancy term for describing an effect which darkens the background and zooms in on the cursor with a spotlight. I somehow associated that with intro or outro from looney tunes, not sure if that makes sense. :p
  2. Sunray: animates some kind of rays around the mouse position.
    kwin sunray mouse locate effect
  3. Radial texture animation: least fancy name, as it is so generic. 🙂 It just animates a texture from outer to inner. The concrete application is to show arrows pointing to the mouse.
    kwin arrow mouse locate effect

For the last 2 effects, I don’t have screencasts yet, don’t ask, I’ve been through hell to create the first one. Also, for the last one, I have to fix the texture uv map generation, or use a better mesh (or maybe a different technique 🙂 ).

Convert PDF to image files

Another entry in my PDF series. 🙂

At work I had to convert a few PDFs into jpeg files. The PDF files actually contain just images, so extracting the images would’ve been as good, but converting PDF pages to images is easier. 🙂 At least on windows. On linux you could use pdfimages, which should be available for your distro through some poppler util package.

A general approach is to use the versatile ImageMagick software. Using the convert command, it’s simply a matter of:

convert -density 200x200 -quality 85% inputfile.pdf outputfile%03d.jpg

to convert inputfile.pdf to a set of jpeg files. Of course you can choose any supported output format you like: png/bmp/gif/etc.. The density option is important as it specifies the output dpi which is only 72 by default. Imagemagick uses Ghostscript to do the pdf reading, so on windows you have to make sure that environment is set up correctly. In my case I had to add its bin directory to the path and set the working dir to the lib path as it didn’t find otherwise (adding to the path didn’t help). If you know a better way, please let me know in the comments. I also specified the quality option to have a jpeg quality factor of 85, which is 75 by default.

Since I had to process a batch of them, I thought it would be nice to have a cool batch script to do them automatically. Here is what I came up with:

set path=%path%;C:\programs\gs\gs8.54\bin
cd C:\programs\gs\gs8.54\lib
for %%C in (%*) do call :startconvert %%C
goto :eof

convert -density 200x200 -quality 85%% %1 %~dp1%~n1%%03d.jpg
goto :eof

Replace the paths as appropiate. To use the bat file, simply drag and drop one or more pdf file on the bat file. It will put jpeg files in the same directory as the pdf file and number them using 3 digits (%03d printf format). %~dp1 stands for the full path of the 1st argument file, %~n1 for the name only (without extension). Also note you have to escape all other %’s.

Getting mic to work with NVidia VT1708S

Ever since I installed opensuse 11.3, I hadn’t used my mic/headset. Today I decided to fool a bit around in Ardour, but somehow my mic didn’t work. And alas, I made a classic beginner’s mistake: “the solution has to be difficult because it does not work out of the box”.

I tried the standard stuff like trying out all input sources, adding hidden channels, etc. but when that didn’t help I was quickly diving into custom .asoundrc configuration, arecord/aplay sysinfo scripts, probing kernel modules, looking into alsa upgrade scripts and the like.. 🙂

Until I had an epiphany while reading random forum post words. I had been adding the “hidden” channels to my mixer which indeed included “mic” and “front mic” with accompanying boost controls. I noticed a few others which I threw in as well for good measure. I neglected them though, as I didn’t feel interested in enabling “smart” 5.1 or IEC958 2, whatever that was. But then I suddenly remembered: motherboards come with configurable audio backpanels, so this wasn’t really about enabling a fancy audioprocessing feature but rather switching between the 5.1 and standard audio panel, duh!

Apparently, the 5.1 was enabled by default, so “muting” it solved my problem!

Btw, in case you wonder: the HDA NVidia VT1708S chipset is actually a HDA Intel chipset with VIA codec, hence the VTxxxx name. To keep things intesting. 😉

I <3 libpcap

A few years ago, I wrote a small app showing the open network connections (announcement following shortly). I never figured out how to measure transfer rates over the connections since the kernel does not seem to provide this info through the /proc filesystem (only some data queue length which is related to kernel mem usage).

Today we all know and love iftop, but where does it get that info? Simple: pcap! Out of curiosity, I checked out the libpcap docs to see how hard it would be to get started. Turned out to be pretty simple! There are a few excellent tutorials which get you started real fast. In about half an hour I made this very simple sniffer which accumulates the received bytes and packets per second and prints it out when the second changes. Each line contains the timestamp (sec), KB/s and number of packets received in that second. Here you can see me watching a youtube vid 🙂

Opening device eth0
ts = 1285276934, load = 0.7 KB/s (4)
ts = 1285276935, load = 0.3 KB/s (1)
ts = 1285276939, load = 0.9 KB/s (4)
ts = 1285276940, load = 14.4 KB/s (44)
ts = 1285276941, load = 294.9 KB/s (764)
ts = 1285276942, load = 608.9 KB/s (1505)
ts = 1285276943, load = 1164.4 KB/s (2882)
ts = 1285276944, load = 1242.6 KB/s (3064)
ts = 1285276945, load = 1166.6 KB/s (2880)
ts = 1285276946, load = 69.9 KB/s (179)
ts = 1285276947, load = 140.1 KB/s (363)
ts = 1285276948, load = 139.9 KB/s (361)
ts = 1285276949, load = 139.7 KB/s (358)
ts = 1285276950, load = 139.7 KB/s (358)
ts = 1285276951, load = 139.3 KB/s (358)

It is a good test to see if the calculated payload is correct. The initial burst of ~1.2MB/s confirms that. 🙂

Configuring numlock indicator in KDE4

My brother has this really neat wireless keyboard with built-in trackball for his mediacenter. There is only one downside: it doesn’t have a numerical keypad and you never really know if the numlock is on or off. I think it is off at boot, but after turning it on and logging on, it is off again, unless you did a reboot.. or something like that.. Anyway, since it can be quite a challenge to enter passwords correctly, I started looking for a numlock plasmoidish solution.

First thing that turned up in the searches was the Keyboard Status applet. However, in the comments someone rightfully asks why it doesn’t use the keystate DataEngine. Great idea, because this is already packaged with vanilla kde. So I started searching for a general LED plasmoid which I could connect any datasource to using some mapping. No such luck. But then I wondered: why would someone write a plasma DataEngine and then not use it? 🙂 There must be some existing plasmoid! It turned out to be the Key State plasmoid which is currently hosted at gitorious.

Since it is a javascript plasmoid, you can install it as follows:

git clone git://
plasmapkg -i keystate

Done! It should now be in the list when adding plasmoids under the name “Key State”. You can configure a custom color for each special key. There are some advanced options as well which I didn’t try out. Here is what it looks like:

Key State plasmoid

A simple rectangle shows my numlock is active. I know, nothing fancy but it’s all we need and it does the job! Thank you Martin Blumenstingl. 🙂

Fullscreen games and Nvidia TwinView

Today, I decided to play a game on my suse box for the first time since I have my “new” game rig. I didn’t play any games under linux lately since Microsoft gave us a free windows 7 RC. 😉 I decided to play some Urban Terror but a few hurdles needed to be taken first.

First one: some time ago I managed to screw up my glx acceleration, yielding a “Unable to create SDL screen: Could not create GL context” error. So I installed the latest nvidia binary driver which detected the screw up and fixed it for me.

Second: I have 2 monitors connected: one CRT on the left and one LCD on the right. The LCD is the primary (which confuses some apps). Anyway, when starting an SDL game like Urt, it only sees one monitor (the “beauty” of nvidia twinview 😉 ) and projects its graphics somewhere half-way the primary screen with all the rest left black. I.e. unusable. As I understand it’s an Nvidia problem as they do not obey the rules of the game (meaning xrandr and consorts) for which they had their reasons too (at least back in the day).
Anyway, to solve it, let’s have a look at my original xorg config, or rather the relevant metamode line:

Option "metamodes" "CRT: 1280x1024_85 +0+0, DFP: 1680x1050_60 +1280+0"

We can see there is one mode defined with my crt on the right and my LCD on the right (+1280). The solution is to simply add a second mode in which we disable the CRT and to switch to that mode using the mode cycle shortcut ctrl+alt+”+” before starting a game. When you’re down switch back to your first mode.

Option "metamodes" "CRT: 1280x1024_85 +0+0, DFP: 1680x1050_60 +1280+0;NULL,DFP:1680x1050_60"

You can add as many modes as you want for your different gaming setups. 😉 It’s not ideal, but it does the trick and it even maintains my full desktop resolution (so apps don’t get confused or icons get misplaced) which you can access by “scrolling” on the side.

Third problem: no matter how I tweaked the framerate cap, vertical sync or other graphics settings, I didn’t achieve the smooth framerate I’m used to from Windows or previous linux installs. Somehow the framerate was really high but not entirely smooth. I tried playing online and had a horrible aim. If I didn’t know it ran flawlessly on my old suse box with ATI radeon 9800 pro, I would have stopped looking. Then I realised: let’s try disable desktop compositing. Problem solved! Smooth framerate, 0wnage ensued.

btw: nowadays, Urt’s master server is down. I created an autoexec.cfg in ~/.q3a/q3ut4/ with the line:


Last problem solved. 🙂