sábado, 29 de agosto de 2009

Popping GNU/Linux out of the Virtual Machine

Hi!

At work I'm tied to a windows machine, however I have been able to use GNU/Linux which is where I'm most productive.

First, I tried working with Portable Ubuntu. It works pretty well, however the latency can be a little high sometimes (Firefox being the most obvious case that I noticed).

About a week ago I started working on a clustering experiment and wanted to give it a shot inside Portable Ubuntu. However, I discovered it wasn't possible because its kernel doesn't support bridging (I was going to use some qemu virtual machines for the experiment).

Well, It seemed like I was going to need a virtual machine to host the experiment after all. I have used qemu and love it because of all the networking tweaking it allows you to do, however it can be very slow... and inside the virtual machine I was going to host more virtual machines, so I decided to use something else, at least on the hosting virtual machine.

I tried VirtualBox and was gladly surprised by its performance. It was veeeeeeeeeery fast.

Got Kubuntu installed on it. It works acceptably. Now the problem with virtual machines where you have a window that represents the computer's monitor is that you have to use key combinations to get in and out of the virtual machine environments.... plus the windows in the virtual machine are inside a window that looks not integrated to the real environment.

But then a truck hit me. How about finding a way to get the windows out of the virtual machine? How about using an X server on Windows (XMing, for example) and configure the Virtual Machine to use that X server. kdm can be configured to use a remote X server.

If you check /etc/kde4/kdm/kdmrc (remember it's Kubuntu, so I'm using KDE... gdm must have something similar), in the [general] section, there's StaticServer and it's set to :0 (in other words, the X server of the host). I changed that to say 10.0.2.2:0.0 (the address of the windows box from VirtualBox):

StaticServer=10.0.2.2:0.0

Then I started XMing (XMing included in Portable Ubuntu, by the way) with -rootless, so that I got no decoration for the X server window, then I restarted the kdm service on the virtual machine and there it is! kdm is displayed on the windows environment. Log in to kde and after a moment of not seen anything on the X server screen I get to see KDE's background, plasma panels and everything else. Cool! The windows are not integrated in windows, but I don't have to get in/out of the Virtual Machine screen anymore.

The only thing I'd have to complain about so far is that sometimes the latency on KDE gets too high and I don't know how to avoid it. I tried with the windows XMing and cygwin's XWing but I got the same latency issue. How can that be avoided?

Picture
The picture I'm including is the same thing running off a Kubuntu 9.04 LiveCD on my wife's box (shhhhhhhhhhh, she better not hear about it).

Sidenote
When I log into kde, depending on the resolution of Windows (the real OS of the machine), KDE's splashscreen is seen or not.

sábado, 22 de agosto de 2009

dhcp-lb: Load balance with DHCP links

Hi!

Some years ago, when I worked at the Hospital of Pediatric Specialties in Maracaibo, I did a project that would update routing for our multi-link internet connection when there was a DHCP event. I decided to redo the whole thing using a simpler approach plus I would release the code without asking for permission (as it's mine now) under Affero GPLv3.

Introduction
So, you have read lartc's guide on 'Routing for multiple uplinks/providers' and it all makes sense (and does work). However, there's a catch for you: Instead of having static network configurations, your ISPs use DHCP to set your network connections and you don't intend to sit all day long waiting for DHCP event to happen to reconfigure the whole thing, do you? That's what I thought.

dhcp-lb
In order to solve the problem I just described I created dhcp-lb. It's a python script that, once configured and linked as a dhclient exit hook, can listen to dhcp events and reconfigure networking accordingly.

What I need
You need python, dhclient, iproute2 (that I think will come by default in almost every distro) and a multipath-enabled kernel (check for CONFIG_IP_ROUTE_MULTIPATH, I think).

How to get it?
Right now, the only way to get it is through bazaar from launchpad's branch I set for it. I have created a PPA, but I have to learn how to use it so be patient (maybe someone can help me in this journey). If you want it but don't want to use bazaar to get it, email me and I'll gladly send you a tgz with it.

Configuration
Configuring it is fairly simple. You need to create a file called /etc/dhcp-lb with the configuration of each link involved in the multilink default route. Each line has the configuration of each link and it has four fields (so far):
- Network Interface
- Routing Table for that interface
- Routing Table ID (numeric, less than 255... check /etc/iproute2/rt_tables)
- Weight (numeric, more than 0)
All 4 fields have to be separated by exactly a single white space at this time. One example /etc/dhcp-lb file would look like this:

# interface routing-table table-id weight
eth0 table-eth0 200 1
wlan0 table-wlan0 201 2

In this example I set wlan0 to have twice the routing weight of eth0 (for example, eth0 is 512 kbps and wlan0 is 1 mbps). Also, if the routing tables are not set in /etc/iproute2/rt_tables, dhcp-lb will take care to add them to that file, so no need to change rt_tables beforehand.

After you have done that, all you need to do is link /usr/bin/dhcp-lb into the exit hooks directory (/etc/dhcp3/dhclient-exit-hooks.d in my case) and you are done. Restart the network service and it should start working right away.

Keep in mind
dhcp-lb only configures routing with multiple uplinks and it doesn't correct any of the shortcomings that come along having multiple uplinks. It only reconfigures routing with dhcp events. What are the shortcomings? That would require a blog posting of its own, but this is the most noticeable (at least, to me):

- Balancing works beautifully for multiple short connections from your LAN. Few long connections? It won't look like it's balancing at all. It's because of the way routing works. The kernel doesn't make a routing decision for every packet that goes out of a box. Instead, it uses a routing cache to associate a target IP with the network interface it chose to use to get to it so it doesn't have to make a routing decision again... and the cache lasts for a few minutes (run this command: ip route show cache to take a look at the actual cache). After a while, it can decide to send packets to that same host through another network interface possibly breaking connections established to that host cause the other host will start receiving packets from a different address.

Conclusion
I hope this project helps you. However, this project is (as you can see from the logs) very young so expect it to have some problems (that I'll be working to solve). Have patches for it? Please, send them without hesitation. I'm open to suggestions and donations if you consider I deserve any.

Update
I just released dhcp-lb 0.02 (sep 9th 2009). Check this post to learn more about it.

domingo, 16 de agosto de 2009

[OT] Adsense: Get scientology out of my site!

I set up Google's adsense on this blog. It's not being making all the truckloads of money I expected from it, but it's better than nothing nevertheless.

However, since a couple of weeks ago, the only advertisements I've seen on those spaces are dedicated to Scientology... at least on the computers I've been able to check for it.

Now, I've got a problem with that... and it's not because I don't like Scientology per se. It's just that I don't have any sympathy for any religion in particular. And come on, if there's an advertisement of Scientology every once in a while, I can let it slip through... but EVERY AD for the last couple of weeks? That is a little too much for my religious tolerance.

So, guys at Adsense, get rid of the Scientology ads on my site.... or even better, set up a page so that I can ban some ads I don't want to see on my site (like religious ones, for example).

Thanks in advance to anyone who can help in this regard.

martes, 11 de agosto de 2009

Installing openSuSE: grub complaining on a hardware RAID

Hi!

I'm a Kubuntu/Debian user (and intend to stay that way), however a few days ago I set myself to install openSuSE 11.1 (LiveCD based on KDE4). The thing is that this particular box has a hardware RAID set up.

0f:08.0 RAID bus controller: Hewlett-Packard Company Smart Array E200i (SAS Controller)

I had no problem installing other OSs on top of it so I thought it was going to be painless.... It wasn't.

As a matter of fact I didn't have too much of a problem (and the installation was pretty fast, congratulations for openSuSE for that).... except for the fact that when the installer was about to finish, on the part where grub was going to be installed on the MBR, it would fail miserably with an error 21. It would complain about not being able to find a certain device. I was given the option to retry installing grub without going though the whole installation procedure all over again. I tried a couple more times with a few option changes but I always got the same error.

I then went into grub (by calling grub as root on the terminal) to see what I could do. I tried to change the root device, but when I wrote root and then hit the tab key to see the available devices, no one showed up. Could it be because I'm working on a live CD and some of those partitions were just created?

I went openSuSE's IRC channel on freenode.net and the guys there were very interested on my problem. After a while someone (sorry not to remember your nick, man.... or woman... but thanks for showing me the light) told me that it could be a problem with grub's device.map file.

I went there (/boot/grub/device.map of the running LiveCD instance) and only saw a line for (fd0). It looks like it's missing all the partitions I have set up on the disk after the installation (Important Notice: see the update to the article at the end). I write a mapping of all the devices that I needed (including the HD I was using and all the other partitions with other operating systems) with what I would guess partitions would be to grub. Something like:

/dev/cciss/c0d0 (hd0)
/dev/cciss/c0d0p1 (hd0,0)
/dev/cciss/c0d0p2 (hd0,1)

And so on. Saved the file then I went into grub again. root tab..... and there are all the partitions I needed. So I do the grub installation procedure which ends up being like this:

root (hd0,4)
setup (hd0)

(hd0,4) would be the / partition I was installing on (with /boot not in a separate partition). Remember I was trying to install it on the MBR, that's why I say (hd0) on the setup command. I get the output that the installation went right and I'm done.... almost. I mount my root partition (that would be / of the just installed openSuSE) and see the content of its /boot/grub/device.map and it's the same old broken one. I replace it with the one I edited on the running LiveCD. Unmount, just in case so the installer (which is still waiting for me) doesn't go crazy.

Then I let the installer finish telling it that I don't want to install any bootloader. It finishes installing. Reboot, I get openSuSE running.

Hope you don't need to apply this but... it could be a little too late. Otherwise, why would you be reading this, right? Good luck anyway!

UPDATE
I'm looking at the device.map file on my box at home with Kubuntu kinky... I mean, karmic (that openSuSE box was at work) and I see that the only line there is a mapping to the hard drive and not all the partitions of my box:

(hd0) /dev/hda

So perhaps I just needed to add a line to map /dev/cciss/c0d0 to (hd0) and that would be it... but it could also be because karmic is using grub2, so keep that in mind when you try. In any case, I'm not going to retry doing the installation just to figure it out.