port redirection from kvm host to guest

By Adam, January 23, 2012 2:58 am

I’ve just started using kvm in earnest, and immediately ran into the challenge of how to access my guest via ssh. My first instinct was to configure the guest in bridged mode, but this doesn’t work well (or at all) with wireless interfaces.

So plan B was to set up port redirection from the host to the guest, e.g. so that ssh’ing to localhost port 2222 would redirect to the guest’s port 22.

After a quick google, some fiddling with iptables, and a glance at the libvirt Networking wiki page, I was still having no luck. Then it hit me – my guest was using user-mode networking, and rather than getting its DHCP-allocated IP from the libvirtd-launched dnsmasq instance on the host, was receiving a hardcoded allocation of 10.0.2.15 from the host which is on 10.0.2.2. This can be extremely puzzling at first, because no network commands run on the host (such as ifconfig, iptables, brctl, route) will reveal this magic address, yet the host is still accessible from the guest via it.

After a lot more googling, I stumbled across a technique for configuring host to guest port redirection on a running VM. This sounded very promising, but virt-manager refused to accept the magic Control-Alt-2 key combination to switch to QEMU monitor mode. It turns out that this is no accident. However, since libvirt 0.8.8, the QEMU monitor can be accessed via virsh.
Note that the --hmp option is required, otherwise the monitor expects the command in JSON format, so omitting it leads to errors like error: internal error cannot parse json ... lexical error: invalid char in json text.

The final hurdle was figuring out the correct monitor command. The host_net_redir command as mentioned in the above article is no longer recognized. Luckily the QEMU monitor interface helped me out here – I spotted an encouraging sounding command hostfwd_add:

# virsh qemu-monitor-command --hmp sles11 'help hostfwd_add'
hostfwd_add [vlan_id name] [tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport -- redirect TCP or UDP connections from host to guest (requires -net user)

and google confirmed that the latter had superceded the former.

So finally we have the complete solution:

# virsh qemu-monitor-command --hmp sles11 'hostfwd_add ::2222-:22'
# ssh -p 2222 localhost
Password:
Last login: Mon Jan 23 00:37:44 2012
linux-mnsh:~ #

Hooray!

UPDATE: just found another very simple solution – add a new NIC to the VM which doesn’t use user-mode networking. Then it will get a IP (on 192.168.100.0/24 by default) which is still NAT’d but also routable via virbr0 on the host, meaning no redirection is necessary; just ssh directly to the guest’s IP from the host. A minor disadvantage of this is that the guest won’t be directly reachable from outside the host, but that’s unlikely to be an issue in most scenarios.

Share

Linux desktop community “outraged” by latest Torvalds comments

By Adam, November 29, 2011 4:40 pm

Once again, users and developers all around the Linux desktop community have been provoked by controversial comments from Linus Torvalds, creator and long-time maintainer of the Linux kernel. Back in October, Linus dubbed GNOME 3 an “unholy mess”, referring to one of the changes as “crazy crap” and demanding “I want my sane interfaces back”. Since then he has gone even further, contending that “for some people, a stable, flexible functional desktop environment is far more important than the latest eye candy or trendy minimalist UI design.”

Reaction from the desktop development community has been swift and mostly unapologetic. Mark Shuttleworth, the founder of Canonical, responded “Once again, Linus is underestimating the importance of aesthetics in computing. You only have to look at Apple to see that people place more importance on visual beauty than the kind of efficient work processes that a flexible and reliable desktop environment enable. This is why we’re pushing our new Unity launcher as a mandatory part of Ubuntu. We’re confident that people will quickly overcome the initial shock of everything taking longer to find and access because they’ll be too busy admiring how beautiful it looks.” He then cited the latest 11.10 release as an example of this. “If you look in the release notes for [Oneiric Ocelot], you’ll see a new Alt+Tab switcher at the top of the list of highlights, and below it other radical changes such as renaming ‘Places’ to ‘Lenses’. Frankly, most people lap up this whizzbang shit, and as long as it looks cooler than their friend’s Windows 7 netbook they’ll be willing to tolerate some minor annoyances which are unavoidable when making immature software a critical component of the desktop. Sure, we could prioritise boring bug-fixing over innovation, but that just doesn’t excite the teenagers on the web forums, and we have to think about the next generation of users. Besides, if you want a dumbed down system that mostly works, there’s always Mac OS X.”

Havoc Pennington, a GNOME developer well-known for initiating the war on Linux desktop flexibility by drastically reducing the number of preferences and replacing GNOME’s default window manager, the high-performance scriptable Sawfish, with Metacity, commented: “It’s about achieving the right work/play balance. If your desktop allowed you to get stuff done too quickly, it would just increase your stress levels. Some ‘power’ users think they want to be able to stream-line their workflows, but we know better, so we are doing them a favour by making this customizability harder. After all, everyone needs basically the same things. Rather than trying to be different, these people should instead learn to enjoy the cute visuals and focus more on having fun. Life’s more than just work, work, work, you know.”

The KDE camp has been slightly less vociferous, perhaps because it’s old hat for them – back in 2008 they pioneered the concept of intrusive redesigns and ended up the wrong end of one of Linus’ rants as a result. “With KDE 4.0, we did our best to prevent people achieving real work, and I think we largely succeeded”, one of the KDE team leaders recalls. “I mean, there was a significant period of time where neither the KDE3 version of knetworkmanager nor its KDE4 rewrite worked properly, so for many wireless networks, the only way you could connect was to disable NetworkManager and write a shell-script to interface directly with wpa-supplicant and ifup. And that’s just one small example.”

Despite Torvalds’ comments, the move towards form over function has been witnessed elsewhere outside the desktop software space. For example, Apple have introduced the MacWheel, a move so bold that it makes innovations such as Unity and the GNOME Shell look positively conservative. However there is no clear industry-wide consensus; in fact companies such as Ebay and Sony are beginning to experiment with rejecting both form and function, turning conventional wisdom on its head.

Share

Running Amazon MP3 downloader on 64-bit Ubuntu 11.04 (Natty Narwhal)

By Adam, September 25, 2011 3:00 pm

Amazon MP3 store – a phenomenonly popular online music store. Ubuntu – a phenomenonly popular version of Linux. 64-bit x86_64 CPUs – been around for years. You’d think this was a good combination, wouldn’t you? Wrong :-( Amazon, along with Spotify and countless others, is dismally failing to support its rapidly growing set of customers who run Linux. As I’ve said elsewhere, even if 2% of your customers use Linux, that can still be a huge number. Hopefully some day these big companies will acquire some common sense.

Anyway, in the mean time a quick google brought up the following solution:

Unfortunately it doesn’t work – the step which installs the manually downloaded .deb files fails due to broken dependencies. However further googling found a post from 2008 which revealed a technique based on the very useful getlibs utility.

So here’s my solution:

  1. Download the 32-bit Amazon downloader app for Ubuntu 9.10.
  2. Run sudo dpkg -i --force-all AmazonMP3DownloaderInstall.deb
  3. Run sudo apt-get install getlibs if you don’t already have getlibs installed.
  4. Run sudo getlibs /usr/bin/amazonmp3 and answer yes to the confirmation.

At this point if you try to run /usr/bin/amazonmp3 you’ll probably hit Ubuntu bug 781870. The workaround is as follows:

export GDK_PIXBUF_MODULE_FILE=/usr/lib32/gdk-pixbuf-2.0/2.10.0/loaders.cache
/usr/bin/amazonmp3

You’ll still get an error that it’s trying to load the 64-bit version of libgvfsdbus.so thanks to Ubuntu bug 369498. I had hopes that export GIO_EXTRA_MODULES=/usr/lib32/gio/modules would fix this, but it seems that this variable only gets honoured too late. However, apparently this issue doesn’t stop the program working so can be ignored.

Another option is to use Banshee’s built-in Amazon downloader, but even without all the politics surrounding Ubuntu’s version of Banshee this didn’t suit my tastes.

UPDATE: Wow. Just found out Amazon doesn’t support re-downloading stuff you’ve already bought. This is truly pathetic, especially considering their Android app kind of implements a locker service. From now on I’ll be using 7digital whenever I can – unfortunately their selection isn’t as big though. The quest for the perfect music services continues … :-/

Share

freedb is dead, long live freedb

By Adam, September 13, 2011 3:13 pm

I’ve been a fan of freeDB for years. It’s a great way of crowd-sourcing CD title/artist/track information and is a huge help when converting CDs into part of your digital music collection (“ripping”).

However, more recently I have noticed that the majority of times I submit a new CD to freeDB, it gets rejected due to a discid collision. This is due to a fundamental limitation in the discid hashing algorithm which freeDB inherited from CDDB – it’s only a 32-bit number, of which a mere 8 bits are used as a checksum for the individual track starting times. So it’s no surprise that we’re getting collisions galore, at an increasing frequency as the database continually grows. Even worse, CDDB attempts to deal with collisions by making CD entries in the database uniquely retrievable by (discid, category) pairs, where category is one of only 11 musical genres. Of course this is woefully inadequate, because there are countless genres and most music defies classification anyway. They attempted to deal with this by calling the 11th category “misc”, but that still has the problem of restricting entries to one unique discid per genre. Unsurprisingly this has caused a huge number of collisions, especially in the “misc” category. As a result, people have been re-submitting collided entries into the wrong genre, simply because having an entry with the wrong genre in the database is still better than not having it at all.

Gracenote, the eventual owner of CDDB have developed a new generation database imaginatively called CDDB2 which adds a much richer meta-data structure. Gracenote has taken advantage of this to clean up the mess caused by attempting to shoe-horn classical CDs into an inadequate schema, and license the results to Apple for iTunes. Unfortunately that’s no use to those of us who recognise the value of freedom over vendor lock-in.

It seems that the freeDB server software hasn’t been updated since 2006, so presumably there’s not much of an active community left. So there’s a ripe opportunity for a smart philanthropist hacker to breathe new life into this valuable project. Sounds ideal for Google Summer of Code task, for instance. As this is largely a lazyweb blog post, here are my thoughts on what needs to be done; it’s unlikely I’ll ever manage to prioritise it above other things already on my plate:

  • Design a new collision-proof hashing algorithm. It should produce at least 128-bit hashes, and include as much information about the contents of the physical CD as possible, namely:
    1. number of tracks
    2. starting times of all tracks
    3. total playing time

    This algorithm could be as simple as calculating the MD5 digest of a delimiter-separated concatenation of the above items represented as integers.

    Notice that this should be limited to information which can be retrieved very quickly; for instance producing MD5 digests of the contents of each track takes too long to be useful in practice.

  • Design the next level of the CDDB protocol (which at the time of writing would be level 7), which allows additional querying by this new 128-bit (or larger) digest.
  • Extend the existing freeDB server software to support this new level whilst remaining backwards-compatible with existing clients. In other words, database entries should be retrievable both by the old (32-bit discid, category) pair and the new digest. This would require iterating once through all existing entries to recalculate the new digest for each.
  • (Optional) Extend one or more F/OSS clients to use the new protocol level, and advocate other clients to do the same …

For bonus points, you could extend the database schema in a similar way to CDDB2, and then start a crowd-sourcing project for cleaning up the database with respect to all those pesky classical tracks which have distinct composer / performer metadata.

So, any takers? You’d win the admiration and gratitude of a few, the satisfaction of knowing you helped slightly improve the lives of millions, and a place in heaven ;-)

Share

How to never EVER lose your phone contacts again

By Adam, July 30, 2011 8:31 pm

It continually astonishes me how often I see facebook status updates / group invites / tweets / emails from friends and acquaintances saying something to the effect of “ARGH my iPhone / Blackberry / Nokia phone has been stolen / lost / eaten by my pet donkey and I lost everyone’s numbers, please can you all send me your numbers!!”

People, it’s 2011 already! Whilst technology is still far from perfect, it landed a man on the moon 42 years ago way before mobile phones existed, and certainly solved this particular problem of disappearing phones several years ago.  So for those of you who still haven’t figured this out, without further ado I will outline a solution which should only cost 10 minutes of your life and ensure you never have to broadcast a panicked message cursing your pet donkey and asking everyone to send you their numbers.

Continue reading 'How to never EVER lose your phone contacts again'»

Share

Panorama theme by Themocracy