SmartOS on SmartOS everywhere for LX brand testing

TLDR? Click here for the quick set of commands to run on your SmartOS machine to try this stuff out.

Hot on the heels of my previous blog entry comes a KVM bootable image containing my latest SmartOS build with some extra tooling to make testing the latest (LX related) commits from Joyent as easy as possible.

Motivation

I run SmartOS on my home server. It runs a couple of VMs and a bunch of zones including my SmartOS build zone that regularly rebuilds SmartOS when there are new commits in the upstream repos. Rebooting requires restoring my working state in my VM and getting the build zone ssh-agent loaded with my SSH key for uploading builds into Manta. In short, it's a little annoying.

On the other hand, to test the latest commits with LX brand fixes requires pretty aggressive rebooting. Any time you're ready to do testing you have to update to the latest code.

Solution

Rather than reboot my GZ regularly I've decided to create a KVM image that I can use to do LX brand testing. Here's how you can try it out. First, obtain the image:

On older systems add my image server like this:

imgadm sources -a http://datasets.shalman.org/datasets

On newer systems it's like this:

imgadm sources -a http://datasets.shalman.org/datasets -t dsapi

Then import the image:

imgadm import 3d09ec02-99c8-11e4-b1a2-8b0aedd63024

This image contains a 10GB bootable zones pool (if you're curious, the way it's built is documented in this wiki page) with my latest build which includes a working vioif network driver.

Here's some example JSON I used to provision a VM with this image:

{
  "alias": "smartos-lx-test",
  "autoboot": "false",
  "brand": "kvm",
  "ram": 2048,
  "vcpus": 3,
  "disks": [
    {
      "boot": true,
      "model": "virtio",
      "image_uuid": "3d09ec02-99c8-11e4-b1a2-8b0aedd63024"
    }
  ],
  "nics": [
    {
      "nic_tag": "admin",
      "model": "virtio",
      "ip": "dhcp",
      "netmask": "dhcp",
      "gateway": "dhcp",
      "primary": 1
    }
  ]
}

Note that while I intend this image to be used with my builds which include a vioif driver for illumos, if you want to use it for your own vanilla builds of SmartOS then use the e1000 nic model instead of virtio (notes here).

I put "autoboot"="false" in there to make connecting to the console easier. When you provision the VM, vmadm will return the UUID.
I generally boot it like so:

vmadm start <uuid>; vmadm console <uuid>

GRUB is configured to put the boot menu on the serial device and to tell illumos to put the console on the serial device so the vmadm console command lets you watch the boot process.

On the first boot the system will detect the new MAC address and reboot. After the second boot returns a login prompt you can log in either from the console or over SSH. The root user's password is "thanksnahum". Change the password:

umount /etc/shadow; cp /usbkey/shadow /etc/shadow; passwd root; cp /etc/shadow /usbkey/shadow

There are two helper scripts that I have placed in /opt/smartdc/bin (which is on your PATH when you use my builds):

  1. update-platform.sh downloads my latest build.
  2. setup-lx.sh imports the LX images and set up two LX branded zones, one 32bit and one 64bit.

Thanks to @sjorge's NAT configuration (implemented in my tree here) the two LX zones will be NAT'd onto the network via the VM GZ's IP address and ports 2201 and 2202 provide SSH access into the LX zones.

If you need to test freshly provisioned LX zones, just use vmadm to delete the existing zones, then re-run setup-lx.sh

Additional thanks to drscream for helping fix up some of the code powering this image.

Using Vanilla SmartOS builds

If you want to use a vanilla build, it's simple. Just do two things:

  1. Make sure to use e1000 networking rather than virtio
  2. Extract your platform tarball into /zones/smartos/platform and reboot.

Summary

Import the image and provision a VM:

imgadm sources -a http://datasets.shalman.org/datasets
imgadm import 3d09ec02-99c8-11e4-b1a2-8b0aedd63024
vmadm create <<"EOF"
{
  "alias": "smartos-lx-test",
  "autoboot": "false",
  "brand": "kvm",
  "ram": 2048,
  "vcpus": 3,
  "disks": [
    {
      "boot": true,
      "model": "virtio",
      "image_uuid": "3d09ec02-99c8-11e4-b1a2-8b0aedd63024"
    }
  ],
  "nics": [
    {
      "nic_tag": "admin",
      "model": "virtio",
      "ip": "dhcp",
      "netmask": "dhcp",
      "gateway": "dhcp",
      "primary": 1
    }
  ]
}
EOF

The VM UUID will be returned.

vmadm start <uuid>; vmadm console <uuid>

Boot it, let it reconfigure the configuration and reboot once, then log in with username "root" password "thanksnahum". Change the password:

umount /etc/shadow; cp /usbkey/shadow /etc/shadow; passwd root; cp /etc/shadow /usbkey/shadow

Optionally, make sure you're on the latest:

update-platform.sh
reboot

Then provision your LX zones:

setup-lx.sh

Have Fun!