diff options
Diffstat (limited to 'images/debian/genimg')
| -rwxr-xr-x | images/debian/genimg | 300 | +0 −300 |
1 files changed, 0 insertions, 300 deletions
diff --git a/images/debian/genimg b/images/debian/genimg deleted file mode 100755 --- a/images/debian/genimg +++ /dev/null @@ -1,300 +0,0 @@ -#!/bin/sh -eux -# SPDX-FileCopyrightText: 2017-2026 Drew DeVault -# SPDX-FileCopyrightText: 2026 Nikolay Govorov -# SPDX-License-Identifier: AGPL-3.0-only - -self=$(dirname "$(readlink -f "$0")") -cd "$self" - -release=${1:-} -arch=${2:-amd64} - -case $release in -bookworm | forky | sid | trixie) ;; -*) - echo "usage: ${0##*/} <bookworm|forky|sid|trixie> [arch]" >&2 - exit 1 - ;; -esac - -case $arch in -amd64) - darch=amd64 - iface=ens3 - kpkg=linux-image-amd64 - ;; -arm64) - darch=arm64 - iface=enp0s1 - kpkg=linux-image-arm64 - ;; -ppc64le) - darch=ppc64el - iface=enp0s0 - kpkg=linux-image-powerpc64le - ;; -*) - echo "unsupported architecture $arch" - exit 1 - ;; -esac - -cleanup() { - # The order here is important if you don't want to hose your mounts - cat /mnt/debootstrap/debootstrap.log || true - umount /mnt/dev/pts 2>/dev/null || true - umount /mnt/dev/shm 2>/dev/null || true - umount /mnt/dev 2>/dev/null || true - umount /mnt/proc 2>/dev/null || true - umount /mnt/run 2>/dev/null || true - umount /mnt/sys 2>/dev/null || true - umount /mnt/boot 2>/dev/null || true - umount /mnt 2>/dev/null || true - qemu-nbd --disconnect /dev/nbd0 || true -} - -out="$release/$arch" -size_gib=32 -mkdir -p "$out" - -# .hmi (Hule Machine Image): plain qcow2 restricted to a feature subset that -# materializes losslessly to raw (no internal snapshots/bitmaps/encryption). -# Base image = chain root, so no backing. Never `qemu-img snapshot` it. -qemu-img create -f qcow2 -o compat=1.1 "$out/root.hmi" "${size_gib}G" -modprobe nbd max_part=16 -qemu-nbd --connect=/dev/nbd0 "$out/root.hmi" -for i in $(seq 1 5); do - sleep "0.$i" - partprobe /dev/nbd0 && break -done -trap cleanup EXIT - -if [ "$arch" = "amd64" ]; then - dd if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/nbd0 bs=1 count=440 -fi - -sfdisk --no-reread /dev/nbd0 <<EOF -1M,256M,L,* -,2048M,S -,,L -EOF - -mkfs.ext4 /dev/nbd0p1 -mkswap /dev/nbd0p2 -mkfs.ext4 /dev/nbd0p3 - -mount /dev/nbd0p3 /mnt -mkdir /mnt/boot -mount /dev/nbd0p1 /mnt/boot - -if [ "$arch" = "amd64" ]; then - debootstrap --include=gnupg2 --arch="$darch" "$release" /mnt -else - ./qemu-debootstrap --include=gnupg2 --arch="$darch" "$release" /mnt -fi - -mount --bind /dev /mnt/dev -mount --bind /dev/pts /mnt/dev/pts -mount --bind /dev/shm /mnt/dev/shm -mount --bind /proc /mnt/proc -mount --bind /run /mnt/run -mount --bind /sys /mnt/sys - -run_root() { - chroot /mnt /usr/bin/env \ - PATH=/sbin:/usr/sbin:/bin:/usr/bin \ - sh -c "$*" -} - -echo 'nameserver 8.8.8.8' >/mnt/etc/resolv.conf -echo 'nameserver 9.9.9.9' >>/mnt/etc/resolv.conf -echo 'nameserver 1.1.1.1' >>/mnt/etc/resolv.conf -cat >/mnt/etc/network/interfaces <<EOF -auto lo -iface lo inet loopback - -auto $iface -iface $iface inet static - hostname build - address 10.0.2.15 - netmask 255.255.255.0 - gateway 10.0.2.2 -EOF -echo build >/mnt/etc/hostname -cat >/mnt/etc/hosts <<EOF -127.0.0.1 build localhost -EOF - -echo 'APT::Install-Recommends "False";' >/mnt/etc/apt/apt.conf.d/60recommends - -run_root apt-get update -run_root apt-get -y install locales -run_root apt-get -y install $kpkg -run_root apt-get -y install build-essential git mercurial ssh sudo \ - gnupg dirmngr ca-certificates apt-transport-https curl dbus \ - systemd-timesyncd ncurses-term qemu-guest-agent - -run_root ln -sf /usr/share/zoneinfo/UTC /etc/localtime -run_root systemctl enable systemd-timesyncd.service - -run_root useradd -mG sudo build -run_root passwd -d build -echo '%sudo ALL=(ALL) NOPASSWD: ALL' >>/mnt/etc/sudoers - -echo "PermitEmptyPasswords yes" >>/mnt/etc/ssh/sshd_config -echo ssh >>/mnt/etc/securetty -run_root systemctl enable ssh -run_root systemctl enable qemu-guest-agent - -# Prevent docker from mucking up networking -mkdir -p /mnt/etc/docker -cat >/mnt/etc/docker/daemon.json <<EOF -{ - "bip": "172.18.0.1/16" -} -EOF - -run_root update-initramfs -u - -kernel_path= -for candidate in /mnt/boot/vmlinuz-*; do - [ -e "$candidate" ] || continue - kernel_path=$candidate - break -done -[ -n "$kernel_path" ] -linuxver=${kernel_path##*/vmlinuz-} - -# Reference partitions by PARTUUID so boot survives whatever the VMM names the -# disk. cmdline is canonical: identical for every boot protocol (extlinux append -# here, -append on the direct path) -- see docs/boot-protocol.md. -boot_partuuid=$(blkid -s PARTUUID -o value /dev/nbd0p1) -swap_partuuid=$(blkid -s PARTUUID -o value /dev/nbd0p2) -root_partuuid=$(blkid -s PARTUUID -o value /dev/nbd0p3) -cmdline="root=PARTUUID=$root_partuuid rw quiet" - -cat >>/mnt/etc/fstab <<EOF -PARTUUID=$boot_partuuid /boot ext4 rw,relatime,data=ordered 0 0 -PARTUUID=$swap_partuuid swap swap defaults 0 0 -PARTUUID=$root_partuuid / ext4 rw,relatime,data=ordered 0 0 -EOF - -# Boot setup: amd64 self-boots via extlinux (firmware-disk/bios); other arches -# have no in-image bootloader, the VMM boots the extracted kernel directly. -case "$arch" in -amd64) - run_root apt-get -y install extlinux - extlinux -i /mnt/boot - - cat >/mnt/boot/extlinux.conf <<-EOF - default debian - label debian - linux vmlinuz-$linuxver - initrd initrd.img-$linuxver - append $cmdline - EOF - ;; -arm64) - cp /mnt/boot/vmlinuz-* "$out/vmlinuz" - cp /mnt/boot/initrd.img-* "$out/initrd" - ;; -ppc64le) - cp /mnt/boot/vmlinux-* "$out/vmlinux" - cp /mnt/boot/initrd.img-* "$out/initrd" - ;; -esac - -sync - -# Detach the disk so root.hmi is fully flushed before hashing; disarm cleanup. -cleanup -trap : EXIT - -# --- Hule machine configuration (`config.json`) ------------------------------ -disk_sha=$(sha256sum "$out/root.hmi" | cut -d' ' -f1) -disk_bytes=$(stat -c%s "$out/root.hmi") -virtual_bytes=$((size_gib * 1024 * 1024 * 1024)) -mem_min=$((256 * 1024 * 1024)) -mem_def=$((1024 * 1024 * 1024)) - -case "$arch" in -amd64) - # Legacy BIOS: extlinux in an MBR disk, booted by the VMM's BIOS firmware. - protocols=$( - cat <<JSON - { - "protocol": "firmware-disk/bios", - "disk": "root" - } -JSON - ) - ;; -arm64) - kernel_sha=$(sha256sum "$out/vmlinuz" | cut -d' ' -f1) - initrd_sha=$(sha256sum "$out/initrd" | cut -d' ' -f1) - protocols=$( - cat <<JSON - { - "protocol": "linux/direct", - "disk": "root", - "kernel": { "path": "vmlinuz", "digest": "sha256:$kernel_sha" }, - "initrd": { "path": "initrd", "digest": "sha256:$initrd_sha" }, - "cmdline": "$cmdline" - } -JSON - ) - ;; -ppc64le) - kernel_sha=$(sha256sum "$out/vmlinux" | cut -d' ' -f1) - initrd_sha=$(sha256sum "$out/initrd" | cut -d' ' -f1) - protocols=$( - cat <<JSON - { - "protocol": "linux/direct", - "disk": "root", - "kernel": { "path": "vmlinux", "digest": "sha256:$kernel_sha" }, - "initrd": { "path": "initrd", "digest": "sha256:$initrd_sha" }, - "cmdline": "$cmdline" - } -JSON - ) - ;; -esac - -cat >"$out/config.json" <<EOF -{ - "schemaVersion": 1, - "kind": "MachineImage", - - "system": { - "os": "linux", - "name": "debian", - "version": "$release", - "architecture": "$arch" - }, - - "machine": { - "cpu": { "minimum": 1, "default": 2 }, - "ram": { "minimum": $mem_min, "default": $mem_def }, - "boot": [ -$protocols - ], - "access": [ - { "type": "ssh", "port": 22, "user": "build", "auth": "empty-password" }, - { "type": "qga" } - ], - "network": { "mode": "static", "address": "10.0.2.15/24", "gateway": "10.0.2.2" } - }, - - "disks": [ - { - "id": "root", - "format": "qcow2", - "path": "root.hmi", - "digest": "sha256:$disk_sha", - "virtSize": $virtual_bytes, - "diskSize": $disk_bytes - } - ] -} -EOF |
