OpenBSD on Digital Ocean

For OpenBSD users, it has been pretty disappointing that Digital Ocean didn’t launch other BSDs with introduction of FreeBSD, even though the technical barrier had been removed to allow it.

Today, I thought I’d try doing an OpenBSD load again (I have tried before without success due to CPU feature issues) and the results were pleasing – you can now enjoy OpenBSD on Digital Ocean.

The key here is using a FreeBSD instance as a shim.

Start up an instance size of your choice in the region that you want your instance in.  Select all that is appropriate to get a FreeBSD instance up and running.

Log into your new instance and switch to root

sudo su -

Using your closest mirror, download the miniroot installer.  At this time, miniroot57.fs is what we will be using for this example.

fetch http://ftp.hostserver.de/pub/OpenBSD/snapshots/amd64/miniroot57.fs

Turn off the swap on the FreeBSD instance

swapoff /dev/gpt/swapfs

GEOM will prevent writing the miniroot shim to the instance’s storage.  By turning on the debug flags for GEOM, this allows us to do what we like to the raw vtbd0 disk

sysctl kern.geom.debugflags=0x10

Now write out the miniroot shim to the vtbd0 device

dd if=miniroot57.fs of=/dev/vtbd0 bs=512k

This is very small and will take less than a second if everything is ok.  Once completed, issue a

shutdown -r now

and move back into the console window in the Digital Ocean portal.

You can now perform a standard generic network install of OpenBSD on your instance with the details that have been provided for network settings, as supplied by Digital Ocean.  The only caveat is for setting up the storage drive.

Since we used the same drive for the shim as we will be installing on, the drive parameters will be incorrect if you try to do a custom layout.  So my recommendations are as follows:

Use/enable DUIDs
Use the (W)hole disk
Select (E)dit auto layout

In the editor, remove all listed partitions using

d *

Create a new swap partition first, 1 Gigabyte will do nicely for this example

a b[Enter]
[Enter]
1G[Enter]
[Enter]

Then create the main file system (** Note: This is not the OpenBSD project recommendation, it is just an example to keep inline with how Digital Ocean creates file systems for other operating systems)

a a[Enter]
[Enter]
[Enter]
[Enter]
/[Enter]

Quit the disklabel editor and write the label to the disk.  You can then continue with your network install as per the normal OpenBSD installation documentation.

Once complete, you’ll be able to reboot into a fully functioning OpenBSD and have access to other Digital Ocean control panel functions like snapshots.

Update 22/04/2015: Creating another OpenBSD instance from a snapshot does not work. It appears that either the snapshot feature on Digital Ocean doesn’t pure image snapshot the disk or the disk tools used by the platform to insert keys, ips etc (and probably the boot record) break the restore.

Update 09/07/2015: OpenBSD snapshot has moved to 5.8 now so the above fetch needs changing:

fetch http://ftp.hostserver.de/pub/OpenBSD/snapshots/amd64/miniroot58.fs

Or you could use the latest -release to do what you need (5.7).  Any OpenBSD -release from now should achieve what you need on Digital Ocean:

fetch http://mirror.aarnet.edu.au/pub/OpenBSD/5.7/amd64/miniroot57.fs

Note: Please refer to http://www.openbsd.org/ftp.html for all the latest mirror information.  Examples above are taken from that list but might not be suitable for your geography or export laws.