Tuning PostgreSQL on FreeBSD:

Installation

Minimal FreeBSD 9.0 install
portsnap fetch extract
/usr/ports/emulators/qemu/make install distclean

Configuration

Add the following to /boot/loader.conf:

# Hypervisor Configuration
kqemu_load="YES"
if_bridge_load="YES"
if_tap_load="YES"
aio_load="YES"

Add the following to /etc/rc.conf:

# Hypervisor
kqemu_enable="YES"
cloned_interfaces="bridge0 tap0 tap1 tap2 tap3"
ifconfig_bridge0="addm bge0 addm tap0 addm tap1 addm tap2 addm tap3 up"

Add the following to /etc/sysctl.conf:

net.link.tap.user_open=1
net.link.tap.up_on_open=1

Virtual Machines

I normally create a directory for my virtual machines, here I'll use /vm to store them, and I'm creating a vm called "testbox":

mkdir /vm/testbox
cd /vm/testbox
qemu-img create testbox_hda.img 1G

To install an OS:

Boot from CD (Make sure you have permissions to /dev/acd0):
qemu -vnc :0 -boot d -hda /vm/testbox/testbox_hda.img -hdc /dev/acd0 -m 64

Boot from ISO: qemu -vnc :0 -boot d -hda /vm/testbox/testbox_hda.img -hdc /cdrom.iso -m 64

Load up a VNC Viewer and point it to localhost and finish the install.

Bridged Networking:

Create /vm/testbox/qemu-ifup and add:

#!/bin/sh

ifconfig $1 up
echo "Adding $1 ..."

Normally you want your virtual machine to load up on boot, so create /usr/local/etc/rc.d/qemu-startup.sh and add:

#!/bin/sh

case "$1" in
start)

/usr/local/bin/qemu -vnc :0 -m 64 -hda /vm/testbox/testbox_hda.img -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=/vm/testbox/qemu-ifup -boot c -localtime -daemonize

echo "Adding bridge0 ..."

ifconfig bridge0 create
ifconfig bridge0 addm re0 addm tap0
ifconfig bridge0 up
;;
stop)
killall qemu
;;
*)
echo "Usage: `basename $0` {start|stop}" >&2
;;
esac

exit 0

In this case, /dev/re0 is my physical network adapter, chmod 755 both scripts and try out qemu_startup.sh

If you want to run multiple machines, just add another qemu line in qemu_startup and add another tap interface to the bridge0 like so:

/usr/local/bin/qemu -vnc :1 -m 64 -hda /vm/testbox2/testbox2_hdaimg -net nic,vlan=0 -net tap,vlan=0,ifname=tap1,script=/vm/testbox2/qemu-ifup -boot c -localtime -daemon

This line: ifconfig bridge0 addm re0 addm tap0
Becomes this: ifconfig bridge0 addm re0 addm tap0 addm tap1

Happy Emulating!