Files
makronix/docs/reference/cgdroot-tree.txt
T
lotherkandClaude Sonnet 5.5 b83aaa425b docs: GOAL, AGENTS.md in every directory, build VM, offline build, references
Measurements named with their logs: the installs (BIOS, UEFI, encrypted, two CDs), the NetBSD self-build in the build VM (2 h 02 min, stopping only at checkflist for the missing userland), 9p and NFS against the local disk.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 12:53:21 +00:00

71 lines
4.1 KiB
Plaintext

The encrypted-root machinery that the NetBSD tree already carries
=================================================================
Source: the tree at /home/lotherk/src/makronix, src/ pinned at e523df740
(NetBSD 11.99.9), read 2026-11-06. The CD facts are from `7z l` of the ISO that
`make iso` built that day. Not yet read line by line: sys/arch/i386/stand
(loader), boot.cfg(5), cgdconfig(8), gpt(8).
How the tree does an encrypted root (distrib/common/cgdroot.rc, 88 lines)
-------------------------------------------------------------------------
The boot loader loads a *miniroot* as a kernel module; the miniroot is a
ramdisk that runs cgdroot.rc as its init. The script:
1. mounts a read-only partition at /etc/cgd, trying in this order
NAME=cgd.conf /dev/wd0a /dev/ld0a (lines 36-45)
("Could not mount the boot partition" and exit 2 if none works);
2. `cgdconfig -C` configures every cgd in /etc/cgd/cgd.conf; this is where the
passphrase is asked (lines 48-54; "Could not decrypt the encrypted volume");
3. chooses the root to mount: NAME=cgdroot and /dev/cgd0a when step 1 found the
config by NAME=, otherwise only /dev/cgd0a (lines 57-63);
4. mounts it read-only at /altroot (lines 65-77);
5. `umount /etc/cgd` and `sysctl -w init.root=/altroot`: init continues from
the decrypted root (lines 85-88).
So an encrypted Makronix needs, on the disk: a boot partition the loader can
read (loader, kernel, boot.cfg, the miniroot module), a small partition named
`cgd.conf` holding /etc/cgd (cgd.conf and its parameter files), and a cgd
partition named `cgdroot` whose cgd0 carries a disklabel with `a` = root.
How the miniroot module is built and shipped
--------------------------------------------
distrib/amd64/kmod-cgdroot/Makefile: MINIROOT=cgdroot, RAMDISK=ramdisk-cgdroot
(6 lines), which includes distrib/common/Makefile.minirootkmod: it takes
stand/<machine>/<ver>/modules/miniroot/miniroot.kmod, adds the ramdisk as the
section `miniroot` with objcopy, gzips it, and in its `release` target installs
it into RELEASEDIR/<machine>/installation/miniroot/.
distrib/amd64/ramdisks/ramdisk-cgdroot/Makefile: IMAGE=ramdisk-cgdroot.fs,
IMAGESIZE=5000k, lists distrib/common/list.cgdroot and mtree.cgdroot.
No set list names cgdroot (grep over distrib/sets/lists): the module is not part
of any set, so sysinst does not unpack it.
It IS on the install CD built on 2026-11-06 (7z l):
amd64/installation/miniroot/cgdroot.kmod 1523615 bytes
amd64/installation/miniroot/miniroot.kmod 1713556 bytes
amd64/installation/ramdisk/ramdisk-cgdroot.fs 5120000 bytes
stand/amd64/11.99.9/modules/miniroot/miniroot.kmod 3256 bytes
=> sysinst, running from that CD, can copy cgdroot.kmod into the boot partition
of the target.
Loader side
-----------
sys/arch/i386/stand/lib/biosdisk.c understands NAME=<wedge name> as a boot
device (lines 94, 928, 1008, 1363, 1642); cgdroot.rc's NAME=cgd.conf and
NAME=cgdroot rely on wedge names, which GPT provides.
What sysinst has and lacks for this (see sysinst-survey.txt)
------------------------------------------------------------
Has: GPT partition type "cgd" (gpt.c:114), the cgd menus and cgdconfig -g /
-V re-enter in the installer (partman.c:1456-1497), "Enable cgd" in the config
menu. Lacks: a layout with a boot partition, a `cgd.conf` partition and a
`cgdroot` partition; writing cgd.conf and its parameter files into the config
partition; copying the kernel, loader and cgdroot.kmod into the boot partition;
a boot.cfg that loads the module; a disklabel on cgd0 with root in `a`.
Open, to read before writing code
---------------------------------
- the loader's `load` command and boot.cfg(5) syntax for a module;
- how the EFI loader (bootx64.efi) finds boot.cfg and the kernel on an ESP, and
whether the kernel and module may live on the FAT ESP;
- gpt(8): partition labels (-l) for `cgd.conf` and `cgdroot`;
- cgdconfig(8): the parameter file, keygen (pkcs5_pbkdf2/sha1), and how the
passphrase is entered when `cgdconfig -C` runs in the miniroot;
- what the BIOS boot path needs (bootxx on which partition).