Boot large signed package roots from disposable ext2 test volumes
@@ -72,3 +72,5 @@ python3 tools/build-queue.py --reserve-mib 6144 "$arch" "$plan/order.tsv" "$port
72Each port gets a fresh, signed SDK containing its transitive prerequisites. The queue records recipe and dependency hashes, compiler logs and ELF page results. A subsequent port consumes an archive after its final checksum is available. Exit status 2 reports outstanding input packages. Rerunning reuses verified outputs and reclaims interrupted scratch directories. The worker built musl-fts, resumed it, and rejected an incorrect input version and a damaged receipt in `foundation/queue-test-03`, receipt SHA-256 `1de747944bd569219494cd127fc1f42cf110f7b0ad2a4e513099249a2e0b3bb1`. Two concurrent resumptions passed in `foundation/queue-resume-04`, receipt SHA-256 `a58a80c0050294666d4ecd41ce5c2affc371c5fbeb58fc672e98a9b7c8c3b14b`.
173
274The published x86_64 Vinix kernel booted 32 signed network packages. It refreshed the trust store with a local CA, established loopback HTTPS, rejected the wrong hostname, committed and read a Git file, signed and verified that file with the installed SSH tools, then installed and queried a local XBPS package. The fixture and logs are `tests/userland/network.sh` and `foundation/network-guest-03`, receipt SHA-256 `4e9afac33947b999911a4ff35f218b49f3356b345e47e7b90e7ffce644d0c7b4`.
75+
76+For package roots too large for a test initramfs, use `python3 tests/disk-root.py "$arch" "$root" "$fixture" "$iso" "$boot" "$output"` on the worker. The root must supply BusyBox init, and the fixture prints `VPAC FIXTURE GUEST PASS` after its checks. The helper creates a fresh ext2 image file from a private copy and runs QEMU in snapshot mode. The x86_64 release kernel read the matching disk identity and relocated all 109 dynamic executable paths from a 106-package root with 512 MiB of guest RAM. The test retains its ext2 and serial hashes under `foundation/disk-exec-x86-02/test`, receipt SHA-256 `6f600855744d04fa71d916f545e746ed36ba2686a56937c2b4c3cb02e3ec6a58`.
@@ -12,7 +12,7 @@ fn run(argv []string) ! {
1212 }
1313}
1414
15-fn boot_image(root string, iso string, output string, mode string, fixture string) ! {
15+fn boot_image(root string, iso string, output string, mode string, fixture string, disk string) ! {
1616 shell := mode == '--shell'
1717 arm := mode.starts_with('--aarch64-')
1818 userland := mode in ['--userland', '--aarch64-userland'] || fixture != ''
@@ -22,6 +22,12 @@ fn boot_image(root string, iso string, output string, mode string, fixture strin
2222 if root == '/' || output == root || output.starts_with(root + '/') {
2323 return error('place the output outside a separate BusyBox package root')
2424 }
25+ if disk != '' {
26+ info := os.stat(disk)!
27+ if info.get_filetype() != .regular || !os.is_file(os.join_path(root, '.vinix-image-id')) {
28+ return error('disk fixtures require a regular image file and a matching initramfs seed')
29+ }
30+ }
2531 digest := sha256.sum(os.read_bytes(os.join_path(root, 'bin/busybox'))!).hex()
2632 helper := if userland {
2733 'userland-check.sh'
@@ -72,9 +78,10 @@ fn boot_image(root string, iso string, output string, mode string, fixture strin
7278 ['boot/limine-bios.sys', 'boot/limine-bios-cd.bin']
7379 }
7480 run(['bsdtar', '-xf', iso, '-C', os.dir(boot), 'boot/vinix', ...boot_files])!
81+ disk_mode := if disk == '' { 'live' } else { 'legacy' }
7582 os.write_file(os.join_path(boot, 'limine.conf'), 'timeout: 0\nserial: yes\nverbose: yes\n/BusyBox\n' +
7683 ' protocol: limine\n kernel_path: boot():/boot/vinix\n resolution: 1024x768x32\n' +
77- ' kaslr: no\n module_path: boot():/boot/initramfs.tar.gz\n cmdline: vinix.disk=live\n')!
84+ ' kaslr: no\n module_path: boot():/boot/initramfs.tar.gz\n cmdline: vinix.disk=${disk_mode}\n')!
7885 run(['tar', '--format=ustar', '--owner=0', '--group=0', '-czf', os.join_path(boot,
7986 'initramfs.tar.gz'), '-C', root, '.', '-C', additions, './etc', './' + helper])!
8087 test_iso := os.join_path(output, if shell { 'busybox-shell.iso' } else { 'busybox.iso' })
@@ -102,6 +109,15 @@ fn boot_image(root string, iso string, output string, mode string, fixture strin
102109 } else {
103110 ['qemu-system-x86_64', '-machine', 'q35', '-vga', 'std', '-cdrom', test_iso, '-boot', 'd']
104111 }
112+ if disk != '' {
113+ drive := 'format=raw,snapshot=on,file=' + disk.replace(',', ',,')
114+ if arm {
115+ emulator << ['-drive', 'if=none,id=ports,' + drive, '-device', 'virtio-blk-device,drive=ports']
116+ } else {
117+ // The x86 release kernel probes ATA and AHCI before choosing the root.
118+ emulator << ['-drive', 'if=ide,' + drive]
119+ }
120+ }
105121 memory := if userland {
106122 '512'
107123 } else if arm {
@@ -113,6 +129,12 @@ fn boot_image(root string, iso string, output string, mode string, fixture strin
113129 'none', '-monitor', 'none', '-serial', 'file:' + log, '-no-reboot']
114130 run(['timeout', '120s', ...emulator])!
115131 lines := os.read_lines(log)!.map(it.trim_space())
132+ if disk != '' {
133+ id := os.read_file(os.join_path(root, '.vinix-image-id'))!.trim_space()
134+ if id == '' || 'VPAC DISK ROOT ${id}' !in lines {
135+ return error('guest did not read the matching volume identity; see ${log}')
136+ }
137+ }
116138 if userland {
117139 pass := if fixture != '' { 'VPAC FIXTURE GUEST PASS' } else { 'VPAC USERLAND GUEST PASS' }
118140 if pass !in lines {
@@ -132,16 +154,19 @@ fn boot_image(root string, iso string, output string, mode string, fixture strin
132154
133155fn main() {
134156 mode := if os.args.len >= 5 { os.args[4] } else { '' }
157+ disk_mode := mode in ['--disk-fixture', '--aarch64-disk-fixture']
135158 script_mode := mode in ['--fixture', '--aarch64-fixture']
136159 if !(os.args.len == 4 || (os.args.len == 5 && mode in ['--shell', '--musl', '--aarch64-musl',
137- '--userland', '--aarch64-userland']) || (os.args.len == 6 && script_mode)) {
138- eprintln('usage: boot.v ROOT ISO NEW_DIRECTORY [--shell|--musl|--aarch64-musl|--userland|--aarch64-userland|--fixture SCRIPT|--aarch64-fixture SCRIPT]')
160+ '--userland', '--aarch64-userland']) || (os.args.len == 6 && script_mode)
161+ || (os.args.len == 7 && disk_mode)) {
162+ eprintln('usage: boot.v ROOT ISO NEW_DIRECTORY [--shell|--musl|--aarch64-musl|--userland|--aarch64-userland|--fixture SCRIPT|--aarch64-fixture SCRIPT|--disk-fixture SCRIPT DISK|--aarch64-disk-fixture SCRIPT DISK]')
139163 exit(2)
140164 }
141165 output := os.abs_path(os.args[3])
142166 new_dir := os.join_path(os.real_path(os.dir(output)), os.file_name(output))
143- fixture := if script_mode { os.real_path(os.args[5]) } else { '' }
144- boot_image(os.real_path(os.args[1]), os.abs_path(os.args[2]), new_dir, mode, fixture) or {
167+ fixture := if script_mode || disk_mode { os.real_path(os.args[5]) } else { '' }
168+ disk := if disk_mode { os.abs_path(os.args[6]) } else { '' }
169+ boot_image(os.real_path(os.args[1]), os.abs_path(os.args[2]), new_dir, mode, fixture, disk) or {
145170 eprintln(err)
146171 exit(1)
147172 }
@@ -0,0 +1,94 @@
1+"""Boot a package root on a disposable ext2 volume with a small matching initramfs."""
2+import argparse
3+import hashlib
4+import os
5+from pathlib import Path
6+import shutil
7+import subprocess
8+import tempfile
9+import uuid
10+
11+
12+def digest(path):
13+ with path.open("rb") as stream:
14+ return hashlib.file_digest(stream, "sha256").hexdigest()
15+
16+
17+def prepare(args):
18+ work = args.work
19+ if args.root == Path("/") or work.is_relative_to(args.root):
20+ raise ValueError("use a separate package root and a new worker output directory")
21+ work.mkdir()
22+ seed = work / "seed"
23+ (seed / "bin").mkdir(parents=True)
24+ shutil.copy2(args.root / "bin/busybox", seed / "bin/busybox")
25+ identity = f"vinix-ports-{uuid.uuid4()}\n"
26+ (seed / ".vinix-image-id").write_text(identity)
27+ disk = work / "root.ext2"
28+ with tempfile.TemporaryDirectory(dir=work) as tmp, (work / "format.log").open("x") as log:
29+ root = Path(tmp) / "root"
30+ subprocess.run(["cp", "-a", "--reflink=auto", args.root, root], check=True)
31+ for item in ("dev", "proc", "tmp", "run"):
32+ directory = root / item
33+ if directory.is_symlink():
34+ raise ValueError(f"invalid mount point: {directory}")
35+ directory.mkdir(exist_ok=True)
36+ (root / "tmp").chmod(0o1777)
37+ for dest in (".vinix-image-id", "userland-check.sh", "etc/inittab"):
38+ if os.path.lexists(root / dest):
39+ raise ValueError(f"fixture would overwrite /{dest}")
40+ (root / ".vinix-image-id").write_text(identity)
41+ # Only the ext2 copy prints the identity. A fallback into the seed
42+ # initramfs runs the original fixture and cannot satisfy this check.
43+ with (root / "userland-check.sh").open("xb") as script, args.fixture.open("rb") as fixture:
44+ script.write(b'#!/bin/sh\nIFS= read -r volume_id </.vinix-image-id || exit 1\n'
45+ b'echo "VPAC DISK ROOT $volume_id"\n')
46+ shutil.copyfileobj(fixture, script)
47+ (root / "etc").mkdir(exist_ok=True)
48+ console = "/dev/console" if args.arch == "aarch64" else "/dev/com1"
49+ (root / "etc/inittab").write_text(f"::sysinit:/bin/sh -c 'exec /bin/sh /userland-check.sh >{console} 2>&1'\n")
50+ # Account for data, directory blocks, inode tables and free working space.
51+ usage = int(subprocess.check_output(["du", "-sB1", root], text=True).split()[0])
52+ entries = sum(len(dirs) + len(files) for _, dirs, files in os.walk(root)) + 1
53+ mib = 1024**2
54+ size = (usage * 5 // 4 + 64 * mib + mib - 1) // mib * mib
55+ with disk.open("xb") as output:
56+ output.truncate(size)
57+ mkfs = shutil.which("mke2fs") or "/usr/sbin/mke2fs"
58+ # fakeroot covers both the ownership changes and mke2fs's input reads.
59+ subprocess.run(["fakeroot", "--", "sh", "-ec", 'chown -Rh 0:0 "$1"; shift; exec "$@"', "disk-root",
60+ root, mkfs, "-q", "-F", "-t", "ext2", "-b", "4096", "-I", "128", "-N",
61+ str(max(4096, entries * 2)), "-O",
62+ "filetype,sparse_super,^has_journal,^resize_inode,^dir_index,^extent,^64bit,^metadata_csum",
63+ "-d", root, disk], check=True, stdout=log, stderr=subprocess.STDOUT)
64+ fsck = shutil.which("e2fsck") or "/usr/sbin/e2fsck"
65+ subprocess.run([fsck, "-fn", disk], check=True, stdout=log, stderr=subprocess.STDOUT)
66+ debug = shutil.which("debugfs") or "/usr/sbin/debugfs"
67+ actual = subprocess.check_output([debug, "-R", "cat /.vinix-image-id", disk], text=True, stderr=log)
68+ if actual != identity:
69+ raise ValueError("ext2 disk identity differs from the boot seed")
70+ stat = subprocess.check_output([debug, "-R", "stat /bin/busybox", disk], text=True, stderr=log)
71+ fields = next(line.split() for line in stat.splitlines() if line.startswith("User:"))
72+ if int(fields[1]) or int(fields[3]):
73+ raise ValueError("packaged BusyBox on ext2 must be owned by root")
74+ return seed, disk
75+
76+
77+def run(args):
78+ work = args.work
79+ seed, disk = prepare(args)
80+ mode = "--aarch64-disk-fixture" if args.arch == "aarch64" else "--disk-fixture"
81+ with (work / "boot.log").open("x") as log:
82+ subprocess.run([args.boot, seed, args.iso, work / "guest", mode, args.fixture, disk],
83+ check=True, stdout=log, stderr=subprocess.STDOUT)
84+ with (work / "receipts.sha256").open("x") as receipt:
85+ for item in (work / "format.log", work / "boot.log", work / "guest/serial.log", disk, args.fixture):
86+ receipt.write(f"{digest(item)} {item}\n")
87+
88+
89+if __name__ == "__main__":
90+ parser = argparse.ArgumentParser(description=__doc__)
91+ parser.add_argument("arch", choices=("x86_64", "aarch64"))
92+ for arg in ("root", "fixture", "iso", "boot", "work"):
93+ parser.add_argument(arg, type=lambda path: Path(path).resolve())
94+ run(parser.parse_args())