Qemu bumps Virtualbox off my table ?

In one of my previous posts I explained how to do bridged networking in Virtualbox. But since then, I haven't blogged much.


The observant reader will notice how I'm straying from my "no projects untill personal life crap sorted" blogging policy
when writing about this subject. I should point out that virtualisation is very useful to me at work and by claiming that
this is not really a project, I should be able to sneak out of anything I have said earlier.


Last time I played with Virtualbox, I hit a bug and reported it. But I haven't seen any change with respect to that bug. Because I really needed to do some virtual machining, I turned to Qemu and was happily surprised. True, Qemu doesn't have the nice GUI frontend that Virtualbox has, but it's totally free and opensource, and it works.

I wrote this script to automagically start my Qemu machines with randomised MAC-addresses, and to be able to setup networking much easier.


#!/usr/bin/perl

sub randomMac {
my $out = "1c:71";
my $i = 0;

for($i = 0; $i < 4; $i++) {
$rand = rand(255);
$out .= sprintf(":%02x", $rand);
}

return $out;
}

# format: diskimage, cd=cdrom, nw=interfaces


$globalDiskImage = "";
$globalCDROMImage = "";
$globalMemory = "128";

foreach $arg (@ARGV) {
if($arg =~ /^cd=(\S+)/) {
$globalCDROMImage = $1;
} elsif($arg =~ /^nw=(\S+)/) {
@globalInterfaces = split(/,/,$1);
} elsif($arg =~ /^mem=(\S+)/) {
$globalMemory = $1;
} else {
$globalDiskImage = $arg;
}
}

$cmdline = "qemu -localtime";

print "########################################################\n";
$counter = 0;
foreach $int (@globalInterfaces) {
$mac = randomMac();
$cmdline .= " -net nic,vlan=$counter,macaddr=$mac";
print "# Interface eth$counter (MAC: $mac) = ";
if($int ne "") {
$cmdline .= " -net tap,ifname=$int,script=/bin/true,vlan=$counter";
print "$int\n";
} else {
print "\n";
}
$counter++;
}

if($globalCDROMImage ne "") {
$cmdline .= " -cdrom $globalCDROMImage -boot d";
print "# CDROM = $globalCDROMImage\n";
}

if($globalMemory ne "") {
$cmdline .= " -m $globalMemory";
print "# Memory = $globalMemory MB\n";
}

if($globalDiskImage) {
$cmdline .= " $globalDiskImage";
print "# Harddisk = $globalDiskImage\n";
}

print "########################################################\n\n";
system($cmdline);


"1c:71" in the MAC-address is the l33t-speak version of ICTI, which is the division I work for ;)

Oh, I should also say some stuff about my attempts to play with Gnome NetworkManager. I found out the hard way that NM is still very much a work in progress... My attempts to automatically create a bridge and accompaning tap devices have worked OK, but when my eth0 device (ethernet interface) goes down, NetworkManager doesn't detect it anymore because it is watching the bridge named "eth0" instead of the old device named like that.

It turns out that I was reinventing the wheel with my entire setup. Debians (and thus Ubuntus) /etc/network/interfaces configuration file has support for bridges. And maybe NetworkManager will do a better job if I create a bridge that way.