DEV Community

Cover image for OpenBSD vm on GCE/GCP - (1/2) Local Part

OpenBSD vm on GCE/GCP - (1/2) Local Part

nabbisen profile image Heddi Nabbisen Updated on ・4 min read


It's a happy month for me as an OpenBSD user this month because the new version, 6.4, has been released on October 18, 2018.
Hello, Puffy, again : )

Well, Google Cloud Platform (GCP) is one of my favorite cloud computing platforms because of its functionality and pricing.
Unhappily, Google Compute Engine (GCE), its Infrastructure as a Service (IaaS) component, doesn't support OpenBSD officially.

I managed to create a custom image of OpenBSD on GCE/GCP thanks to this script by dmitshur.
I've got happy, again!

✿ ✿ ✿

This post is about how to create an OpenBSD virtual machine (vm) on GCE/GCP.

The key factors are 2x2:

  • To create a virtual machine:
    • Use serial console.
    • Prepare for virtual network interface, vio0. (It's OK just to use DHCP.)
  • To set up GCP:
    • Upload RAW image.
    • Use gsutil commands to create cloud image.

Here are the operation steps:

  1. Create VDI disk where OpenBSD is installed
    by VirtualBox

  2. Convert VDI image to RAW image for GCE and compress it to upload
    by VBoxManage commands

  3. Upload the image to Google Cloud Storage
    by gsutil commands

  4. Create an instance on GCE
    by Google Cloud Console


  • OS: OpenBSD 6.4 amd64

Requirements with references

✿ ✿ ✿


Step 1: Create VDI disk where OpenBSD is installed

Create a virtual machine for OpenBSD with VirtulBox:

* Note: According to GCP's Free Products, the storage size of GCE must be less than 30 GBytes if you want to let it free to use.

Add OpenBSD installer media, install64.iso, to "Storage":

Let's start the guest OS:

Proceed installation like these settings:

keyboard layout    :  [your-language]
hostname           :  [your-hostname]
network            :  "em0" -> "dhcp" -> "none" -> "done"
domain, dns        :  (default) (or [your-domain])
password for root  :  [your-password]
sshd               :  "yes"
x windows system   :  "no"
com0               :  "no"  # Because we'll set it up after installation by editing /etc/boot.conf
user               :  "no" (or create someone)
allow root login   :  "yes" # If you set it "no", be sure to create a ssh-allowed user.
Enter fullscreen mode Exit fullscreen mode

* Caution: It's absolutely necessary to have a ssh-allowed user in order to manage the machine at the end of this tutorial. So don't forget to allow root login or create a ssh-allowed user. Moreover, validate the config "allow root login" as needed.

disk               :  "wd0" -> "W"hole -> Use "A"uto layout (or edit layout)
Enter fullscreen mode Exit fullscreen mode

* Note: You can choose to edit layout by manual partitioning.

location of sets   :  (default)             # "cd0"
                      -> (default)          # 6.4/amd64
                      -> "-game*" # optional: exclude more which is not necessary like "-x* -man*"
                      -> "done"
                      -> "yes"
Enter fullscreen mode Exit fullscreen mode

After installation, halt it:

# halt # and power off guest
Enter fullscreen mode Exit fullscreen mode

We need to add some settings to the virtual machine.


  1. Eject the installer media from "Storage" settings of VirtualBox.
  2. Boot the machine again.
  3. Wait util the initial OS settings at rebooting finish.

Then, operate the guest OS as follows:

# echo 'set tty com0' > /etc/boot.conf # activate serial connection
# echo 'dhcp' > /etc/hostname.vio0     # register GCE virtual network

# # check file content
# cat /etc/boot.conf
set tty com0
# cat /etc/hostname.vio0
Enter fullscreen mode Exit fullscreen mode

Next change the line in "/etc/ttys" in order to enable GCP serial console:
(thanks to Rickard Dahlstrand)

- console "/usr/libexec/getty std.9600" vt220 off secure
+ console "/usr/libexec/getty std.9600" vt220 on  secure
Enter fullscreen mode Exit fullscreen mode

It's also possible to change it after creating vm on GCP.

When all been done, shutdown it:

# shutdown -p now
Enter fullscreen mode Exit fullscreen mode

Option: SMT - Multithreading

If You need multithreading, add this setting:

# echo 'hw.smt=1' > /etc/sysctl.conf

# # check file content
# cat /etc/sysctl.conf
Enter fullscreen mode Exit fullscreen mode

* Note: OpenBSD 6.4 release announcements explain as follows:

amd64 now uses eager-FPU switching to prevent FPU state information speculatively leaking across protection boundaries.
Because Simultaneous MultiThreading (SMT) uses core resources in a shared and unsafe manner, it is now disabled by default. It can be enabled with the new hw.smt sysctl(2) variable.

Option: How to manage the guest OS next time

set tty com0 means to use the serial port as a console.
Therefore, in order to manage the guest OS next time, we need to set "Enable Serial Port" before running it:

✿ ✿ ✿

* Note: This post is divided into two parts. The latter part is:

Discussion (0)

Forem Open with the Forem app