2.2 Startup Sequence
Startup runs to completion before loregd accepts a single request. Database preparation, device negotiation, and registration failures are fatal: loregd logs the error and exits with status 1. Readiness notification is best effort; a failure is logged and serving continues.
2.2.1 1. parse and validate arguments #
loregd extracts the hive-to-database mapping and validates it as described
in §2.1. Before opening a hive, it ensures /run/loregd exists, verifies
tmpfs, and takes the runtime lock. Missing directories are created with
the descriptor below in the creation call; no later restamping is needed.
It removes old volatile stores only after taking that lock.
2.2.2 2. open each hive database #
For each declared hive, create missing database parent directories before
opening SQLite. This includes /var/state/loregd on a standard first boot.
loregd creates each missing ancestor, /run/loregd, and each fresh volatile
store directory with the same explicit descriptor in the native creation
call:
O:SYG:SYD:P(A;OICI;GA;;;SY)(A;OICI;GA;;;BA)
SYSTEM owns the directory. Its protected DACL grants full control only to SYSTEM and Administrators, inherited by files and directories. Native creation failure aborts startup; there is no POSIX-only fallback in the daemon.
Existing directories keep their ownership, descriptor, and mode. A path that exists but is not a directory, including a symbolic link, fails with an error naming the path. If another creator wins a race, loregd checks the resulting type and leaves an existing directory unchanged.
ppk packages contain only /usr. loregd needs its storage before it can
serve the registry, so it prepares these directories itself; registry-backed
path provisioning runs too late for this Phase 1 service.
Four pieces of connection state are established immediately:
PRAGMA journal_mode=wal. The result is read back and checked; if the database does not reportwal, the open fails. WAL mode is what allows concurrent readers alongside a writer (§4.1), so silently running without it is not acceptable.PRAGMA foreign_keys=ON. Neither schema declares a foreign key, so this constrains nothing.PRAGMA busy_timeout=0; SQL lock conflicts return busy immediately (§4.4).- The volatile database is attached (§3.3).
Each database/sql handle is limited to a single underlying connection.
2.2.3 3. attach the volatile store #
Each hive gets a fresh tmpfs-backed SQLite database, attached as volatile
and put in WAL mode with private caches. Before opening hives, loregd
ensures and locks /run/loregd, verifies tmpfs, and removes old volatile
stores left by a crash (§3.3). It never reuses a prior process's volatile
data.
2.2.4 4. establish the schema #
If the database has no schema_version table, it is new: loregd creates
the persistent tables, creates the volatile tables, and stamps the schema
version, in one transaction.
If the version is present, it is compared against the version loregd supports. A newer version aborts startup, and so does an older one (§3.1).
2.2.5 5. first-boot root key #
For each hive, look for a key with no parent. If none exists, this is the hive's first boot: loregd generates a random 16-byte GUID for the root key, builds the default hive-root security descriptor, and inserts the root key record.
The default root descriptor grants SYSTEM and Administrators full access to the key, grants Authenticated Users read access, marks all three as container-inheritable, and sets both owner and group to SYSTEM.
2.2.6 6. crash recovery #
SQLite's own WAL recovery handles any transaction that was uncommitted when the process died; it happens when the database is opened and needs nothing from loregd.
What loregd does on top of that is clean up orphaned keys; key records that no path entry in any layer points at. These can survive a crash between a key's creation and the creation of the path entry naming it. In one transaction, loregd deletes the values belonging to orphaned keys, then their blanket tombstones, then the key records themselves.
The hive root is exempt: it legitimately has no parent and no path entry
pointing at it, so orphan detection skips keys whose parent_guid is
null.
2.2.7 7. compute the maximum sequence number #
For each hive, take the maximum sequence across the path entries,
values, and blanket tombstones; in both the persistent and the volatile
tables; then take the maximum across all hives.
That single global figure is what loregd reports at registration, so the
kernel can resume allocating sequence numbers above everything already
stored.
In practice the volatile tables are empty at this point in startup and contribute nothing.
2.2.8 8. open the registry device #
Open /dev/pkm_registry. The kernel requires SeTcbPrivilege in the
calling thread's token to permit this; loregd performs no check of its
own and relies on the kernel to refuse.
Before registration, negotiate RSI lifetime extension version 1 with
REG_SRC_NEGOTIATE. Retain the returned source-session identifier for request
contexts and lease renewal. A kernel without this extension is incompatible;
startup fails before registering hives instead of silently changing lifetime
semantics.
2.2.9 9. register the hives #
Issue REG_SRC_REGISTER with every hive name, its root key GUID, and the
global maximum sequence number from step 7.
The registration flags are zero: loregd registers global hives only and never private ones.
2.2.10 10. signal readiness and serve #
loregd sends readiness to NOTIFY_SOCKET if it is set (§2.1). The complete
notification attempt has a one-second deadline. A failed attempt produces
a warning, not a startup failure. The daemon installs its termination
signal watcher (§2.3) and enters the request loop (§4.2).
2.2.11 Backup and repair limits #
loregd creates no automatic startup backup. Opening a hive prepares its schema, root, orphan cleanup, and reader pool. Orphan cleanup deletes unreferenced persistent records; it does not restore a backup or repair arbitrary database corruption.
WAL recovery and RSI_FLUSH checkpointing create no separate recovery copy.
Read-only RSI transactions provide snapshots for higher-level backup
operations, but do not save those snapshots themselves. The
kernel backup interface
is a separate operation.
The command-line interface provides no offline repair command. Database recovery requires a separately verified backup and a procedure appropriate to that backup format.