Archive for the 'Linux' Category

Patching K3B on Kubuntu Hardy Heron

Tuesday, May 6th, 2008

I’ve recently built a new desktop machine - the subject of another post when I get time - and because the hardware is fairly recent I decided to try Ubuntu which I knew would support it rather than switch to an unstable branch of Debian.

My first impressions of Hardy Heron - Ubuntu’s latest release; I’m using the variant with the KDE desktop - are very positive. The installer is excellent and the hardware detection very impressive. As a comparison, it took me the better part of a day to install a fairly vanilla Windows XP Pro SP2 on the first partition of the box. Nearly every driver install required a reboot as did many of the security updates. By contrast, it took less than an hour to download and install Kubuntu and the installation includes a far greater range of packages than I have on the windows partition.

The one fly in the ointment has been a problem with K3b. If I started with a blank CD in the drive, all was fine but launching it with either an empty drive or a blank DVD caused the process to hang for a long while and finally launch with the warning:

“No CD/DVD writer found.
K3b did not find an optical writing device in your system. Thus, you will not be able to burn CDs or DVDs. However, you can still use other K3b features like audio track extraction or audio transcoding or ISO9660 image creation.”

After this the DVD drive was disabled, making it impossible to even eject until the machine had been shutdown completely and restarted.

Both growisofs and wodim worked from the command line so the problem had to be in the KDE application. Launching K3B from the console reveals debug information and showed the hang up was occurring after the step checking for RAW_R96R:

...
(K3bDevice::Device) /dev/scd0: checking for RAW_R96R

After a long pause the process would continue:

(K3bDevice::ScsiCommand) failed:
                           command:    GET PERFORMANCE (ac)
                           errorcode:  72
                           sense key:  NO SENSE (2)
                           asc:        0
                           ascq:       3
(K3bDevice::Device) /dev/scd0: GET PERFORMANCE length det failed.
(K3bDevice::ScsiCommand) failed:
                           command:    MODE SENSE (5a)
                           errorcode:  0
                           sense key:  NO SENSE (2)
                           asc:        0
                           ascq:       0
(K3bDevice::Device) /dev/scd0: MODE SENSE length det failed.
(K3bDevice::ScsiCommand) failed:
                           command:    MODE SENSE (5a)
                           errorcode:  0
                           sense key:  NO SENSE (2)
                           asc:        0
                           ascq:       0
(K3bDevice::Device) /dev/scd0: MODE SENSE with real length 65535 failed.
(K3bDevice::Device) could not open device /dev/scd0 for reading
                    (No such device or address)
Error while retrieving capabilities.
Could not initialize device /dev/scd0
Could not resolve /dev/scd0
/dev/scd0 resolved to /dev/scd0
(K3bDevice::Device) could not open device /dev/scd0 for reading
                    (No such file or directory)
could not open device /dev/scd0 (No such file or directory)
Devices:
------------------------------
kdecore (KAction): WARNING: KActionCollection::operator+=(): function is severely deprecated.
removing udi /org/freedesktop/Hal/devices/pci_8086_2922_scsi_host_0_scsi_device_                                                                                                                                                 lun0_scsi_generic
removing udi /org/freedesktop/Hal/devices/pci_8086_2922_scsi_host_0_scsi_device_                                                                                                                                                 lun0
removing udi /org/freedesktop/Hal/devices/pci_8086_2922_scsi_host_0
removing udi /org/freedesktop/Hal/devices/storage_model_DVDRW_LH_20A1S
Unmapping udi /org/freedesktop/Hal/devices/storage_model_DVDRW_LH_20A1S from dev                                                                                                                                                 ice /dev/scd0

dmesg reveals the following occuring

May  1 23:52:15 mingus kernel: [ 3580.143800]          cdb ac 00 00 00 00 00 00 00  00 01 03 00 00 00 00 00
May  1 23:52:15 mingus kernel: [ 3580.143801]          res 40/00:03:00:00:00/00:00:00:00:00/a0 Emask 0x4 (timeout)
May  1 23:52:15 mingus kernel: [ 3580.455532] ata6: soft resetting link
May  1 23:52:15 mingus kernel: [ 3580.619411] ata6: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
May  1 23:52:45 mingus kernel: [ 3610.751976] ata6.00: qc timeout (cmd 0xa1)
May  1 23:52:45 mingus kernel: [ 3610.751985] ata6.00: failed to IDENTIFY (I/O error, err_mask=0x5)
May  1 23:52:45 mingus kernel: [ 3610.751993] ata6: failed to recover some devices, retrying in 5 secs
May  1 23:52:50 mingus kernel: [ 3615.752086] ata6: hard resetting link
May  1 23:52:56 mingus kernel: [ 3621.263794] ata6: port is slow to respond, please be patient (Status 0x80)
May  1 23:53:00 mingus kernel: [ 3625.752312] ata6: hard resetting link
May  1 23:53:06 mingus kernel: [ 3631.268013] ata6: port is slow to respond, please be patient (Status 0x80)
May  1 23:53:11 mingus kernel: [ 3635.804490] ata6: hard resetting link
May  1 23:53:16 mingus kernel: [ 3641.316197] ata6: port is slow to respond, please be patient (Status 0x80)
May  1 23:53:46 mingus kernel: [ 3670.813264] ata6: limiting SATA link speed to 1.5 Gbps
May  1 23:53:46 mingus kernel: [ 3670.813266] ata6: hard resetting link
May  1 23:53:51 mingus kernel: [ 3675.821377] ata6.00: disabled
May  1 23:53:51 mingus kernel: [ 3675.821404] ata6: hard resetting link
May  1 23:53:57 mingus kernel: [ 3681.736761] ata6: port is slow to respond, please be patient (Status 0x80)
May  1 23:54:01 mingus kernel: [ 3685.825584] ata6: hard resetting link
May  1 23:52:15 mingus kernel: [ 3580.143800]          cdb ac 00 00 00 00 00 00 00  00 01 03 00 00 00 00 00
May  1 23:52:15 mingus kernel: [ 3580.143801]          res 40/00:03:00:00:00/00:00:00:00:00/a0 Emask 0x4 (timeout)
May  1 23:52:15 mingus kernel: [ 3580.455532] ata6: soft resetting link
May  1 23:52:15 mingus kernel: [ 3580.619411] ata6: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
May  1 23:52:45 mingus kernel: [ 3610.751976] ata6.00: qc timeout (cmd 0xa1)
May  1 23:52:45 mingus kernel: [ 3610.751985] ata6.00: failed to IDENTIFY (I/O error, err_mask=0x5)
May  1 23:52:45 mingus kernel: [ 3610.751993] ata6: failed to recover some devices, retrying in 5 secs
May  1 23:52:50 mingus kernel: [ 3615.752086] ata6: hard resetting link
May  1 23:52:56 mingus kernel: [ 3621.263794] ata6: port is slow to respond, please be patient (Status 0x80)
May  1 23:53:00 mingus kernel: [ 3625.752312] ata6: hard resetting link
May  1 23:53:06 mingus kernel: [ 3631.268013] ata6: port is slow to respond, please be patient (Status 0x80)
May  1 23:53:11 mingus kernel: [ 3635.804490] ata6: hard resetting link
May  1 23:53:16 mingus kernel: [ 3641.316197] ata6: port is slow to respond, please be patient (Status 0x80)
May  1 23:53:46 mingus kernel: [ 3670.813264] ata6: limiting SATA link speed to 1.5 Gbps
May  1 23:53:46 mingus kernel: [ 3670.813266] ata6: hard resetting link
May  1 23:53:51 mingus kernel: [ 3675.821377] ata6.00: disabled
May  1 23:53:51 mingus kernel: [ 3675.821404] ata6: hard resetting link
May  1 23:53:57 mingus kernel: [ 3681.736761] ata6: port is slow to respond, please be patient (Status 0x80)
May  1 23:54:01 mingus kernel: [ 3685.825584] ata6: hard resetting link
May  1 23:54:07 mingus kernel: [ 3691.752971] ata6: port is slow to respond, please be patient (Status 0x80)
May  1 23:54:11 mingus kernel: [ 3695.841797] ata6: hard resetting link
May  1 23:54:17 mingus kernel: [ 3701.757192] ata6: port is slow to respond, please be patient (Status 0x80)
May  1 23:54:46 mingus kernel: [ 3730.858562] ata6: limiting SATA link speed to 1.5 Gbps
May  1 23:54:46 mingus kernel: [ 3730.858565] ata6: hard resetting link
May  1 23:54:51 mingus kernel: [ 3735.884188] ata6: EH complete
May  1 23:54:51 mingus kernel: [ 3735.884287] ata6.00: detaching (SCSI 5:0:0:0)

It looks like the bug is probably in the libsata code failing to handle an error rather than K3B but I haven’t had a chance to investigate further.

As a quick workaround, download the k3b source and hack bool K3bDevice::Device::getSupportedWriteSpeedsViaGP to return false immediately and shortcircuit the call to ioctl that locks the device. The code will fall back to setting a maximum speed determined by the previous call to getSupportedWriteSpeedsVia2A.

Using Mutt with Exim4 to Send Mail via Smarthost over SSL (TLS) Connection on Port 465

Monday, November 26th, 2007

One day I’ll learn pine and I’m sure I’ll love it but for now I’m hooked on mutt.

Getting mutt to use exim4 for delivery is as simple as adding set sendmail="/usr/sbin/exim4" to your ~/.muttrc. Getting exim4 working as a smarthost to authenticate over port 465 is far harder.

The solution is to use a tunnel as outlined in this excellent post: exim4 with ssmtp on Debian.

Before finding this answer, I also discovered a very clear post on testing an smtp auth connection here and a useful tutorial on setting up and testing exim, both of which may be helpful to other people.

Debian Tip: How to Backup Installed Package List Before Reinstall/Upgrade

Sunday, October 14th, 2007

Many thanks to Renato for the following useful tip:

On your existing box:
COLUMNS=180 dpkg -l | awk '{print $2}' | xargs > /tmp/t

Then (having backed up then restored the list to /tmp/t, on the new install:
apt-get install `cat /tmp/t`

Migrating Emails from One IMAP Provider to Another

Sunday, May 20th, 2007

I have finally tired of mailsnare’s poor customer service. For a long while, the only way to get a response to a ticket was to post on the forums and publicly shame them into responding. Then they deleted the forums.

After trying several candidates, I have finally settled on webmail.us.

There are IMAP providers out there offering more bells and whistles but webmail.us advertises 99.99% uptime and offers 24 hour support by email, web or phone. With that kind of service, I can live without cutting edge, alpha-geek features that aren’t much use when the email server has been down for three days and no one is responding to requests for service…

Migrating several years worth of email from one imap provider to another has proved a little trickier than expected.

The low-tech solution is to set up Thunderbird to check both accounts and drag messages from one to the other. Unfortunately you cannot create folders on dragging which makes it necessary to manually create all target folders. Moreover, if you interupt the copy process (for example by opening another folder) then it is aborted and not all messages will be copied across. This grows old very quickly.

Enter imapsync to the rescue.

Syncing the two accounts over ssl is as simple as:

imapsync --host1 mail.mailserver1.com --user1 username1 --password1 secret1 --host2 mail.mailserver2.com --user2 username 2 --password2 secret2 --ssl1 --ssl2

All necessary folders are created in the second account and flags and datestamps are preserved. The man pages are very comprehensive and deserve close reading.

Debian Etch contains the package by default and apt-get will handle all the perl dependencies. (Etch also includes a similar tool imapcopy which looks promising but I have yet to try it.) Users of other distros - or operating systems - should try the imapsync project page.

Edit - I did run into a problem with messages being copied more than once on subsequent reruns of imapsync.

This was easily solved by following the advice in the FAQ. Some IMAP servers add headers for each message transfered so each time you run the process, imapsync thinks all the messages are new. Rather than dig through the headers to work out exactly where this was happening, I took the lazy option and instructed imapsync to just use the Message-ID header when comparing messages and to ignore any size changes.

imapsync ... --useheader 'Message-ID' --skipsize

Voila. Four and half years worth of email effortlessly transfered from one IMAP account to another.

Chickenfoot

Saturday, March 24th, 2007

David MacIver drew my attention to Chickenfoot today: “a Firefox extension that puts a programming environment in the browser’s sidebar so you can write scripts to manipulate web pages and automate web browsing.” It sounds like a slightly better Greasemonkey (although I must admit I haven’t touched Greasemonkey for a long time and it has no doubt changed since then.)

Being unable to install it was the final straw in making me decide to upgrade firefox. I’ve been running the default debian version out of a combination of laziness and paranoia about security but in the last few months I’ve really began to notice how out of date it is. More and more sites have been crashing my browswer. Fewer and fewer extensions have been working. But like the proverbial frog in the pan of boiling water, I have noticed all this happening but failed to jump out.

Turns out it was very simple to do. I just added backports my /etc/apt/sources.list

deb http://www.backports.org/debian sarge-backports main

then

apt-get update && apt-get install firefox -t sarge-backports

Now I’m finally able to install Chickenfoot but I haven’t played with it yet because I’m catching up on the 1000+ unread posts in bloglines that I haven’t been able to read for months since the sites last upgrade made it crash my browser.

Patching Eclipse 3.2 for Debian 3.1

Saturday, July 1st, 2006

Eclipse 3.2 is out but I haven’t had much of a chance to look at it yet because I’ve spent the afternoon trying to get it to install.

The GTK focus bug from 3.1 is still present (the problem lies with Debian’s use of version numbers) so you need to download the source, patch it and compile it for your own platform. (Instructions here.)

Compilation proved a little trickier than it was for 3.1. As before you need to edit plugins/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java - feel free to use my patch from the root of your unzipped source:

$ patch -p0 < debGTKBugPatch

I couldn’t get the default build to work but finally got things compiling (ignoring literally hundreds of warnings about non-type safe generic code) by editing the build.xml file and changing javacSource and javacTarget to 1.5 (I only have Java 1.5 on my machine: it should be possible to compile at least some of the source using Java 1.4 but I haven’t tried it)

<property name="javacSource" value="1.5" />
<property name="javacTarget" value="1.5" />

Finally start the build process and go and do something else for a while (on my ageing P4 1.8 it takes close to 50 minutes to build).

$ export ANT_HOME=/usr/bin/ant
$ export JAVA_HOME=/usr/
$ chmod +x build
$ ./build -os linux -ws gtk -arch x86 -java5home /usr/bin/

The custom built version will be in result/linux-gtk-x86-sdk.tar.gz. Extract it into another directory and run eclipse from there.

These notes explain how I got it to work on my machine. Your setup may differ.

Python for Series 60

Sunday, June 11th, 2006

To give myself a break from my studies, I’ve been exploring writing code for my mobile phone. I bought a Series 60 phone at Christmas from a high-street store planning to learn how to program it. Instead I ended up wasting most of the holidays dealing with Carphone Warehouse’s appalling customer service.

(It’s a long story. In brief, the salesman lied to me and sold me the phone on a tariff that was unusable with the handset meaning I couldn’t get network access on it. His manager, an unhelpful thug, refused to accept the return of the phone. It took close to 40 hours of phone calls, letters, emails and visits to stores to cancel the contract and get my money back. The experience left a very bitter taste in my mouth. I will never use Carphone Warehouse again.)

I’ve only scratched the surface of developing C++ apps for Symbian so far but while searching for a way to read GSM cell info (according to the forum posts it looks as if the API is restricted to registered developers who pay) I found that it was simplicity itself to get this data using Python for Series 60.

Learning Python is (yet another) thing on my todo list and after installing it on the phone and trying out a few sample scripts from the web I’m eager to do so.

Although it’s easy to code on your pc and send the finished script to your phone via bluetooth, there is also a way to code directly on the phone from your machine by using the bluetooth console that is included with Nokia’s python installer.

Assuming you have bluetooth up and running already on your Debian box:

$ sdptool add --channel=2 SP
Serial Port service registered
$ rfcomm listen /dev/rfcomm0 2
Waiting for connection on channel 2

Now start python on the phone and select bluetooth console from the options.

Connection from 00:16:4E:CD:09:06 to /dev/rfcomm0
Press CTRL-C for hangup

In a new terminal on the machine start minicom with the following flags

$minicom -s -m

then choose “Serial Port Setup” and set the Serial Device to “/dev/rfcomm0″ and you’re ready to run.

Test with:

import appuifw
appuifw.note(u'Hello world!', 'info')

You should get a “Hello world!” info box popping up on your phone screen.

Now for something more interesting, print the gsm location details of your nearest cell (see how simple this is):

import location
print(location.gsm_location())

Finally to send a text message (replacing 0000000000 below with the real destination number) :

import messaging
messaging.sms_send("0000000000", u"Hello there")

I can see Python coming in very handy for creating rapid prototypes of applications and/or simple applications for private use only. Although I find the low level details you need to know for C++ development fascinating, there’s something undeniably satisfying about being able to write an application that does something powerful in only two or three lines of code.

Brother HL-2030 Printer on Debian

Tuesday, June 6th, 2006

Just bought a new mono laser printer, the Brother HL-2030 and setting it up on Debian was simplicity itself thanks to excellent driver support.

Hop over to the Brother Linux Driver Homepage and follow the appropriate links to download the LPR and CUPS wrapper drivers.

As the FAQ warns, you’ll need a temporary symlink to get the CUPS wrapper to install:

$ dpkg -i brhl2030lpr_1.1.2-3_i386.deb
$ ln -s /etc/init.d/cupsys /etc/init.d/cups
$ dpkg -i cupswrapperhl2030_1.0.0-1_i386.deb
$ rm /etc/init.d/cups

and you’re done.

The drivers are GPL too. No closed source binaries here. Well done Brother! It’s a great printer too and very reasonably priced.

Not Bashing Windows

Monday, May 15th, 2006

Whenever I use Windows, I really miss the power of the command line.

I’ve recently had to convert a number of wav files to mp3s. From bash it’s as simple as:

for i in *wav; do lame -h $i `echo $i | sed -e "s/wav/mp3/g"`; done

I’d hate to do that via a GUI.

Conditional Branching Based on Return Values in Bash

Thursday, April 13th, 2006

In bash, the return value of a called program is stored in a variable called $?

grep returns zero on a succesful match, one on no match and minus one on an error. Being able to read this return value enables easy conditional branching based on pattern matching, eg:


#/!bin/bash
# Branch based on pattern matching
PATTERN=$1
FILE=$2
grep $PATTERN $FILE > /dev/null
if [ $? -eq 0 ]; then
echo $PATTERN found
echo Now do something to $FILE
else echo Skipped $FILE
fi

Sure, you could use Perl or another more sophisticated scripting language to do this but the bash shell is powerful enough for most tasks.