OpenBSD Host How To

QEMU running on various flavours of BSD (FreeBSD, OpenBSD, NetBSD, etc)

OpenBSD Host How To

Postby guy on Sun Jul 17, 2005 3:46 pm

Seeing as I couldn’t find much help elsewhere, here’s the fruits of my endeavours. This briefly covers how to get an OpenBSD host running a Windows XP VM.

Download and install the qemu package with pkg_add

Create a disk image:
Code: Select all
# qemu-img create -f qcow virtual.hd 4G

OpenBSD Qemu appears to be incapable of booting a physical CDROM, so you’ll have to create a .iso of your install disk. After spending most of a day trying to figure this out using dd and OpenBSD, I gave up and stuck the CD in my FreeBSD workstation, dd’d it, and copied back over to the Open machine.

Networking wasn’t working using the layer 3 tunnelling offered by /dev/tun device, so you’ll need to configure a layer 2 tunnel. The following qemu-ifup script will do this for you:
Code: Select all
#!/bin/sh

guest_gw=”192.168.10.1″
guest_net=”192.168.10.0″
guest_mask=”255.255.255.0″

/sbin/ifconfig em0 alias $qemu_ip netmask $qemu_mask
/sbin/route add $guest_ip $guest_gw $guest_mask
/sbin/ifconfig $1 $guest_gw $guest_mask link0

You'll need to add IP forwarding:
Code: Select all
sysctl -w net.inet.ip.forwarding=1

Update /etc/sysctl.conf whilst you're at it.

NAT can be configured in /etc/pf.conf by adding the following:
Code: Select all
ext_if="em0"
table <qemu-net> persist { 192.168.10.0/24 }
nat on em0 inet from <qemu-net> to any -> em0

Use pfctl to load the pf ruleset:
Code: Select all
# pfctl -f /etc/pf.conf

You can check the NAT configuration of pf using the following:
Code: Select all
# pfctl -sn

Finally, launch your VM with:
Code: Select all
# qemu -m 256 -boot d -cdrom winxp.iso  -hda virtual.hd -n ./qemu-ifup

'256' refers to the RAM made available to the VM. Clearly, if you don't have 256MB to spare, specify less. :wink:


Now for the best bit... once you've done all that, built you shiny virtual XP machine and start using it, you'll quickly realise you might be better using a Linux host until we get a BSD port of the Qemu accelerator, KQEMU. :cry:
guy
 

Postby Edgemaster on Sun Apr 30, 2006 2:20 pm

The above is generally correct, but I found the following helpful:
QEmu under OpenBSD seems to be unable to use the cdrom device, no problem, make an image of the disk. For this , I used the readcd program in the cdrtools package:
Code: Select all
# readcd dev=/dev/cd0c f=xppro.iso

I found that the recommended tap network support worked well, with a couple of changes.
Copy the file /usr/local/share/examples/qemu/qemu-ifup to /etc/qemu-ifup
Edit the ETHER=trunk0 line to point to your network interface (eg sis0).

Then starting qemu with:
Code: Select all
# qemu -cdrom xppro.iso -boot d -soundhw all -net tap xp.img

Starts successfully and boots into Windows setup.
However, I find that since I have an upgrade version, I am required to swap disks in the virtual cd drive, this doesn't seem to work too often, since Windows only recognises a disk after several attempts with
Code: Select all
(qemu) switch cdrom win98.iso


A possible solution to this is installing Windows 98 first, then upgrading to XP.
Edgemaster
 
Posts: 1
Joined: Sun Apr 30, 2006 2:02 pm

Re: OpenBSD Host How To

Postby atlscrog on Mon Nov 17, 2008 9:13 pm

I know this is an old thread, but I found it helpful and wanted to add my experience.

The biggest difference is I chose to not assign IP addresses to the tun0 (and tun1, tun2, tunX) interfaces.

Instead, I create a bridge and add them to the bridge along with a real nic.

I then assign an IP address to the interface withing the guest OS that follows my physical network addressing scheme.

For example, I use 192.168.1.1 as my default gateway.

Physical server NICs are assigned an address in a range, such as 192.168.1.20-29, while virtual NICs are assigned a separate range such as 192.168.1.30-39.

Granted, I'm running a very small home network with less than ten machines (including guest OS's), so this simple scheme works for me.

Here is my qemu-ifup script (it is simplified version of the stock script):

#! /bin/sh

_ETHER=nfe0
_BRIDGE=bridge0

# Let the environment over-ride this
[ "$BRIDGE" ] || BRIDGE=${_BRIDGE}
[ "$ETHER" ] || ETHER=${_ETHER}

if test `id -u` -ne 0; then
SUDO=sudo
fi

echo -n " {$1 ($BRIDGE <-> $ETHER)"

# Set the tun device into layer2 mode
$SUDO ifconfig $1 link0 up
$SUDO brconfig $BRIDGE add $1


The bridge is configured by the host machine in /etc/bridgename.bridge0 and includes the following:

add nfe0
up

And that's it. This seems to work well.
atlscrog
 
Posts: 0
Joined: Mon Nov 17, 2008 9:03 pm

Re: OpenBSD Host How To

Postby Sunnz on Thu May 28, 2009 1:25 am

Just a heads up for those who haven't tried QEMU from the latest ports, they now have a very nice README.OpenBSD that explain exactly how to get networking the way you wanted and some tips on running it under a non-root user.

You can read it on the web: http://www.openbsd.org/cgi-bin/cvsweb/p ... web-markup

That's for 4.5 but the same idea apply to older versions of OpenBSD/ports.
Sunnz
 
Posts: 0
Joined: Fri May 22, 2009 9:49 am


Return to QEMU for *BSD

Who is online

Users browsing this forum: No registered users and 0 guests