98 lines
5.7 KiB
Plaintext
98 lines
5.7 KiB
Plaintext
Encrypted root installed by sysinst: what was read, and the design
|
|
==================================================================
|
|
Read 2026-11-06 in the tree at /home/lotherk/src/makronix, src/ pinned at
|
|
e523df740. Continues cgdroot-tree.txt.
|
|
|
|
What was read, and the sentence that settles each point
|
|
--------------------------------------------------------
|
|
boot.cfg(5) (src/share/man/man5/boot.cfg.5, "load"):
|
|
"Used to load kernel modules, which will be passed on to the kernel for
|
|
initialization during early boot. The argument is either the complete path
|
|
and file name of the module to be loaded, or a symbolic module name."
|
|
and the example "menu=Boot with module foo:load /foo.kmod;boot".
|
|
=> the boot partition carries /cgdroot.kmod and boot.cfg says
|
|
"load /cgdroot.kmod;boot /netbsd". The wiki's `fs /ramdisk-cgdroot.fs`
|
|
(cgdroot-guide.txt) is the older mechanism; this tree builds the module
|
|
(cgdroot-tree.txt) and has it on the CD.
|
|
|
|
distrib/common/cgdroot.rc lines 39-45 (unmodified in the tree):
|
|
for dev in NAME=cgd.conf /dev/wd0a /dev/ld0a ; do
|
|
if mount -o ro $dev /etc/cgd 2>/dev/null ; then
|
|
=> mount without -t: the partition labelled "cgd.conf" must be a file system
|
|
the kernel can mount by its wedge type, so GPT type ffs; cgd.conf and the
|
|
parameter file are at its root. Lines 57-63: root is NAME=cgdroot or
|
|
/dev/cgd0a, so cgd0 carries a disklabel with `a` as root.
|
|
|
|
gpt(8) (src/sbin/gpt/gpt.8, "add"):
|
|
"-l label ... -s size ... -t type": `gpt add -t ffs -l cgd.conf -s 256m disk`
|
|
and `gpt add -t cgd -l cgdroot disk` (the second takes the rest).
|
|
|
|
sysinst partman (partman.c pm_cgd_init, 1366-1392): its defaults are
|
|
pkcs5_pbkdf2/sha1, verify disklabel, aes-xts, encblkno1, 256 bit. The
|
|
installer uses the same ones: `cgdconfig -g -V disklabel -i encblkno1
|
|
-k pkcs5_pbkdf2/sha1 -o <file> aes-xts 256`, then `cgdconfig -V re-enter
|
|
cgd0 <dev> <file>` (partman.c:1466-1490).
|
|
|
|
Upstream sysinst writes no cgd.conf into the target and has no boot partition
|
|
for a cgd root: grep cgd over the sysinst sources finds only the partman menus,
|
|
gpt.c:114 (the GPT type), configmenu.c ("Enable cgd") and util.c (have_cgd).
|
|
(The `setup_cgd_boot` of cgdroot-tree.txt's source note was our own patch
|
|
0005, now in patches/unused/; it is not NetBSD.)
|
|
|
|
Design (src/usr.sbin/sysinst: cgdroot.c, hooks in install.c, disks.c,
|
|
arch/i386/md.c, arch/amd64/Makefile -DCGDROOT)
|
|
----------------------------------------------------------------------------
|
|
Simple mode only, BIOS only (UEFI would need cgdroot.rc to mount the FAT ESP).
|
|
1. "Encrypt the disk?" after the mode menu (cgdroot_ask).
|
|
2. disk chosen; cgdroot_prepare(): swap check, the last chance for the real
|
|
disk, destroy the scheme, `gpt create -f`, the two `gpt add`, read the
|
|
GPT back to get the dk names, the two cgdconfig calls (passphrase twice),
|
|
then find_disks() again with the disk forced to cgd0 (cgdroot_force_disk);
|
|
"cgd" is added to is_bootable_device()'s list so that cgd0 is handled like
|
|
raid: no MBR, no BIOS geometry, a plain disklabel.
|
|
3. the ordinary simple flow on cgd0: default layout, disklabel, newfs, fstab
|
|
(root /dev/cgd0a), md_post_newfs_bios returns early, sets unpacked.
|
|
4. cgdroot_finish(): newfs -O 2 and mount the boot partition at
|
|
/targetroot/cgdboot; copy netbsd and /usr/mdec/boot from the new root and
|
|
cgdroot.kmod from the CD (/mnt2/amd64/installation/miniroot/); write
|
|
cgd.conf ("cgd0 NAME=cgdroot /etc/cgd/cgdroot") and the parameter file;
|
|
md_cgdroot_boot(): boot.cfg, `installboot -f -o console=...` with
|
|
bootxx_ffsv2 on the boot partition, `gpt biosboot -b <start> disk`;
|
|
fstab gets "NAME=cgd.conf /cgdboot ffs rw,noauto".
|
|
|
|
Result (same day): `tools/install-cgd.sh` passed; the CD has the /dev nodes
|
|
(dk0-63, cgd0), so the MAKEDEVTARGETS worry below did not apply, and the loader
|
|
found boot.cfg on the GPT ffs partition. Two fixes were needed: cgd0 must get a
|
|
disklabel (partitions_read_disk makes a GPT), and the CD is the installer root,
|
|
so the kmod path comes from ext_dir_bin, not /mnt2.
|
|
|
|
Not read, not tested (as of this note)
|
|
--------------------------------------
|
|
- whether the miniroot of the CD has the /dev nodes (dk*, cgd0) cgdconfig
|
|
needs: the unused patch 0005 claimed it had not (MAKEDEVTARGETS); the test
|
|
decides.
|
|
- whether the loader finds /boot.cfg on a GPT ffs partition at the first
|
|
boot partition without a MBR active flag (the protective MBR from
|
|
`gpt biosboot`).
|
|
- a wrong passphrase at boot, and a kernel update (copy to /cgdboot).
|
|
|
|
UEFI (same day, tools/install-cgd.sh -f uefi passed)
|
|
----------------------------------------------------
|
|
Read: src/sys/arch/i386/stand/lib/biosdisk.c biosdisk_findpartition() (1040-
|
|
1125): the default boot partition is, in this order, the one with the GPT
|
|
"bootme" attribute, the one starting at the boot sector, else "bootable_fs_part",
|
|
the first partition of type FFS/LFS/RAID/CCD/CGD/ISO9660. A FAT ESP is none of
|
|
these, so the EFI loader's default device is the first FFS partition, here
|
|
cgd.conf (log: "boot: NAME=cgd.conf:/netbsd: No such file" when the kernel was
|
|
on the ESP). efiboot/boot.c:67: boot.cfg is read from esp:/EFI/NetBSD/boot.cfg,
|
|
else /boot.cfg of the default device.
|
|
Layout: ESP 128m (EFI/boot/bootx64.efi installed with `installboot -e -o
|
|
console=...`, EFI/NetBSD/boot.cfg), cgd.conf 256m FFS (netbsd, cgdroot.kmod,
|
|
boot.cfg, cgd.conf, cgdroot), cgdroot. cgdroot.rc is unchanged.
|
|
Test infrastructure: the OVMF IDE driver reads a CD so slowly that the loader
|
|
needed more than 9 minutes for the kernel; vmsh.sh puts the disk and the CD on
|
|
AHCI for -f uefi (CD to the installer: 261 s). tools/vm-screendump.sh saves the
|
|
screen of a VM.
|
|
Not tested: a UEFI machine with real NVRAM boot entries (the test boots the
|
|
removable path EFI/boot/bootx64.efi); wrong passphrase; kernel update.
|