# qemu on same subnet as host

## ooky

Ok I finally got this workiing. . . 

I was attempting to get an emulator working so that it appeared on the same subnet as the rest of my network.  The advanatage of doing this is to run Windows 2000 as an emulated guest system and have it log into an Active Directory domain.

My system (I am only pointing this out because I have an amd64 compiled kernel, I'll explain later):

KT800

amd 3400+

1024 Meg RAM

Gentoo 2004.3 (linux-2.6.9-gentoo-r14)

GCC 3.4.3 (x86_64-pc-linux-gnu-3.4.3-20050110)

Host:

192.168.1.26 (IP)

255.255.255.0 (netmask)

192.168.1.255 (broadcast)

192.168.1.10 (IP of Gateway/firewall)

Guest (DHCP should work too)

192.168.1.27 (IP)

255.255.255.0 (netmask)

192.168.1.10 (gateway/firewall)

192.168.1.10 (DNS)

Requirements (that I am at least aware of):

autoconf-1.5 (this is only to install vde from cvs, which is not needed on all systems, and may not even be needed on an amd64)

vde (on my amd64 system it kept erroring out when emerging from portage I had to use the cvs version http://sourceforge.net/projects/vde/)

qemu (emerge qemu works fine also try the install from cvs https://forums.gentoo.org/viewtopic-t-302314-highlight-qemu+kqemu.html)

TUN/TAP Compiled into kernel

Bridge-Utils (emerge bridge-utils)

Bridging enabled in the kernel

I had some problems getting vde working on my system.  I found out that by installing autoconf-1.5 and installing vde from cvs that I was able to successfully compile it.  After downloading it and installing autoconf, as root go into the vde-cvs directory and execute the following commands:

 *Quote:*   

> 
> 
> autoreconf --install
> 
> make 
> ...

 

You may have to do a 'autoreconf --install --force', but you shouldn't have to.

Now to get the bridge setup.  Stop all network services that you have.  Just to be safe I removed sshd and net.eth0 from my rc scripts and rebooted ('rc-update del sshd' and 'rc-update del net.eth0').   You may be able to leave your rc scripts and just do a 'ifconfig eth0 down' on all your interfaces, but I was having some trouble here (most likley user error).  Here is the script that I used to get the bridge setup:

 *Quote:*   

> 
> 
> #!/bin/bash
> 
> /usr/local/bin/vde_switch -tap tun0 -daemon  #path may be different on non cvs installed vde - /usr/bin/vde_switch
> ...

 

Plug in the values to match your network.  You should be able to install this as an init.d/rc script.  I haven't gotten that far yet.

Also, here is the command that I use to start qemu:

 *Quote:*   

> 
> 
> vdeqemu -m 196 -hda hd.img -boot c
> 
> 

 

References:

https://forums.gentoo.org/viewtopic-t-302314-highlight-qemu+kqemu.html

http://sourceforge.net/projects/vde/

http://lists.gnu.org/archive/html/qemu-devel/2004-09/msg00150.html

https://forums.gentoo.org/viewtopic-t-169553-highlight-qemu.html

Now if I can only get the kqemu module working, . . .

----------

## salfter

With the above, I now have bridged networking running for WinXP Pro SP2 under QEMU 0.8.0.  I ran into a snag with DHCP, though...apparently dhcpcd doesn't like to work on bridge interfaces ("dhcpcd br0" will twiddle its thumbs until timeout).  dhclient works OK, though, and while it's a pain to configure manually, newer baselayouts take care of dhclient config for you.  All you need to do is bring down eth0, set up the bridging configuration in /etc/conf.d/net to bridge eth0 and tun0, symlink /etc/init.d/net.tun0 and /etc/init.d/net.br0 to /etc/init.d/net.lo, fire up vde_switch as given above, and start /etc/init.d/net.br0.  Here's what's added to my /etc/conf.d/net:

```

modules=("dhclient")

bridge_br0="eth0 tun0"

config_eth0=("null")

config_tun0=("null")

config_br0=("dhcp")

depend_br0() {

  need net.eth0 net.tun0

}

brctl_br0=("setfd 0" "sethello 0" "stp off")

```

I have this installed on my notebook, but all of the above is usually commented out so that ifplugd can start/stop eth0 only when a cable is plugged into the network jack.  To get bridged networking running when the machine is unplugged, I suspect the bridge would need to be given a static IP (like 192.168.1.1) and WinXP would then need to be given an IP on the same subnet.

Now I just need to fix the QEMU 0.8.0 ebuild so it'll use kqemu...no wonder WinXP has been so sluggish.

----------

## wafox

Pretty neat trick.  Just what I was looking for.    I was able to get the bridge working fine - thanks salfter - but can't seem to run vdeqemu.  When I try to load up windows 2k I get a command line error.

Using the command line: vdeqemu -localtime -m 512 -cdrom /dev/cdrom -hda /virtual_hdd/win2k.img -boot c 

I get this error:

option -tun-fd is not a valid option 

All my network devices are down prior. I've run the vde_switch command line as per the example and chmod on /tmp/vde.ctl as well.  All that seems to be working fine.  Oh I also have the kqemu module loaded with major=0.  Qemu works just fine normal -- just not with vde.

I was thinking it might be a version issue?  I'm using the following versions:

net-misc/vde version 1.5.8  (emerged it)

app-emulation/qemu 0.8.0 (emerged it)

net-misc/bridge-utils 1.0.6-r3 (emerged it)

Any of you guys run into this or even know what the error means?  Looks like it's trying to pass an option to qemu that it has no idea about...  So close yet so far.

----------

## melbaum

qemu-0.8 doesn't have the -tun-fd option anymore. vdeq and vdeqemu use it to connect to the tun interface. The vdeqemu approach stops working (for me at least) in 0.7.2. There is an fd=h option in 0.8 than I haven't yet figured out how to use. Maybe start up the tun with vde_switch -tun tap0 -daemon and then start qemu with fd=/tmp/vde.ctl? or just fd=h?

----------

