git diff showing a weird output ^[[1;33m^[[mmmmh?!

I came back to an old project on another machine only to find that the git diff command did not behave as expected anymore:

^[[1;33mdiff --git a/myproject/myapp/models.py b/myproject/myapp/models.py^[[m
^[[1;33mindex 0216829..d9e1637 100644^[[m
^[[1;33m--- a/myproject/myapp/models.py^[[m
^[[1;33m+++ b/myproject/myapp/models.py^[[m
^[[1;35m@@ -87,6 +87,12 @@^[[m ^[[mclass DoomDoomDoom(models.Model):^[[m

Instead of showing the colours defined in ~/.gitconfig, it was displaying escaped sequences in black and white, as well as a "(stdin)" prompt at the bottom of the page.

At first I thought it was a difftool issue but actually it relates to the pager, i.e. with either of these commands things works well:

$ git --no-pager diff # No paging
$ git diff --color | less -R # With paging

The default pager in git is supposed to be 'less'... Still, making sure it actually is fixed this for me:

$ git config --global core.pager 'less'

I'm still annoyed. Why was a different pager being used (and not showing in git config --list) and what tool was it?

Leave a comment

wvdial: stackmaster assertion failure & EuroPython

At EuroPython, I happily took advantage of the prepaid SIM card that you could order together with your ticket. However tethering with Wind (Italy) was not to work that simply. On Debian Wheezy I ended up with the following error:

[...]
--> Modem initialized.
wvdial: utils/wvtask.cc:409: static void WvTaskMan::_stackmaster(): Assertion `magic_number == -0x123678' failed.

A bit of astute googling reveals that libwvstreams needs to be downgraded.

$ aptitude versions libwvstreams4.6-base # or apt-cache policy libwvstreams4.6-base
Package libwvstreams4.6-base:                        
p A 4.6.1-1                                       stable                    500 
i A 4.6.1-4                                       testing,unstable          500 
$ sudo aptitude install libwvstreams4.6-base=4.6.1-1

Tadam! wvdial now works. The same configuration as last year seems to do the trick (though on Fedora 16, the Network Manager's Mobile Broadband tool was easy to set up with Wind without  bothering with wvdial.)

[Dialer wind]
Modem Type = USB Modem
Modem = /dev/ttyACM0
Username = "wind"
Password = "wind"
Init6= AT+CGDCONT=1,"IP","internet.wind"
Leave a comment

Debugging udev rules under Debian

I've been playing with the Finch, however today I was unhappy to discover that the robot stopped working again for non-root users. The Finch documentation helpfully links to this blog post on how to write a udev rule, which is the script I was using in the first place.

SUBSYSTEM=="usb", SYSFS{idVendor}=="2354", SYSFS{idProduct}=="1111", MODE="0660", GROUP="plugdev"

Time to figure out how to debug udev rules! The debian wiki hints at a tool called udevtest, which doesn't exist on my system or in aptitude. Turns out nowadays one should use udevadm test instead. Here we go: thanks to lsusb I know that the Finch is on bus 001, device 007.

# udevadm test /dev/bus/001/007

In the output around the rules file for the finch, there is this:

add_rule: unknown key 'SYSFS{idVendor}' in /etc/udev/rules.d/55-finch.rules:1
add_rule: invalid rule '/etc/udev/rules.d/55-finch.rules:1'

Looking for documentation on how to write udev rules, one would find the following guide, which indicates that ATTR should be used instead of SYSFS. Let's rewrite the rule:

SUBSYSTEM=="usb", ATTR{idVendor}=="2354", ATTR{idProduct}=="1111", MODE="0660", GROUP="plugdev"

The error doesn't show in the udevadm test output anymore, and unplugging/replugging the Finch makes it usable by non-root users again. Victory!

Leave a comment | 3 so far

aptitude / apt-get limbo

A couple of weeks ago I started getting in trouble when trying to update my system (Debian Wheezy) via aptitude. A dozen or so packages were failing to configure, and while these failures occurred other packages couldn't install.

Output would contain things like this:

Setting up install-info (4.13a.dfsg.1-8) ...
/var/lib/dpkg/info/install-info.postinst: 32: /var/lib/dpkg/info/install-info.postinst: update-info-dir: not found
dpkg: error processing install-info (--configure):
 subprocess installed post-installation script returned error exit status 127
configured to not write apport reports
                                      Setting up gconf2 (2.32.4-1) ...
/var/lib/dpkg/info/gconf2.postinst: 52: /var/lib/dpkg/info/gconf2.postinst: gconf-schemas: not found
dpkg: error processing gconf2 (--configure):
 subprocess installed post-installation script returned error exit status 127
configured to not write apport reports
                                      dpkg: dependency problems prevent configuration of evolution:
 evolution depends on gconf2 (>= 2.28.1-2); however:
  Package gconf2 is not configured yet. [...etc... updaterc.d not found... update-initramfs not found...]

I'm not quite sure how or why that happened but it turned out to be a $PATH issue. Widespread problems that wreck systems tend to be small changes in one critical place, I find.

To debug it, I picked the first item not found:

$ locate update-info-dir
/usr/sbin/update-info-dir
/usr/share/man/man8/update-info-dir.8.gz
$ echo $PATH
<lots of stuff but not /usr/sbin>

From then on, append the missing directory to your $PATH in .bashrc, and/or you can also switch to the root user who hopefully would have a clean environment. $ dpkg --configure -a and you're flying again!

Leave a comment | 2 so far

Getting Hibernate (Suspend to disk) working Linux Debian Squeeze / Lenovo Thinkpad X201

Here's how I got Hibernate working on my Thinkpad X201, currently running Debian Squeeze.

First, make sure you have a swap partition at least as large as your RAM. Following that little incident last year, my swap had a different UUID and I never realised it was never mounted. Manually editing /etc/fstab following the useful blkid output did the trick.

Second, install uswsusp, helpfully discovered thanks to the ThinkWiki.

And that's it! Hibernate works, through the Shutdown menu and pm-hibernate, and so far Suspend doesn't seem to have been adversely affected. Woohoo!

Leave a comment

FOSDEM, over and out

Another fantastic edition of FOSDEM is now finished. Many thanks to the organisers for another great job!

Welcome talk, picture of the room

Amazingly, the Welcome talk managed to top off last year's FOSDEM dance, this time by making the audience contribute the music. I hope they do it again next year, it was kind of fun smashing hands on the wooden board (middle row, yep!)

Lift door with the writing: Today's recommendation: Make a friend. Smile at the person next to you.

Many stands, a ton of talks, even more people than last year. Some dev rooms remained closed because full for most of the conference, but surprisingly if one carefully planned which talks to attend and made sure to be there a little early, it was usually possible to get in and even grab a seat.

Lots of people standing outside

I'll post short summaries of some of the talks I attended. This year I took notes on my phone (my lovely lovely N900) for all talks but one. I also took more pictures, which is great (although the quality of the pictures isn't always). Looks like getting the phone out to snap a pic is less of an effort than having an actual camera to carry around, get out of the case etc.

A huge camel plush at a stand

This was my 3rd FOSDEM and this time I spent a bit more time on the social aspect, sometimes even skipping talks (gasp!) I cared a little bit less about to chat with interesting people. This is great, though it made the conference quite a bit more exhausting. Must balance better -- and find a nice hotel in a quieter neighbourhood.

Once again delighted with the experience. Until next year, FOSDEM! :)

A chocolate snowman

Leave a comment

Tethering on the N900

As FOSDEM (woohoo \o/) draws closer and the likelihood of spending a lot of time in the airport doesn't change, I thought it was time to find out how to use my N900 as a modem or for "tethering" as I'm told the proper word is.

Some background:

  • my laptop runs Debian Squeeze (unstable) -- the stable release is coming out this week-end by the way!
  • my phone carrier is Meteor (Ireland) and I use their 3G/GPRS connection for data.

Tethering via the USB cable

The official Maemo webpage makes it all sound real simple but it didn't quite work this way for me. The wizard did not appear either on Debian or when I tried on Ubuntu 10.10. Although the phone did show up in Network Manager -> Wired networks, it only displayed as Disconnected and I couldn't find any option to set up a new 3G network.

After many failed attempts, this is the approach that worked for me. It requires wvdial. One annoyance: it works once, then I need to unplug and re-plug the phone.

Here's the wvdial information for Meteor Ireland:

APN: data.mymeteor.ie
Username: my
Password: meteor

Tethering via Bluetooth

Emboldened by my success I decided to follow the link to the Debian wiki on how to set up the same using Bluetooth. I was very disappointed to see they recommend using a KDE app even under Gnome, and when I looked at the number of dependencies it would bring I thought I'd take my chance the Gnome way.

...I'll skip on the embarrassing moments where I was thinking Gnome 3 wasn't set up yet to handle Bluetooth then found out the Bluetooth service was actually turned off... *cough* I used the Bluetooth applet to pair with the phone and followed the rest of the instructions on the wiki page, until the rfcomm command brought up the following error.

Can't connect RFCOMM socket: Connection refused

Using "sdptool browse <N900_MAC_ADDRESS>" revealed that I did not have the "Dial up networking service" running on the phone. You actually need to install an extra app, available in the repos first (application name is: Bluetooth Dial-Up Networking). I then followed these instructions on the Maemo wiki to set up rfcomm.conf, until "Restart the bluetooth stack" in the first section, and ta-dah! With "wvdial bluetooth" I can now start the connection via Bluetooth.

To be honest I'm sure this is a battery drain nightmare and I can't imagine tethering without the cable but heh! I learnt about several new tools and if I ever need it, it's there :-)

Final wvdial.conf, in all its mighty glory

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Baud = 460800
New PPPD = yes
ISDN = 0
New PPPD = yes
Phone = *99***1#
Username = "my"
Password = "meteor"
Init6= AT+CGDCONT=1,"IP","data.mymeteor.ie"

[Dialer usb]
Modem Type = USB Modem
Modem = /dev/ttyACM0

[Dialer bluetooth]
Modem = /dev/rfcomm0
Leave a comment | 5 so far

Linux on the Lenovo ThinkPad X201

As anyone who's been within hearing range can tell you, I've acquired a new laptop recently that I've grown quite fond of. Here's my experience getting various Linux distributions working on it, your mileage may vary (e.g. my experience with Debian was widely different from others'). I ordered the laptop from the Lenovo website, the only significant specs change was to upgrade to the i5-540M processor.

Ubuntu 10.10

The latest version, Maverick Meerkat / 10.10 installed fine, no issues whatsoever.

Debian Squeeze

Debian is my main development distro and I absolutely needed it working on the laptop before setting up everything to be Just RightTM. Unfortunately, stable wouldn't boot, and the daily testing images were acting very weird, asking me for a password and, no matter what I typed, showing me an empty grub menu that slowly disappears up the screen.

Eventually I solved this thanks to UNetbootin, using it to create a LiveUSB from Debian unstable. I'm not quite sure how it does that, but whatever it did did the trick (yay!) and I was able to boot from the stick and install Debian off it. If you go this way, don't forget to update your apt sources.list to point to unstable. Also, Suspend works for the first time ever, wahoo :D Hibernate was a bit more moody, though it worked last time I tried it. The option seems to have disappeared from my menus a couple of weeks back, but I've been messing with various things including Gnome Shell, which may be related.

Fedora 13/14

The Fedora 13 stick seemed a bit reluctant to boot up fully, but did so after a couple of tries. The installer's partition editor wasn't playing so nice and I ended up using GParted first to create the partition (which led to entirely unrelated problems due to my own clumsiness). Once this was done everything was fine, including the wireless. When I was trying Fedora 14 prerelease in late October the stick booted fine, and since then I've upgraded to Fedora 14 without an issue either.

Sugar on a Stick (Mirabelle -- based on Fedora 13)

The stick does not boot :/ (Black screen with the grey blinking underscore on the top left). I must install Mango Lassi (based on Fedora 14) on a stick soon and check out if that works...


I still have more space than I need after installing those 3. I'll probably try to install a source-based distro as well, either Arch or Gentoo, not sure yet. Recommendations?

Leave a comment | 2 so far

Recovering a lost partition table Trial by fire

If your hard drives are currently doing fine and you're ready to skip this article, please just do this for me: run fdisk -l as root, maybe fdisk -u -l as well and store the output in a file on a usb stick or another machine. Thanks. That's the kind of thing you chuckle at until a twitch or update destroys your partition table and you're staring at a black screen with a blinking grey underscore instead of a boot screen, knowing that your data is there somewhere but the computer doesn't know where to find it. Neither do you. With that info you'll be able to recreate the partition table using fdisk or parted, following tutorials online.

Now let's assume you're like me and you don't have that data. Here are a few links and ideas that you can try out, most of which didn't work for me but all taken together ended up giving me a working system back. Arm yourself with a LiveUSB stick running Linux, and let's begin.

Try #1: gpart

Not to confuse with gparted, which by the way is the tool I messed up my laptop with. I was reading the menus wondering why the resize option was greyed out, when I had one of those finger twitches (too much caffeine?) and bam! An 'error' alert popped up and the layout of my hard drive changed to "Unallocated" -- and that was it. One twitch! I should try to reproduce the bug now that I have my fdisk output, but I'm not brave enough yet... (Working machines are so handy!)

...Anyhow. Gpart came with the recommendation that "it worked for me X years ago, and here's the actual web page I used to fix things", so I tried it. Gpart works non-destructively and tries to guess where your lost partitions start and end.

I'm afraid to say gpart failed miserably for me, only listing a 3Mb partition that I don't think actually exist, after a 2h run. It's still worth a shot, and won't do any harm if it doesn't work.

Resources:

  • Recovering a lost partition table, including what to do after gpart gives you back accurate looking information
  • Partition-Rescue HOWTO -- I was reading this while waiting for gpart to finish, it gives other tips on how to find/guess your partition table, including a command (cat /proc/partitions) that should work beautifully if you haven't rebooted the machine yet after erasing/losing the partition table
  • gpart -- A bit more information, example output, manpage, changelog

Try #2: Testdisk

Running testdisk (quick search)

Googling more I came across Testdisk, a very cool utility that do the same thing as gpart and then more, and is also available in the Fedora repositories. The most important thing I can say is to read the site carefully. I found the step by step guide especially useful. The commands are not always straightforward (p to list files?) but it's incredibly powerful and the second the "Quick search" started running it was already listing a fairly good idea of my 6 main partitions and their types.

Running testdisk (deep search)

I thought deep search wasn't working for me but reading the step by step guide, I realised it gives back potentially overlapping partitions and it's up to you to examine them to find the most likely one. Considering I could list the files off all my partitions after the quick search, I decided to give up on the deep search output and start again, using what quick search gave me as my best bet for writing a new partition table.

Writing the partition table

Select the Write option when you feel ready. This is not a destructive option either, in that if you get it wrong you can try running gpart or testdisk again, and write another table based on a different guess.

Win #1: Data backup

The new partition table didn't actually quite work for me. Windows wouldn't boot, and Grub was gone so I had no access to my Linux partitions. I booted off the LiveUSB stick again, and mounted the newly remade partitions from the 'Places' menu to back up the files I sort of cared about (this is a 1-week old laptop! Not much data).

chroot magic + grub

Making sure I only had one partition mounted (Ubuntu in this case), I chrooted into it from its mount point in /media.

chroot /media/1234-5678-90ab-cdef 

From there the idea was to use grub-install to reinstall grub. The hard drive I was trying to rehabilitate was /dev/sda, replace with the drive you want to fix.

grub-install /dev/sda

Now that didn't quite work for me. I forgot to write down the exact error messages, but it was complaining about not being able to write to /dev/null. This Ubuntu Forum post helped me solve that one, and by the way also contains more ideas to try out if you end up still grub-less.

Now, for the proper /dev directory to be picked up in your chroot environment:

mount -o bind /dev /media/1234-5678-90ab-cdef/dev

grub-install /dev/sda should now works handsomely :) Rebooting the machine, only Ubuntu was visible in the Grub boot menu. Running update-grub within Ubuntu resulted in an accurate list of every OS during the following boot, yay.

Note that I actually sort of lost a partition in the process, the OEM "Rescue partition" that Lenovo set up at the end of the drive. TestDisk picked it up properly, but this partition is supposed to run when pressing the blue ThinkVantage button, and wouldn't start anymore. I didn't feel too sorry and deleted it (one more primary partition slot for me!). I also had to recreate the swap partition, which is pretty minor.

Thanks TestDisk for saving the day! :)

Resources:

Leave a comment