Eric Radman : a Journal

Running a Linux VM on OpenBSD

Writing portable applications requires testing on a variety of platforms. Sometimes I run an alternate OS on a separate piece of hardware, but if you travel running a VM with your target OS is very helpful.

The following sections are a tutorial on running Debian in a VM hosted by OpenBSD.


First create a new disk image

qemu-img create debian.img 4G

Then make a shell script to fire it up


cd ~/vm
qemu-system-i386 \
  -m 256M \
  -net nic,vlan=1,model=e1000,macaddr=fe:e1:ba:d3:e7:33 \
  -boot once=d \
  -cdrom ~/iso/debian-7.0.0-i386-netinst.iso \

By default the first ethernet port will be bridged with tun0. If you want to use a different interface set the ETHER. See also the excelent OpenBSD qemu/pkg/README for more recommendations for running QEMU.

Booting Linux

Linux 2.6 may hang after messages such as this

Setting APIC routing to flat
..TIMER: vector=0x30 apic1=0 pin1=0 apic2=-1 pin2=-1
..MP-BIOS bug: 8254 timer not connected to IO-APIC
...trying to set up timer (IRQ0) through the 8259A ...
..... (found apic 0 pin 0) ...
....... failed.
...trying to set up timer as Virtual Wire IRQ...

Adding no_timer_check to the kernel boot parameters will skip this check and should allow you to boot. To make this change permanent in Debian also add this entry to the configuration variable GRUB_CMDLINE_LINUX_DEFAULT in /etc/defaults/grub. Then run

$ sudo grub-update

Networking on the OpenBSD Host

I want OpenBSD and Debian to be able to obtain an IP via DHCP on their wired interfaces and I don't want external networking required for an NFS share to the VM. To accomplish this I need two interfaces since dhclient will erase any other IPv4 addresses already assigned. We can't assign an address directly to the bridge, but we can configure a virtual Ethernet device and add it.




add vether0
add em0


At home I can make internet accessible from the VM while OpenBSD is on wireless by adjusting my firewall to route packets addressed to via my laptop and add a PF rule to NAT the same addresses
match out on $ext_if from nat-to ($ext_if)
match out on $ext_if from nat-to ($ext_if)
route add

Where is set in dhcpd.conf to be my Thinkpad T60p

host T60 {
        hardware ethernet 00:1b:77:11:10:c5;

Finally I turn on IP forwarding on may laptop in

one interface ( to another (

Forwarding isn't requried for using the bridge, but it is required to reach the Internet when connected to wireless because unlike wired interfaces a wireless interface will only respond on a single MAC address.

T60$ netstat -rn -f inet
Routing tables

Destination        Gateway            Flags   Refs      Use   Mtu  Prio Iface
default          UGS        0     2449     -    12 wpi0          UH         1        0 33196     4 lo0      link#5             UC         2        0     -     4 vether0         fe:e1:ba:d0:b9:30  UHLc       0        2     -     4 lo0         fe:e1:ba:d3:e7:33  UHLc       0      107     -     4 vether0
192.168.0/24       link#2             UC         1        0     -     4 wpi0        00:10:a4:7a:9a:ad  UHLc       1      281     -     4 wpi0          UG         0       27 33196    56 lo0

Networking on the Debian VM

Edit /etc/network/interfaces and add the following to enable DHCP on the interface while maintaining another static address

allow-hotplug eth0
  iface eth0 inet dhcp

auto eth0:0
  iface eth0:0 inet static

See the Debian wiki page on NetworkConfiguration for other options.

File Sharing

Add the following lines to /etc/rc.conf.local to start up NFS-related services on boot

nfsd_flags="-tun 4"

and list the paths and hosts to export


Now we can add a line to /etc/fstab in the VM that mounts the home directory on boot /home/eradman nfs auto  0 0

Last updated on November 26, 2016