Virtual Machine on OpenBSD - If you would like to try out a new command line based operating system such as the newest OpenBSD release and you dont have an extra computer laying around, a virtual machine might be the perfect thing for you. Also, a virtual machine is also great for creating bootable USB sticks. Developers will also love the ability to work within a virtual environment. One thing that needs to be mentioned is that virtualization needs to be supported and enabled in your BIOS. If you already have it enabled, great! So, lets get to how to set up a virtual machine.

Start the virtual machine daemon

First thing we need to do is to start vmd, the virtual machine daemon.

# rcctl -f start vmd
vmd(ok)

We will also need to download the iso for the installation image. You can use my script here to download the image from the command line.

Create the disk image for installation

Now, lets get to setting up the virtual machine. It's really quite easy as is most things with OpenBSD. First we want to create a disk image to install our operating system on.

# vmctl create -s 20G obsd73.qcow2
vmctl:qcow2 imagefile created

Start the VM on the disk image

Next, we need to start the virtual machine using the installation image and the disk image we just created. So, type the following into your terminal.

# vmctl start -m 1G -i 1 -L -r install73.iso -d obsd73.qcow2 obsd
vmctl: started vm 1 successfully, tty /dev/ttyp3

Connect to the serial console and install

Next we will attach to the serial console

# vmctl console obsd
connected to /dev/ttyp3 (speed 115300)

Now that we are attached, simply push enter and start the installation. In order to leave the console, the escape sequence ~. is needed. When you are done, simply type halt -p to shutdown. Wait a few seconds after it says to push any key to continue and press CNTRL+C

If you need to stop the virtual machine.

# vmctl stop obsd
stopping vm obsd: requested to shutdown vm 1

Configure VM for internet connection

After the virtual machine installs, we need to get internet connectivity. On the host, enable ip forwarding

# sysctl net.inet.ip.forwarding=1

This should give you connectivity between your virtual machine and your host.

Finally, we need to add a couple of rules to the hosts pf config

# nano /etc/pf.conf

Add the following rules (check /etc/resolv.conf on the host for DNS server IP address

match out on egress from 100.64.0.0/10 to any nat-to (egress)
pass in proto { udp tcp } from 100.64.0.0/10 to any port domain \
	rdr-to $dns_server port domain

Don't forget to reload the pf file

# pfctl -f /etc/pf.conf

Now you should have a connection to the outside world from your virtual machine!

# ping -c 3 google.com
PING google.com (142.251.33.78): 56 data bytes
64 bytes from 142.251.33.78: icmp_seq=0 ttl=58 time=15.788 ms
64 bytes from 142.251.33.78: icmp_seq=1 ttl=58 time=15.233 ms
64 bytes from 142.251.33.78: icmp_seq=2 ttl=58 time=16.501 ms

--- google.com ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 15.233/15.840/16.501/0.519 ms

Configure your VM for easy startup

After you stop your virtual machine session, to simplify things in the future, open /etc/vm.conf and add the following

vm "obsd" {
	memory 1G
	disk /home/puffy/obsd73.qcow2
	owner puffy
	disable
        local interface
}

Now you need to reload the new VM configuration

# vmctl reload

Now you can simply start your VM with the following

# vmctl start -c obsd

you can check the status of your VM with

# vmctl status

When you are finished with your sesssion, type

# halt -p

Wait for a few seconds after it asks to press any key to reboot and press CNTRL+C


Powered by OpenBSD httpd on a Raspberry Pi | This website is IPv6 enabled