Skip to content
OleksandrChekhovskyiPublic

About

Disposable QEMU guests for cross-platform testing.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vmctl

Disposable QEMU guests for cross-platform testing, driven by one POSIX shell script. Built for the case where a project needs to be built and tested on an OS that is not the one on your desk — FreeBSD, initially.

Guests are reproducible: nothing is ever installed by hand. A guest is an official upstream cloud image plus a cloud-init seed, so any guest can be deleted and recreated from its definition.

Requirements

Everything except the guest images is expected to be on the host already:

  • qemu-system-x86_64, qemu-img, KVM access (/dev/kvm)
  • genisoimage (builds the cloud-init seed), curl, xz, rsync
  • python3 (serves the response file and drives installers over the console)
  • an SSH key at ~/.ssh/vmctl_ed25519:
ssh-keygen -t ed25519 -f ~/.ssh/vmctl_ed25519 -N ''

Quick start

./vmctl bake freebsd-14.4      # one-time, slow: provision and keep the result
./vmctl up freebsd-14.4        # seconds, from the baked image
./vmctl ssh freebsd-14.4

./vmctl with no arguments lists every command.

The image tiers

The reason bake exists is that a cold FreeBSD cloud image is expensive to boot: its firstboot service downloads and applies the full patch set for the release, then reboots, which takes minutes. Paying that per rebuild would make the whole loop useless, so it is paid once:

Tier File Cost Made by
base <guest>.base.qcow2 one download fetch
golden <guest>.golden.qcow2 one slow boot bake
overlay <guest>.qcow2 instant create

Guests run on the overlay, so the state you break is never the state you paid for. rebuild throws the overlay away and makes a new one — a few seconds back to a clean machine. purge drops everything including the download, for verifying the whole flow from nothing.

One consequence is worth internalizing: a guest built on the golden image boots already provisioned, so its seed is never applied again. Editing cloud-init/ or a guest's PACKAGES therefore does nothing until you bake again — create warns when it spots this.

Getting code into a guest

Two paths, deliberately:

./vmctl clone freebsd-14.4 https://github.com/you/project    # pristine
./vmctl sync  freebsd-14.4 ~/source/project                  # working tree

clone gets committed state only, which is exactly right for checking that the documented build-from-source path works for a real user. sync rsyncs your working tree including uncommitted changes, which is what you want while iterating on a port. It excludes build*/ so host build trees — wrong architecture — never reach the guest, and keeps .git so version stamping still works.

Provisioners

Guests differ only in how they first come into existence, selected by PROVISIONER in the guest file:

  • nocloud (default) — boot a vendor cloud image and configure it from a cloud-init seed. Used by the FreeBSD guests.
  • autoinstall — no cloud image exists, so install once from official media by answering the installer over the serial console (provision/autoinstall.py), then run a POST_INSTALL script over SSH. Used by the OpenBSD guest.

Both converge on the same golden image, so everything after bake — create, up, ssh, sync, rebuild — is identical.

Adding a guest

Drop a file in guests/. It is plain shell, sourced by vmctl; see guests/freebsd-14.4.conf. Give each guest a unique SSH_PORT, and a unique HTTP_PORT too if it autoinstalls.

Pick the guest login with care. GUEST_USER must not collide with a system account on the target OS — build, an obvious choice, is taken on OpenBSD (uid 21, home /var/empty), and its installer silently declines to create a user that already exists, which surfaces much later as a login that cannot authenticate. The guests here use builder.

Notes on FreeBSD guests

FreeBSD's cloud images are provisioned by nuageinit(8), the base-system Lua implementation of cloud-init, not the Python one. It reads the same NoCloud seed but supports a subset, and three details cost real debugging time:

  • runcmd entries must be plain strings. Upstream's [sh, -c, "..."] exec form is accepted and silently ignored.
  • A user created without a password ends up *LOCKED*, and FreeBSD's sshd refuses a locked account even for publickey auth. The seed runs pw unlock to undo this. Do not add locked: true — that is the same lock, and it makes the guest permanently unreachable.
  • PermitRootLogin no is the default and nuageinit does not edit sshd_config, so there is no root login. The build user has passwordless sudo.
  • The login greeting has two independent sources: login(1) prints the motd unless ~/.hushlogin exists, and the skel dotfiles run fortune(6) from both .profile and .login. The seed handles all of them; suppressing only the motd still leaves a tip above every prompt.

Unrelated to cloud-init, one QEMU detail matters: the seed volume must not win the firmware's boot order, so both drives carry an explicit bootindex. Without it SeaBIOS reports "No bootable device" to the VGA console, which the serial log does not capture — the guest simply looks dead.

Notes on OpenBSD guests

OpenBSD publishes no cloud image, so the guest is installed from install79.iso via autoinstall(8). The response file answers only what must differ from the defaults; anything it omits takes the installer's default answer.

  • The console is the hard part. QEMU's -nographic sets a fw_cfg flag that moves the firmware and bootloader onto the serial line. -display none does not, and neither does -vga none: with those the guest boots invisibly and the driver waits forever. -nographic combined with an explicit -serial unix:... gets both the flag and a socket to script against.
  • The bootloader's boot> prompt times out in about five seconds, so the reply must be driven by matching output rather than by sleeping. The socket is opened with wait=on so the machine cannot start before the driver has connected.
  • Change the default console to com0 matters for every later boot; without it the installed system talks to a screen nobody reads.
  • There is no working response-file question for a user's ssh key. Such a line is accepted and ignored, so only root gets a key at install time and the guest user is set up afterwards by provision/openbsd-post.sh.
  • No sudo in base: escalation is doas, keyed on wheel membership.
  • pkg_add rejects an ambiguous name when a package ships flavours, so PACKAGES uses rsync-- to select the unflavoured one.

About

Disposable QEMU guests for cross-platform testing.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages