Skip to content

Adding an OS image ​

How to teach vz a new cloud disk or installer ISO, so users can vz image pull it and paste the printed disks line into a node.

An OS image is one image maker file and one line in the catalog. The image maker fetches the file and turns it into a disk or ISO. It does not build the VM: a node boots that file on its platform, which for every OS except macOS is the default generic UEFI machine. The engine and the platforms do not change. Read VM assembly first if you have not.

Before you start ​

Find out what the distribution publishes for arm64 / aarch64:

  • [ ] A URL for the image that stays stable, or a folder plus a checksum list that names the current file
  • [ ] A checksum list next to it (SHA256SUMS, CHECKSUM, *.SHA512, ...)
  • [ ] The file format: raw, raw in tar.xz, raw in .xz, qcow2, or ISO
  • [ ] Whether the image has cloud-init (or another reader of the NoCloud seed), and whether it uses the virtio serial console (hvc0) for its login prompt

IMPORTANT

Virtualization cannot open qcow2. vz converts qcow2 to sparse raw (with qemu-img when it is installed, otherwise its own converter). The built-in converter refuses backing files, encryption, external data files, extended L2 entries and zstd compression.

1. Write the image maker ​

Create Sources/LabOS/Images/<Family>.swift. Model it on an existing maker of the same shape:

Upstream formatModel onUnpacker
qcow2Rocky.swift, Ubuntu.swiftQCOW2ToRaw()
raw inside tar.xzDebian.swiftTarXZMember(member: "disk.raw")
raw compressed with xzno shipped maker uses it yetXZToRaw()
ISODebianNetinst in Debian.swiftKeepAsIs()

A skeleton for a qcow2 cloud disk, based on RockyCloudDisk:

swift
// Example.swift
//
// Example Linux GenericCloud, qcow2.

import Foundation
import LabCore
import LabImages

public struct ExampleCloudDisk: DownloadImageMaker {
    public let version: Int
    public let reference: ImageReference
    public let aliases: [String]

    public init(version: Int, aliases: [String] = []) {
        self.version = version
        self.reference = ImageReference(.disk, "example-\(version)")
        self.aliases = aliases
    }

    public var title: String { "Example Linux \(version) GenericCloud" }
    public var notes: String { "qcow2, converted to raw" }

    public var artifact: Artifact {
        let base = "https://download.example.org/\(version)/images/aarch64/"
        let file = "Example-\(version)-GenericCloud.latest.aarch64.qcow2"
        return Artifact(
            source: FixedFile(URL(string: base + file)!),
            checksums: URL(string: base + file + ".CHECKSUM")!,
            digest: .sha256,
            unpacker: QCOW2ToRaw(),
            fileName: "example-\(version)-cloud-arm64.raw"
        )
    }

    public func labFileLines(path: String) -> [String] { LabFileLines.cloudDisk(path: path) }
}

What each piece does:

MemberMeaning
referenceKind and name: ImageReference(.disk, "example-10") or ImageReference(.iso, ...). Lowercase letters, digits, - and .
aliasesOther names, for example ["example"] for the newest release. Names and aliases must not collide within a kind
title, notesShown by vz image ls
supportDefaults to .tested. Use .experimental("what is missing") until it boots to a login prompt
artifact.sourceFixedFile(url), or NewestListedFile(in:prefix:suffix:) when the name carries a point release
artifact.checksumsThe published checksum list. GNU, BSD and one-digest formats are all read
artifact.digest.sha256 or .sha512, matching the list
artifact.fileNameThe name in ~/.vz/images. Keep it free of point releases so lab files keep working after an update
labFileLines(path:)The disks line image pull prints for the user to paste. Use LabFileLines.cloudDisk or LabFileLines.installer

An image maker has no plan method: it never decides the machine. A node that boots the file is a generic node by default, which is GenericUEFI with the virtio serial console. If the OS needs first-boot defaults, they belong in its user-data, not in the engine. Only an OS that needs a machine type Virtualization offers besides the generic one needs a platform; see Adding a platform. The node never names the image.

If a family has more than one image, share code through a helper in the same file (like DebianCloudDisk and DebianNetinst in Debian.swift), never a base class and never a call into another family's maker.

An image maker with its own source ​

If the image does not fit Artifact (for example it needs an API call to find the file), conform to ImageMaker instead of DownloadImageMaker and implement fileName and fetch(with:events:) yourself, as MacOSImage does.

2. Register it ​

Add one line to StandardImages.all in ImageCatalog.swift, under "Cloud disks" or "Installer ISOs":

swift
ExampleCloudDisk(version: 10, aliases: ["example"]),

The order of this list is the order of vz image ls. ImageCatalog fails a precondition (the process stops) if two makers have the same reference.

3. Test it ​

Add cases to Tests/LabOSTests/ImageTests.swift:

  • the name and aliases resolve (catalog.image(ImageReference(.disk, "example")))
  • the artifact: file name, resolved upstream name, unpacker type, digest
  • labFileLines prints a disks line and no image key
bash
make test-core

These tests inspect the makers; they download nothing and create no VMs.

4. Boot it ​

Pull it and boot a one-node lab with a cloud-init seed:

bash
.build/debug/vz image ls disk
.build/debug/vz image pull disk example-10
cd "$(mktemp -d)"
.build/debug/vz init     # then paste the printed disks line into the node
.build/debug/vz up
.build/debug/vz node console vm1

TIP

Use examples/11-multi-distro as a template: its init/<distro>/user-data files create the lab user the same way on every distribution.

Mark the image .tested only when the guest reaches a login prompt (or its own ready signal), gets a DHCP address and runs the cloud-init seed. Otherwise leave it .experimental with a reason that tells users where it stops.

5. Document it ​

  • Add a row to the image table in Images.
  • If the image needs anything unusual (a different kernel for displays, a different console), say so in its notes and in the guide.
  • Consider adding it to an example lab, for example examples/11-multi-distro. See Writing examples.

See also ​