Alpine Linux 3.19.1 on SmartOS

Create an Alpine Zone/VM from Scratch on SmartOS

So you have heard about SmartOS and you think it is like your other favorite virtualization system such as VMware, ProxMOX, XCP-NG, virt-manager, etc. You find some examples showing you how to:

  • import an image from the image repository
  • create a configuration file for that image
  • turn the image into a "zone" and start it up
  • release it into "production"

The above pattern is pretty straightforward and I actually stayed using that pattern every since around 2016 when I started playing with SmartOS and Triton.

I found this recipe or those like it from other fragments on the Internet - the ones I remember are:
 - https://gist.github.com/TyrfingMjolnir/8d6da3e5ef5d3167fefa673039552f83
 - https://pastebin.com/tN1f5VCd
 - https://docs.smartos.org/managing-images/
 - https://docs.smartos.org/how-to-create-an-hvm-zone/

It's 2024 now and the process I used before is still the same but it turns out I was only using the images from the image repository and because of that I was missing out using SmartOS in instances where I wanted a different type of system not available in the image repository. Bhyve appears to be the new favorite machine type these days so that is what I will use in this example.

So here I wanted to show an example of how to create a virtual machine that isn't available in the image repository from scratch and it's pretty easy once you've seen all the steps written down.

Here we go … I'm going to go over each step and explain how the commands you type affect the SmartOS system in each step so you can see what is going on. This might be a better video or screencast with voice over.

The process has the following steps:

  • download a bootable iso file - same as you would with any OS install
  • create a json configuration file for your new VM
  • vmadm create -f file (this populates the /zones/<UUID> hierarchy for your new VM
  • cp your ISO file into the zone's /root directory
  • use bhyveextraopts to temporarily mount the ISO file as a CDROM device
  • start the VM and also connect to its serial console
  • Install the system just like you would from any other system using the text interface over the serial console
  • reboot the system and remove the cdrom device
  • that's it!

Here is a json configuration file thats works for me with the latest version of SmartOS available today (20240125T000404Z):

{
  "brand": "bhyve",
  "vcpus": 1,
  "autoboot": false,
  "alias": "alpine",
  "hostname": "alpine",
  "bootrom": "uefi",
  "ram": 1024,
  "resolvers": [
    "8.8.8.8",
    "1.1.1.1"
  ],
  "disks": [
    {
      "boot": true,
      "model": "virtio",
      "size": 4096
    }
  ],
  "nics": [
    {
      "nic_tag": "usi",
      "model": "virtio",
      "ip": "172.17.1.20",
      "netmask": "255.255.0.0",
      "gateway": "172.17.0.1",
      "primary": true
    }
  ]
}

A few words on the configuration file:

  • it's json, careful on the commas syntax
  • note that autoboot is false - initially
  • the size in the disks object is MB
  • you will need to adjust your network settings to match your nictag. I just have one associated with one of my ISPs.

Now let's get our ISO file and new zone created and setup:

root# vmadm create -f bh-alpine3-config.json
Successfully created VM 2df56f40-efd2-4893-9e40-fda287ffd2c6
root# cd /zones/2df56f40-efd2-4893-9e40-fda287ffd2c6/root/
root# wget --no-check-certificate https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.1-x86_64.iso
root# cd
Take node of the UUID that is created when you run vmadm create.
You need to use this UUID instead of the one from my system in all
the steps below.

At this point, the zone is created by smartos, and you have placed the installation media in the newly created /zones/<UUID>/root directory. vmadm should show your system in it's list now in the "stopped" state:

root# vmadm list
UUID                                  TYPE  RAM      STATE             ALIAS
2df56f40-efd2-4893-9e40-fda287ffd2c6   BHYV  1024     stopped           alpine

At this point we are going to perform a temporary modification to the system by adding a cdrom device and associating that device with the ISO file you cp'd into the /root directory above. After that we will boot the system for the first time and quickly get on the console to watch the magic (make sure you are replacing the example UUID below with the one generated when you initially ran the vmadm create command above.

  root# vmadm update 2df56f40-efd2-4893-9e40-fda287ffd2c6 bhyve_extra_opts="-s 7:0,ahci-cd,/alpine-virt-3.19.1-x86_64.iso"
  Successfully updated VM 2df56f40-efd2-4893-9e40-fda287ffd2c6

  root# vmadm start 2df56f40-efd2-4893-9e40-fda287ffd2c6
  Successfully started VM 2df56f40-efd2-4893-9e40-fda287ffd2c6

  root# vmadm console 2df56f40-efd2-4893-9e40-fda287ffd2c6

Welcome to Alpine Linux 3.19
Kernel 6.6.14-0-virt on an x86_64 (/dev/ttyS0)

localhost login:

This starts the system with the CDROM mounted, and you should see activity on the serial console. Note that not all Linux distributions are serial console friendly but I don't want to muddle this process with any discussion of VNC or RDP as this is already sorta long.

From here, you should see the system boot into the alpine installer. From there, install the system as per normal. You should see the /dev/vda disk image you specified in your json there at the correct size and any eth<x> NICs as well for you to confiugre.

When you are done with the alpine install, reboot the system and then shut it down and remove the temporary cdrom device. (note there is probably a way to eject the image as well)

This is how you "remove" the cdrom and start your new system for the first time:

vmadm update 2df56f40-efd2-4893-9e40-fda287ffd2c6 bhyve_extra_options=""
vmadm start 2df56f40-efd2-4893-9e40-fda287ffd2c6

Congratulations - you now have a VM running on the awesome SmartOS plaform!


Author: Dan Mack

Created: 2024-02-02 Fri 06:00

Validate