How to run multiple guest OS in QEMU?

This weekend I’ve been fiddling with

QEMU. I’ve installed OpenBSD on a single image and wanted to have two instances of it communicating via network. Installing the system was easy, but the networking setup was quite a pain. See how I did that… To make QEMU instances communicate with each other I needed to plug them to a “network”. That’s why I’ve created a bridge to which Virtual Instances would connect to.

I’ve used the following script:

#!/bin/bash                                                                                                                                                 
# 1st, release all DHCP address and remove all IP address associated
# with the original eth0
#/sbin/dhcpcd -k
kill pidof dhclient
/sbin/ip addr flush eth0
# then take the interface down so we can rename it
/sbin/ip link set eth0 down
# now rename the original eth0 to reth0 (Real ETH0)
nameif reth0 00:24:81:43:61:5b
# OK, bring the same interface (with new name though) back up
/sbin/ip link set reth0 up
# 2nd let's create a bridge called eth0 so other programs think they are
# talking to the same old interface (actually they will talk to the
# bridge which is a clone of the original eth0 - with name MAC addr)
/usr/sbin/brctl addbr eth0
# then add both origianl eth0 and tap1 device to the bridge
/sbin/brctl addif eth0 tap1
/usr/sbin/brctl addif eth0 reth0
echo "showing bridge mac addresses"
/usr/sbin/brctl showmacs eth0
# 3rd, we need to bring the newly created bridge UP
/sbin/ip link set eth0 up
# 4th, renew the DHCP address if possible
#/sbin/dhcpcd -n
dhclient eth0
/sbin/ip addr show

Then I just needed to start Qemu with this command line:

sudo qemu openbsd-4.7.img  -net tap -net nic,macaddr=52:54:00:12:34:57,model=ne2k_pci

Since I’ve set up bridge for Qemu instances, I’ve plugged TAP interfaces into it. That’s why I’ve needed to specify this in my qemu exec line. I’ve also added macaddress setting since both my instances were getting the same one. And that’s all! It works like a charm. Now on to some harder things!

You May Also Like

Grails with Spock unit test + IntelliJ IDEA = No thread-bound request found

During my work with Grails project using Spock test in IntelliJ IDEA I've encountered this error:

java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
at org.codehaus.groovy.grails.plugins.web.api.CommonWebApi.currentRequestAttributes(CommonWebApi.java:205)
at org.codehaus.groovy.grails.plugins.web.api.CommonWebApi.getParams(CommonWebApi.java:65)
... // and few more lines of stacktrace ;)

It occurred when I tried to debug one of test from IDEA level. What is interesting, this error does not happen when I'm running all test using grails test-app for instance.

So what was the issue? With little of reading and tip from Tomek Kalkosiński (http://refaktor.blogspot.com/) it turned out that our test was missing @TestFor annotation and adding it solved all problems.

This annotation, according to Grails docs (link), indicates Spock what class is being tested and implicitly creates field with given type in test class. It is somehow strange as problematic test had explicitly and "manually" created field with proper controller type. Maybe there is a problem with mocking servlet requests?