Install qemu and the kmod from ports. The tap(4) and bridge(4) devices need to be configured to allow the guest OS full network access.
Contents |
$ sudo portinstall emulators/qemu emulators/kqemu-kmod
> pkg_info -x qemu Information for qemu-0.8.2_1: Comment: QEMU CPU Emulator Description: QEMU is a FAST! processor emulator using dynamic translation to achieve good emulation speed. QEMU has two operating modes: * Full system emulation. In this mode, QEMU emulates a full system (for example a PC), including a processor and various peripherials. It can be used to launch different Operating Systems without rebooting the PC or to debug system code. * User mode emulation (Linux host only). In this mode, QEMU can launch Linux processes compiled for one CPU on another CPU. It can be used to launch the Wine Windows API emulator or to ease cross-compilation and cross-debugging. As QEMU requires no host kernel patches to run, it is very safe and easy to use. (but kqemu is now also supported for the i386 on i386 and amd64 case) See also the preconfigured system images on http://oszoo.org/ Many live cd isos also work. WWW: http://qemu.org/
> pkg_info -x kqemu-kmod Information for kqemu-kmod-1.3.0.p9_1: Comment: Kernel Acceralator for QEMU CPU Emulator (development version) Description: KQEMU is a qemu accelerator kernel module on x86/amd64. WWW: http://qemu.org/qemu-accel.html
kqemu_load="YES" if_tap_load="YES"
perm tap? 0660
A tap device is created and added to the bridge to allow packets into the virtual tap interface. Bridging is already compiled into the kernel. The network configuration is as below:
main-lan: 192.168.44.0/24 qemu-lan: 192.168.45.0/24 tap0: 192.168.45.1 # the default g/w for the guest OS iwi0: 192.168.44.10 # laptop wireless interface
net.inet.ip.forwarding=1 net.link.tap.user_open=1
# nat on iwi0 [qemu] nat on iwi0 from 192.168.45.0/24 to any -> (iwi0)
# trust 192.168.45.0/24: Thats our qemu subnet pass in on tap0 from 192.168.45.0/24 to any keep state
> cat ~/bin/qemu-ifup #!/bin/sh [ -z $1 ] && exit ifconfig=/sbin/ifconfig echo "Executing $0 ..." echo "Bringing up $1 for bridged mode..." sudo $ifconfig $1 192.168.45.1 up echo "Adding $1 to bridge0..." sudo $ifconfig bridge0 create sudo $ifconfig bridge0 addm tap0 up sudo $ifconfig bridge0 addm iwi0 up sleep 2
> qemu -hda dfly.img -net nic -net tap,script=~/bin/qemu-ifup Executing /home/shanu/bin/qemu-ifup ... Bringing up tap0 for bridged mode... Adding tap0 to bridge0... ifconfig: SIOCIFCREATE2: File exists ifconfig: BRDGADD tap0: File exists ifconfig: BRDGADD iwi0: File exists
Below is the ifconfig output with a qemu session running
> ifconfig tap0
tap0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
inet6 fe80::2bd:a8ff:fe31:1500%tap0 prefixlen 64 scopeid 0x4
inet 192.168.45.1 netmask 0xffffff00 broadcast 192.168.45.255
ether 00:bd:a8:31:15:00
Opened by PID 63473
> ifconfig bridge0
bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 76:63:f6:17:56:44
priority 32768 hellotime 2 fwddelay 15 maxage 20
member: iwi0 flags=3<LEARNING,DISCOVER>
member: tap0 flags=3<LEARNING,DISCOVER>