Building an Ubuntu image

Build an Ubuntu node image by installing the required packages, pointing chrony at internal time sources, removing public repositories, and cleaning the VM before upload.

Start from the official Ubuntu cloud image for amd64, or the provider-specific variant in the section Provider requirements. Run all steps as root in a booted virtual machine that can reach your package sources, and keep cloud-init installed. If a tool such as Packer runs these steps and snapshots the VM, leave out the final shutdown, because the tool stops the VM itself. Keep every other clean-up command. The tool logs in with its own temporary SSH key, which stays in the image unless the clean-up step removes it.

  1. Wait for the first boot to finish, then install the packages.

    Until cloud-init finishes, it can hold the package manager lock.

    cloud-init status --wait || true
    export DEBIAN_FRONTEND=noninteractive
    apt-get update
    apt-get install -y \
      apparmor apt-transport-https conntrack dbus libseccomp2 nfs-common \
      python3-apt python3-kubernetes python3-minimal socat \
      software-properties-common openssh-server openssh-client \
      cloud-init haproxy chrony ca-certificates
  2. Stop the services and timers that must not run or reach out from the image.

    Bootstrap enables haproxy on the Kubernetes bastion node only.

    DEBIAN_FRONTEND=noninteractive apt-get purge -y unattended-upgrades
    systemctl disable --now haproxy
    systemctl disable --now apt-daily.timer apt-daily-upgrade.timer
    systemctl disable motd-news.timer ua-timer.timer 2>/dev/null || true
  3. Point chrony at internal time sources.

    This step is required. Add server <ntp-server> iburst lines to /etc/chrony/chrony.conf. Remove the public pools of Ubuntu. On Ubuntu 26.04, they are in /etc/chrony/sources.d/ubuntu-ntp-pools.sources, which you delete. Installing chrony removes systemd-timesyncd, so chrony is the only time service in the image. Bootstrap replaces chrony.conf only when the access profile sets NTP servers.

  4. Add your private CA, if you have one, and check that the system trusts it.
    cp internal-ca.crt /usr/local/share/ca-certificates/internal-ca.crt
    update-ca-certificates
    openssl verify -CAfile /etc/ssl/certs/ca-certificates.crt \
      /usr/local/share/ca-certificates/internal-ca.crt
  5. Remove the public repositories.
    rm -f /etc/apt/sources.list /etc/apt/sources.list.d/ubuntu.sources
  6. If you use a mirror, add it, and then refresh the package lists from it.

    The refresh checks the mirror, its signing key, and your CA while you can still fix them, and it leaves the mirror package lists in the image. Replace the URL, the suites, and the key path with your own.

    install -d -m 0755 /etc/apt/keyrings
    cp internal-mirror.gpg /etc/apt/keyrings/internal-mirror.gpg
    cat > /etc/apt/sources.list.d/internal-mirror.sources <<'EOF'
    Types: deb
    URIs: <package-mirror>/ubuntu
    Suites: resolute resolute-updates resolute-security
    Components: main universe
    Signed-By: /etc/apt/keyrings/internal-mirror.gpg
    EOF
    apt-get update
  7. Stop cloud-init from rewriting the repository configuration on first boot.
    cat > /etc/cloud/cloud.cfg.d/99-air-gapped.cfg <<'EOF'
    apt:
      preserve_sources_list: true
    package_update: false
    package_upgrade: false
    EOF

    With a pass-through mirror, you can instead let cloud-init generate the repository configuration from the mirror on every first boot. Put the following block in the same file in place of the apt: section, and keep package_update and package_upgrade. cloud-init writes /etc/apt/sources.list.d/ubuntu.sources with the distribution signing keys, so in step 6 write your mirror to that file instead of a separate internal-mirror.sources file, to avoid listing the same repositories twice.

    apt:
      preserve_sources_list: false
      primary:
        - arches: [default]
          uri: <package-mirror>/ubuntu
      security:
        - arches: [default]
          uri: <package-mirror>/ubuntu
  8. Clean up and shut down.

    Do not log in to the VM again after this step. If you use a mirror, leave out the rm -rf /var/lib/apt/lists/* line so that the image keeps the mirror package lists from step 6.

    apt-get clean
    rm -rf /var/lib/apt/lists/*
    rm -f /etc/ssh/ssh_host_* /root/.ssh/authorized_keys /home/*/.ssh/authorized_keys
    cloud-init clean --logs --machine-id --seed
    shutdown -h now

The VM is stopped and its disk is ready to upload.