Files
lw-everestlinuxandClaude Opus 5.5 f687558b66 Initial import: build and boot Everest Linux in QEMU
everest.sh builds Everest's signed packages in an Alpine container,
publishes the base, extra and extra-src repositories, installs the
system with glacier-bootstrap into an initramfs and boots it in QEMU.
The image carries glacier, a toolchain and the repositories, and builds
packages from source inside the VM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 09:33:38 -04:00

131 lines
5.1 KiB
Bash
Executable File

#!/bin/sh
# everest.sh - build and boot a minimal Everest system.
#
# ./everest.sh keygen make the signing key (once)
# ./everest.sh build PKG build one package into pkgs/, signed
# ./everest.sh build all every package in PACKAGES (below)
# ./everest.sh adopt DIR take packages built from recipes into pkgs/
# ./everest.sh publish sign the repositories into repo/
# ./everest.sh initramfs assemble boot/vmlinuz + boot/initramfs.gz
# ./everest.sh boot boot it in QEMU on this terminal
#
# The repositories (repo/{base,extra,extra-src}) are published at
# https://pkg.everestlinux.org/REPO, which everest-repos' repos.conf
# lists. Until that server exists, initramfs and boot serve repo/ under
# that name locally, over https with a throwaway test CA (testca/):
# initramfs inside its container, boot to the VM (guest 10.0.2.100:443,
# relayed with socat). In the VM, run
# sh /sys/firmware/qemu_fw_cfg/by_name/opt/everest/testnet/raw
# to bring up the network and trust the test CA (scripts/vm-testnet.sh;
# neither is shipped). EVEREST_MEM / EVEREST_CPUS size the VM.
#
# Packages are built inside an Alpine container (Dockerfile.build), so
# they target musl. glacier-ng and libglacier-ng default to siblings of
# this directory; override with GLACIER_NG / LIBGLACIER_NG.
#
# Every package's sidecar is signed (REPO_DESIGN.txt section 7: syspkg
# installs a base package only with a signature by a key trusted for
# base). The SECRET key lives outside this tree, in EVEREST_KEYS
# (default ~/.config/everest/keys), and is mounted read-only into the
# build container; the public key ships in everest-repos.
set -eu
HERE="$(cd "$(dirname "$0")" && pwd)"
GLACIER_NG="${GLACIER_NG:-$HERE/../glacier-ng}"
LIBGLACIER_NG="${LIBGLACIER_NG:-$HERE/../libglacier-ng}"
IMAGE=everest-build
EVEREST_KEYS="${EVEREST_KEYS:-$HOME/.config/everest/keys}"
KEY_NAME=everest-2026
PACKAGES="musl busybox linux everest-bootscripts everest-repos zlib libarchive libconfig luajit libglacier-ng glacier-ng doas libressl ca-certificates curl linux-headers binutils make gcc"
# in_container KEYS ARGS...: run container.sh ARGS in the build image.
# KEYS is "ro" or "rw" to mount EVEREST_KEYS at /keys, "-" for none.
# MOUNT=SRC:DST[:ro] adds one more mount.
in_container() {
keys="$1"; shift
docker build -q -t "$IMAGE" -f "$HERE/Dockerfile.build" "$HERE" >/dev/null
if [ "$keys" = - ]; then
set -- "$IMAGE" sh /everest/scripts/container.sh "$@"
else
set -- -v "$EVEREST_KEYS:/keys:$keys" "$IMAGE" sh /everest/scripts/container.sh "$@"
fi
docker run --rm \
-e HOST_UID="$(id -u)" -e HOST_GID="$(id -g)" -e KEY_NAME="$KEY_NAME" \
-v "$HERE:/everest" \
-v "$(cd "$GLACIER_NG" && pwd):/glacier-ng:ro" \
-v "$(cd "$LIBGLACIER_NG" && pwd):/libglacier-ng:ro" \
${MOUNT:+-v "$MOUNT"} \
"$@"
}
case "${1:-}" in
keygen)
if [ -e "$EVEREST_KEYS/$KEY_NAME.sec" ] || [ -e "$EVEREST_KEYS/$KEY_NAME.pub" ]; then
echo "[x] $EVEREST_KEYS/$KEY_NAME already exists." >&2
exit 1
fi
mkdir -p "$EVEREST_KEYS" && chmod 700 "$EVEREST_KEYS"
in_container rw keygen
;;
build)
pkg="${2:?usage: $0 build PKG|all}"
if [ ! -r "$EVEREST_KEYS/$KEY_NAME.sec" ]; then
echo "[x] Missing signing key $EVEREST_KEYS/$KEY_NAME.sec." >&2
exit 1
fi
if [ "$pkg" = all ]; then
for p in $PACKAGES; do in_container ro build "$p"; done
else
in_container ro build "$pkg"
fi
;;
adopt)
dir="$(cd "${2:?usage: $0 adopt DIR}" && pwd)"
if [ ! -r "$EVEREST_KEYS/$KEY_NAME.sec" ]; then
echo "[x] Missing signing key $EVEREST_KEYS/$KEY_NAME.sec." >&2
exit 1
fi
MOUNT="$dir:/adopt:ro" in_container ro adopt /adopt
;;
publish)
if [ ! -r "$EVEREST_KEYS/$KEY_NAME.sec" ]; then
echo "[x] Missing signing key $EVEREST_KEYS/$KEY_NAME.sec." >&2
exit 1
fi
in_container ro publish
;;
initramfs)
in_container - initramfs
;;
boot)
# Press Enter for a root shell. Leave with `poweroff -f`, or Ctrl-A X.
# Drop -enable-kvm if /dev/kvm isn't available.
set -- -enable-kvm -m "${EVEREST_MEM:-6144}" -smp "${EVEREST_CPUS:-2}" -nographic \
-kernel "$HERE/boot/vmlinuz" -initrd "$HERE/boot/initramfs.gz" \
-append "console=ttyS0 rdinit=/init"
# The local repo/ as https://pkg.everestlinux.org (see the top).
if [ -f "$HERE/repo/base/repo.idx" ] && [ -f "$HERE/testca/server.pem" ]; then
port="${EVEREST_SERVE_PORT:-8443}"
(cd "$HERE/repo" && exec openssl s_server -quiet -WWW -accept "127.0.0.1:$port" \
-cert "$HERE/testca/server.pem" -key "$HERE/testca/server.key" >/dev/null 2>&1) &
server=$!
trap 'kill $server 2>/dev/null' EXIT
set -- "$@" -netdev "user,id=net0,guestfwd=tcp:10.0.2.100:443-cmd:socat STDIO TCP:127.0.0.1:$port" \
-device virtio-net-pci,netdev=net0 \
-fw_cfg "name=opt/everest/testca,file=$HERE/testca/ca.pem" \
-fw_cfg "name=opt/everest/testnet,file=$HERE/scripts/vm-testnet.sh"
fi
# repo/ itself, shared read-only: scripts/vm-testnet.sh mounts it
# over the image's copy at /srv/everest, so `everest.sh publish`
# reaches a running VM (syspkg -y) without a new initramfs.
if [ -f "$HERE/repo/base/repo.idx" ]; then
set -- "$@" -virtfs "local,path=$HERE/repo,mount_tag=everest-repo,security_model=none,readonly=on"
fi
qemu-system-x86_64 "$@"
;;
*)
sed -n '2,30p' "$0"
exit 1
;;
esac