Create and upload an OpenBSD disk image to Azure

Applies to: ✔️ Linux VMs ✔️ Flexible scale sets

This article shows you how to create and upload a virtual hard disk (VHD) that contains the OpenBSD operating system. After you upload it, you can use it as your own image to create a virtual machine (VM) in Azure through the Azure CLI.

Prerequisites

This article assumes that you have the following items:

  • An Azure subscription: If you don't have an account, you can create one in a couple of minutes. If you have an MSDN subscription, see Monthly Azure credit for Visual Studio subscribers. Otherwise, learn how to create a free trial account.
  • Azure CLI: Make sure you have the latest Azure CLI installed and logged in to your Azure account with az login.
  • OpenBSD operating system installed in a .vhd file: A supported OpenBSD operating system (6.6 version AMD64) must be installed to a VHD. Multiple tools exist to create .vhd files. For example, you can use a virtualization solution such as Hyper-V to create the .vhd file and install the operating system. For instructions about how to install and use Hyper-V, see Install Hyper-V and create a VM.

Prepare an OpenBSD image for Azure

On the VM where you installed the OpenBSD operating system 6.1, which added Hyper-V support, complete the following procedures:

  1. If DHCP isn't enabled during installation, enable the service:

    doas echo dhcp > /etc/hostname.hvn0
    
  2. Set up a serial console:

    doas echo "stty com0 115200" >> /etc/boot.conf
    doas echo "set tty com0" >> /etc/boot.conf
    
  3. Configure package installation:

    doas echo "https://ftp.openbsd.org/pub/OpenBSD" > /etc/installurl
    
  4. By default, the root user is disabled on VMs in Azure. Users can run commands with elevated privileges by using the doas command on OpenBSD VM. Doas is enabled by default.

  5. Install and configure prerequisites for the Azure agent:

    doas pkg_add py-setuptools openssl git
    doas ln -sf /usr/local/bin/python2.7 /usr/local/bin/python
    doas ln -sf /usr/local/bin/python2.7-2to3 /usr/local/bin/2to3
    doas ln -sf /usr/local/bin/python2.7-config /usr/local/bin/python-config
    doas ln -sf /usr/local/bin/pydoc2.7  /usr/local/bin/pydoc
    
  6. You can find the latest release of the Azure agent on GitHub. Install the agent:

    doas git clone https://github.com/Azure/WALinuxAgent
    doas cd WALinuxAgent
    doas python setup.py install
    doas waagent -register-service
    

    Important

    After you install the Azure agent, it's a good idea to verify that it's running:

    doas ps auxw | grep waagent
    root     79309  0.0  1.5  9184 15356 p1  S      4:11PM    0:00.46 python /usr/local/sbin/waagent -daemon (python2.7)
    doas cat /var/log/waagent.log
    
  7. Deprovision the system to clean it and make it suitable for deprovisioning. The following command also deletes the last provisioned user account and the associated data:

    doas waagent -deprovision+user -force
    

Note

If you're migrating a specific VM and don't want to create a generalized image, skip the deprovision step.

Now you can shut down your VM.

Prepare the VHD

The VHDX format isn't supported in Azure, only fixed VHD. You can convert the disk to fixed VHD format by using Hyper-V Manager or the PowerShell convert-vhd cmdlet. Here's an example:

Convert-VHD OpenBSD61.vhdx OpenBSD61.vhd -VHDType Fixed

Create storage resources and upload

First, create a resource group with az group create. The following example creates a resource group named myResourceGroup in the eastus location:

az group create --name myResourceGroup --location eastus

To upload your VHD, create a storage account with az storage account create. Storage account names must be unique, so provide your own name. The following example creates a storage account named mystorageaccount:

az storage account create --resource-group myResourceGroup \
    --name mystorageaccount \
    --location eastus \
    --sku Premium_LRS

To control access to the storage account, obtain the storage key with the az storage account keys list:

STORAGE_KEY=$(az storage account keys list \
    --resource-group myResourceGroup \
    --account-name mystorageaccount \
    --query "[?keyName=='key1']  | [0].value" -o tsv)

To logically separate the VHDs you upload, create a container within the storage account with az storage container create:

az storage container create \
    --name vhds \
    --account-name mystorageaccount \
    --account-key ${STORAGE_KEY}

Finally, upload your VHD with az storage blob upload:

az storage blob upload \
    --container-name vhds \
    --file ./OpenBSD61.vhd \
    --name OpenBSD61.vhd \
    --account-name mystorageaccount \
    --account-key ${STORAGE_KEY}

Create a VM from your VHD

You can create a VM with a sample script or directly with az vm create. To specify the OpenBSD VHD you uploaded, use the --image parameter:

az vm create \
    --resource-group myResourceGroup \
    --name myOpenBSD61 \
    --image "https://mystorageaccount.blob.core.windows.net/vhds/OpenBSD61.vhd" \
    --os-type linux \
    --admin-username azureuser \
    --ssh-key-value ~/.ssh/id_rsa.pub

Obtain the IP address for your OpenBSD VM with az vm list-ip-addresses:

az vm list-ip-addresses --resource-group myResourceGroup --name myOpenBSD61

Now you can SSH to your OpenBSD VM as normal:

ssh azureuser@<ip address>
  • To learn more about Hyper-V support on OpenBSD 6.1, read OpenBSD 6.1.
  • To create a VM from a managed disk, read az disk.