OpenBSD vm on GCE/GCP - (1/2) Local Part
Tags: openbsd, gcp, gce, vm
Published: 2018-10-31 13:29:46

---
title: OpenBSD vm on GCE/GCP - (1/2) Local Part
published: true
description: OpenBSD is a secure, minimal and great OS which isn't officially supported by Google Compute Engine (GCE) of Google Cloud Platform (GCP). This is a tutorial how to create a OpenBSD virtual machine on GCE.
tags: openbsd, gcp, gce, vm
cover_image: https://thepracticaldev.s3.amazonaws.com/i/xxtt2dkg57jbbq7j0udk.jpg
series: OpenBSD vm on GCE/GCP
---

## Intro

It's a happy month for me as an [OpenBSD](https://www.openbsd.org/index.html) user this month because the new version, 6.4, has been released on October 18, 2018.
[Hello, Puffy, again : )](https://www.openbsd.org/64.html)

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](https://github.com/golang/build/tree/master/env/openbsd-amd64) by [dmitshur](https://github.com/dmitshur).
I've got happy, again!


<center>✿ ✿ ✿</center>


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](https://www.virtualbox.org/)

1. Convert VDI image to RAW image for GCE and compress it to upload
    by [VBoxManage](https://www.virtualbox.org/manual/ch08.html) commands

1. Upload the image to Google Cloud Storage
    by [gsutil](https://cloud.google.com/storage/docs/gsutil) commands 

1. Create an instance on GCE
    by [Google Cloud Console](https://console.cloud.google.com/)


---

## Environment

- OS: OpenBSD 6.4 amd64


## Requirements with references

- [OpenBSD installer](https://www.openbsd.org/faq/faq4.html#Download)
    - [installXX.iso - amd64](https://cdn.openbsd.org/pub/OpenBSD/6.4/amd64/install64.iso)
- VirtualBox
- [Google Cloud Storage](https://console.cloud.google.com/storage)
    - <strong>A bucket is required</strong> to upload virtual image temporarily.
- [Google Cloud SDK](https://cloud.google.com/storage/docs/gsutil)
    - [Setting Up Google Cloud SDK For GCP On Arch/Manjaro Linux](https://dev.to/nabbisen/setting-up-google-cloud-sdk-of-gcp-on-archmanjaro-linux-19mk)


<center>✿ ✿ ✿</center>


## Steps

### Step 1: Create VDI disk where OpenBSD is installed

Create a virtual machine for OpenBSD with VirtulBox:

![](https://thepracticaldev.s3.amazonaws.com/i/pt9qvy6wr7bwzejnm4wx.png)

![](https://thepracticaldev.s3.amazonaws.com/i/xfefxa6aglrw7oshjqjz.png)

*\* Note: According to GCP's [Free Products](https://cloud.google.com/free/), the storage size of GCE must be less than 30 GBytes if you want to let it free to use.*

![](https://thepracticaldev.s3.amazonaws.com/i/98vmgezq09pex7pwk6xm.png)

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

![](https://thepracticaldev.s3.amazonaws.com/i/rq2sk77gic374uddmdfd.png)

Let's start the guest OS:

![](https://thepracticaldev.s3.amazonaws.com/i/ing3kg76zbk6i66j9qz1.png)

![](https://thepracticaldev.s3.amazonaws.com/i/zx8fdtwd9xqhrpqtgbl3.png)

Proceed installation like these settings:

```shell
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.
```

*\* <strong>Caution</strong>: 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.*

```shell
disk               :  "wd0" -> "W"hole -> Use "A"uto layout (or edit layout)
```

*\* Note: You can choose to edit layout by [manual partitioning](https://dev.to/nabbisen/openbsd-manual-partitioning-at-installation-4cif).*

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

After installation, halt it:

```shell-session
# halt # and power off guest
```

We need to add some settings to the virtual machine.

So,

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

Then, operate the guest OS as follows:

```shell-session
# 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
dhcp
```

Next change the line in "/etc/ttys" in order to enable GCP serial console:
(thanks to [Rickard Dahlstrand](https://dev.to/rdahlstrand/comment/hi0m))

```diff
- console "/usr/libexec/getty std.9600" vt220 off secure
+ console "/usr/libexec/getty std.9600" vt220 on  secure
```

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

When all been done, shutdown it:

```shell-session
# shutdown -p now
```

#### Option: SMT - Multithreading

If You need multithreading, add this setting:

```shell-session
# echo 'hw.smt=1' > /etc/sysctl.conf

# # check file content
# cat /etc/sysctl.conf
hw.smt=1
```

*\* Note: OpenBSD [6.4 release announcements](https://www.openbsd.org/64.html) 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:

![](https://thepracticaldev.s3.amazonaws.com/i/86edfvp8d4grc2g21yy8.png)


<center>✿ ✿ ✿</center>


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

{% link https://dev.to/nabbisen/openbsd-vm-on-gcegcp---22-cloud-part-4fno %}