# The Registry

---

# The Registry

_Peios / Using Peios / The Registry_

> How Peios stores configuration as keys and typed values in hives, how layers decide which value wins, who stores the data, and how access to each key is controlled.

The registry is where Peios keeps configuration: service definitions, network
profiles, sign-in policy, desktop preferences, and the settings of almost
every component. It is a tree of keys holding typed values. The kernel decides
who can read or change each key. It also lets an installed role, a policy, and
an administrator each set the same value without overwriting one another.
Understanding that model explains why a value you set might not be the one in
effect.

## Hives, keys, and values

A path through the registry names a key, from the top of the tree down:

```text
Machine\System\Services
```

The first part of every path is a **hive**, a top-level tree. A standard
system has two:

- **`Machine`** holds settings for the whole machine.
- **`Users`** holds one subtree for each account, named by the account's
  security identifier (SID): `Users\<SID>`.

`CurrentUser` is a shortcut, not a third hive. At the start of a path, it
stands for `Users\<SID>` of the account the calling program runs as. Other
components can register further hives.

A **key** contains subkeys and values. A **value** is a named piece of data
with a type. A key can also have one value with an empty name, its default
value. The types you meet most are:

| Type | Holds |
|---|---|
| `REG_SZ` | A UTF-8 string |
| `REG_MULTI_SZ` | An ordered list of strings |
| `REG_DWORD` | A 32-bit unsigned integer |
| `REG_QWORD` | A 64-bit unsigned integer |
| `REG_BINARY` | Raw bytes |

Names are case-insensitive but keep the case they were created with, so
`Machine\System\Services` and `machine\system\services` are the same key. The
backslash is the separator. Tools also accept a forward slash, which is easier
to type in a shell.

## Layers

Each value can have several entries at once, one from each **layer** that has
set it. A layer is a named collection of registry writes that can be managed,
and removed, as a unit. When a program reads a value, the kernel returns the
single winning entry: the effective value.

Two numbers decide the winner:

- **Precedence.** Every layer has a precedence. The highest precedence wins.
- **Sequence.** Among layers with the same precedence, the most recent write
  wins.

The **base layer** is built in and is always present. It has precedence 0,
and a write that names no layer goes to it. Layers that a role installs also
sit at precedence 0, so the most recent write among them wins. Policy layers
sit above 0 and override both. Giving a layer a precedence above 0 requires
`SeTcbPrivilege`; being a local administrator doesn't grant it on its own.

Layers make configuration reversible. Deleting a layer removes its entries,
and the next entry down becomes effective again. A layer can also mask a
value, so that the value reads as absent while the layer is in effect.

When a read seems wrong, check which layer won. `reg` and Registry Editor
both report the winning layer for each value.

## Who stores the registry

The kernel holds none of the registry's data. Programs called **sources**
store it, and the kernel asks them for entries when it needs them. On a
standard system, the source is **loregd**, which keeps the `Machine` and
`Users` hives in database files under `/var/state/loregd`.

The kernel makes every decision: which layer wins, who can see a key, and who
can change it. A source only stores what it is given. Programs reading and
writing configuration always talk to the kernel, never to the source.

A key can be **volatile**, which tells its source not to keep it in permanent
storage. loregd holds volatile keys in memory-backed files, so they disappear
whenever loregd restarts, even if the machine doesn't.

If a source stops, its hives become unavailable and requests for them fail
until it returns. Sign-in and other services depend on the registry, so a
storage failure can affect much of the system.
[Diagnosing Registry Storage Failures](/peios/using-peios/registry/diagnosing-failures.md)
covers recovery.

## Who can read and change a key

Every key has a security descriptor, which records who owns it and who can
do what to it. The kernel checks the descriptor once, when a program opens
the key, and the program keeps the access it was granted for as long as the
key stays open. Values don't have security descriptors of their own: the
key's descriptor covers all of them.

The kernel checks only the key being opened, not the keys above it. A program
can open `Machine\System\Services\netd` without any access to
`Machine\System\Services`.

Changing a key's security descriptor doesn't affect programs that already
have it open. Security descriptors aren't layered either, so removing a layer
doesn't undo a change to one.

## Documentation and live state

Each component installs a manual for the registry settings it owns. `regman`
reads those manuals. It tells you what a value means, which values are valid,
and when a change takes effect, but it doesn't read the live registry. Use
`reg` or Registry Editor to see what is actually set.

Storing a value doesn't prove that its component accepted it. The component
that reads a setting checks it and decides when to apply it, so check that
component after a change.

## Where to start

These pages cover the tasks:

- [Finding a Registry Setting](/peios/using-peios/registry/finding-a-setting.md) to find the
  owner and live state of a setting before you change it.
- [Changing a Registry Setting](/peios/using-peios/registry/changing-a-setting.md) to make a
  change from the command line and confirm that it applied.
- [Registry Editor](/peios/using-peios/registry/registry-editor.md) to browse and edit the
  registry on the desktop.
- The SDK's [Registry Overview](/peios/developing-for-peios/sdk-registry/overview.md) to use the
  registry from your own code.

---

# Registry Reads, Writes, and Layers

_Peios / Using Peios / The Registry_

> Choose a live registry operation without confusing it with documentation or a backup.

`reg` reads and changes the live registry. `regman` explains the intended
meaning of a setting; it does not read the value configured on this machine.
Consult the documentation before changing a setting whose accepted values you
do not know.

## Keep the key and value name separate

The key path and the value name are separate arguments. A value name can
contain separators that are not allowed inside a key-path component. The
special value-name token `@` selects the empty-name default value.

Value literals have types. Numeric-looking input can be inferred as a number,
losing a textual spelling such as leading zeros. Use an explicit string type
when those characters are part of the value's meaning. Inspect the resolved
type reported after a successful write.

The empty-name default value is unrelated to a consumer's documented
fallback when an entry is absent. To preserve text such as `007`, use an
explicit literal such as `sz:007`. Quote backslash paths in a shell, or use
forward slashes. `reg(1)` owns the full type-prefix and encoding reference.

Names preserve display case and compare without locale-sensitive case rules.
They are not Unicode-normalized, so visually identical names can remain
distinct. Ordinary value data is opaque to the registry; its consumer checks
whether the bytes make sense for the type and setting. A link key's target
has additional interpretation by the kernel.

A volatile key describes storage lifetime, not when a setting applies. Check
`reg info` for volatility and the setting's manual for application timing.

## Choose a layer deliberately

An effective read resolves the visible value across layers. Deleting an entry
in one layer can reveal a lower entry. Masking hides lower values instead,
while hiding a key affects path visibility.

These are different operations, not interchangeable ways to remove data.
Select the layer and understand the lower state before changing either.
Security-descriptor changes affect the key object directly; removing a
configuration layer does not undo them.

The winner has the highest precedence, then the newest write sequence within
that precedence. A sequence is not a timestamp or a history of previous
values. Base and role layers can share precedence zero; writing to base does
not prevent a later role update from winning. `reg get KEY NAME -L` reports
only the effective winner, not every hidden entry.

See [Recovering a Registry Layer](/peios/using-peios/registry/recovering-a-layer.md)
before disabling or removing configuration, and [Removing Registry
Entries](/peios/using-peios/registry/removing-entries.md) before choosing between
withdrawal and masking.

## Separate exchange from exact backup

JSON export and apply provide a reviewable representation of keys and values.
A batch applies within one hive transaction. It is not a cross-hive
transaction. Export does not claim to preserve every security component.

Text export is useful for review, but the text import path is not implemented.
Use the supported JSON document when applying an export. Opaque backup and
restore use a different kernel mechanism and require the corresponding
privileges.

Use [Applying a Registry Batch](/peios/using-peios/registry/applying-a-batch.md) for
related edits and [Backing Up Registry
Configuration](/peios/using-peios/registry/backing-up-configuration.md) for recovery.

## Treat notifications as prompts to reread

A registry watch tells you that relevant state changed. Reread the state
needed by your application; do not treat the notification itself as the
complete new configuration.

For an operator watch, run this in a terminal and read the current values
from another:

```sh
reg watch Machine/System/KMES --subtree --filter value
reg get Machine/System/KMES BufferCapacity -L
```

The watch command remains running until interrupted; the second command is a
separate read. Watch permission does not grant permission to read descendant
values. The command reports changes without decoding every detailed record.

Watches describe effective-state changes, not every hidden layer write.
After overflow, an interruption, restore, or source reconnection, read the
required key or subtree again. A watch follows its opened key object; if a
replacement key takes the same path, reopen the path and arm a new watch.
Uncommitted transaction changes are not consumer notifications.

Operations use the caller's authority. Interactive confirmation protects
against mistakes but is not an access check, and redirected input can change
prompting behavior. `reg(1)` defines types, layers, batch syntax,
confirmation, and status codes.

## Inspect a link rather than its target

Normal opens follow registry links. To inspect a suspected link itself,
replace `KEY` with its path:

```sh
reg info KEY --no-follow
reg get KEY @ --no-follow -L
```

Check the link flag and the winning unnamed target value. A link flag is
fixed at creation; storing `REG_LINK` in an ordinary key does not create a
link. Conversely, a winning value of the wrong type can break resolution of
a flagged link. A target is literal: `CurrentUser` is not expanded inside it.

Targets are layered, so withdrawing a target entry can reveal a different
one. Check both the stored target and the resolved object after repair.
`reg(1)` defines which mutating commands support operating on a link itself;
do not assume every command accepts the inspection options above.

## Diagnose access to a key and a layer

A write needs the key's operation rights and access to its destination
layer. Use `reg sd` for the key's owner, group, and DACL; reading its SACL
needs `ACCESS_SYSTEM_SECURITY`. Values have no separate descriptors.

Inspect layer metadata permissions as well as the target key. Its `Owner`
value is informational, not an authorization grant. Creating or promoting a
layer above precedence zero needs `SeTcbPrivilege`. Merely being a local
administrator does not establish that privilege.

Do not create `Machine\System\Registry\Layers\base` as an exploratory
repair. Without that metadata key, a compiled descriptor allows
Authenticated Users to write into base, subject to target-key access.
Creating the key replaces that fallback with its real descriptor; inherited
read-only grants can unexpectedly prevent personal configuration writes.

A parent's readability does not establish a child's permissions, and LCS
does not apply filesystem-style traverse checks to each path component.
Inheritance applies when a key is created. Editing a parent's descriptor
does not rewrite existing descendants or revoke rights on existing handles.
Reopen the key when testing a changed descriptor. The kernel's
[access flow](/kernel/internals/lcs/security/the-access-flow.md) and
[layer authorization](/kernel/internals/lcs/layers/writing-into-a-layer.md)
references define the checks.

---

# Finding a Registry Setting

_Peios / Using Peios / The Registry_

> Identify the owner, scope, and live state of a setting before changing it.

Find a setting by its purpose and consuming component. A path can contain
operator configuration, a runtime observation, or personal preferences;
those are different kinds of data.

## Find and inspect

1. Search installed manuals with a term from the setting's purpose:

   ```sh
   regman -k buffer
   ```

2. Read the matching key and value documentation. Confirm its owner, scope,
   type, accepted values, and application timing.
3. Inspect live state with `reg` or Registry Editor. Keep the key path and
   value name separate. A documented default can apply even when no live
   entry exists; do not create one solely because it appears in the manual.
4. Follow [Changing a Registry
   Setting](/peios/using-peios/registry/changing-a-setting.md) when the intended
   change and recovery are understood.

## Common owners

| Purpose | Starting location | Owning guidance |
|---|---|---|
| Service definitions | `Machine\System\Services` | [Service configuration](/peios/using-peios/services-and-jobs/registry-key-reference.md) |
| Boot and init settings | `Machine\System\Init` | [Boot modes](/peios/using-peios/boot/boot-and-boot-modes.md) |
| Network profiles and reported state | `Machine\System\Network` | [Profiles](/peios/using-peios/network-configuration/configuring-profiles.md) and [name resolution](/peios/using-peios/network-configuration/name-resolution.md) |
| Shared authentication grants | `Machine\Generic\Authn\Policy` | [Granting Access](/peios/using-peios/authentication/granting-access.md) |
| authd source registration | `Machine\Software\Authd\Sources` | [Registering a Principal Source](/peios/using-peios/authentication/registering-a-source.md) |
| Personal preferences | `Users\<SID>` | The component consuming the particular key |

This is an orientation map, not a complete schema. A shared format under
`Machine\Common`, such as `SecurityDescriptorBuilder`, is still defined by
its consumers' documentation; it is not automatically part of a specification.
Use the installed manual for the specific value.

## Identity and reported state

`CurrentUser` is an alias resolved from the calling thread's effective token.
A service or impersonating thread can therefore address a different account
from an interactive shell. The kernel's [hive routing
reference](/kernel/internals/lcs/data-model/hives-and-routing.md) defines the
alias's limits. It is not a separate hive or a universal substitution inside
every stored string.

Machine-to-user fallback is consumer-specific. [Session
locales](/peios/using-peios/command-line-basics/session-locales.md) combine corresponding
machine and personal values; that rule does not apply to unrelated settings.

Services also publish facts. For example, netd's status and readiness describe
observed network state. Change its documented profiles to request behavior;
do not edit a reported address and assume that it configures an interface.
Remembered DNS observations are distinct from active resolver state and
configured resolver overrides.

## Missing or unreadable

A missing manual entry can mean documentation is absent. A missing live value
can select a documented fallback. Access denied means the caller lacks the
right for that operation; listing a parent does not establish access to a
child's contents.

Check the actual descriptor. There is no universal rule that every registry
key is readable by everyone, and knowing a path grants no access to it.

---

# Finding a Setting's Meaning

_Peios / Using Peios / The Registry_

> Use installed registry manuals before reading or changing live configuration.

`regman` reads the documentation shipped for registry settings. It explains
what a key or value means, what values are accepted, and which component owns
it.

## Documentation and state answer different questions

A documented default is not necessarily the value configured on this machine.
`regman` does not query the live registry. Use `reg` for the effective value
and its available provenance.

The component that consumes a setting decides whether it is meaningful.
Successfully storing a value does not establish that the consumer accepted it.
Read the setting's type, range, and application behavior first.

## Start with a name or a search term

An exact key and value lookup is useful when an error names the setting. A key
lookup groups its documented values, while a search finds names and summaries
when you know the subject but not its location.

Some components document a family of keys using wildcard paths. An exact
record is more specific than a matching family description. Read the resolved
path so that you know which documentation answered the query.

## Installed packages supply the corpus

Packages place their registry manuals under `/usr/share/regman`. A missing
entry can mean that documentation is absent; it does not establish that the
live key is absent. Overlapping definitions are reported rather than silently
treated as one authoritative record.

The lookup index is an accelerator. Invalid indexes fall back to reading the
manuals instead of serving unchecked index data. Authors can format, lint, and
rebuild the index as part of preparing a package.

`regman(1)` defines lookup, search, path selection, and authoring commands.

---

# Changing a Registry Setting

_Peios / Using Peios / The Registry_

> Verify a setting's documentation, stored value, and consuming component as separate steps.

A registry write changes stored configuration. Its consumer still decides
whether the data is valid and when to apply it. Verify both storage and
behavior before treating an edit as complete.

## Before you start

Find the owning component and confirm that the value is configuration rather
than a reported fact. You need access to the exact key and the destination
layer. Keep a working route to the machine if the change affects access.

Read the setting's registry manual. Record its type, valid range, default,
and application timing. `regman` reads installed documentation, not live
state. A missing manual entry is not permission to try arbitrary values.

## Inspect, change, and verify

1. Inspect the setting and its manual. For example, these commands read
   the kernel event-buffer setting without changing it:

   ```sh
   regman 'Machine\System\KMES' BufferCapacity
   reg ls Machine/System/KMES -l
   reg get Machine/System/KMES BufferCapacity -L
   ```

2. Record the current type, effective value, winning layer, and sequence.
   If the value is absent, record that instead. `-L` shows the winning
   entry; it does not enumerate every entry hidden beneath it.
3. Prepare recovery appropriate to the change. A JSON export is useful for
   review but does not preserve everything an opaque registry backup does.
   Include permissions and layer definitions when recovery depends on them.
4. Write the intended value with an explicit type and destination layer.
   For example, only after confirming that an 8 MiB event buffer is the
   intended configuration:

   ```sh
   reg set Machine/System/KMES BufferCapacity qword:8388608 --layer base
   reg get Machine/System/KMES BufferCapacity -L
   ```

5. Check the effective value and type. Follow the manual's application
   point: a live change, service restart, or reboot. Inspect the consumer's
   state and events, then test the behavior the change was intended to alter.

The desktop equivalent is [Changing Registry
Values](/peios/using-peios/registry/changing-registry-values.md). It still requires the
same choice of layer and separate consumer check.

## Interpret a different result

A higher-precedence layer can keep a successful write from becoming the
winner. At equal precedence, write order chooses the effective entry. Do not
repeat base-layer writes to try to override stronger policy.

A conditional write checks the destination layer's entry. A sequence reported
for a winner in another layer is not a version of the entry you intend to
change. Read `reg(1)` before using `--expected-seq` in automation.

A watch notification reports a registry change, not consumer acceptance.
Some consumers reject invalid configuration and keep their last valid state;
others have a documented compiled fallback. Read the component's rule and
rejection diagnostic. Do not assume every component repairs, clamps, or
resets a value in the same way.

## Recover and check again

After a timeout or source failure, read back inspectable state before
retrying.
A dispatched write or commit can have succeeded despite a lost reply.

Restore the intended entry in its intended layer, or withdraw that layer's
entry through the supported tool. Deletion can reveal a different winner
rather than select a compiled default. Removing a layer does not restore a
key's previous security descriptor or undo actions a service already took.

Repeat both the stored-state check and the consumer check after recovery.
If storage is unavailable, start with [registry storage
failure diagnosis](/peios/using-peios/registry/diagnosing-failures.md) instead of
editing backing databases.

## When two readers see different state

Compare effective thread credentials before comparing registry results.
A private hive can shadow the global hive, and a privately attached layer
can remain active when disabled globally. Impersonating threads in one
process need not share a view. An administrator's global read or backup
therefore need not describe a sandbox's private configuration.

The kernel defines [private hive routing](/kernel/internals/lcs/data-model/private-hives.md)
and [private layer attachment](/kernel/internals/lcs/layers/private-layers.md).
The workload's isolation mechanism controls these attachments; `reg` does
not manage them. Limits on scopes and layers can also reject an operation
without a key-permission failure.

---

# Registry Editor

_Peios / Using Peios / The Registry_

> Understand typed values, layers, permissions, and recovery operations.

Registry Editor displays keys, values, and their registry documentation.
A key is a container; a value is named data with a type. The editor reads
as your account and distinguishes unavailable access from an empty key.

The tree starts at **Machine**, **Users**, and **CurrentUser**. A direct
path can reach a readable child even when you cannot list its parent.
The detail pane shows a value's data, type, size, and winning layer, or
information about the selected key.

## Stored data and documented defaults

The registry manual supplies descriptions, expected types, defaults, and
application timing. Documented values absent from the key are shown as
**Not set**. These are explanatory entries, not stored data or exported
values. A type mismatch or malformed value is shown instead of being
silently repaired.

A saved registry value can still be rejected by its consuming component.
Follow its manual and inspect its status after a change.

## Layers

**Writes go to** selects the destination layer. A value's displayed winner
can come from another layer. Writing a lower layer does not displace an
entry with higher precedence. Deleting a value removes the selected
layer's entry, so another entry can become visible instead of the value
becoming absent.

Layer management changes whole sets of entries. Positive precedence needs
the operating-system privilege `SeTcbPrivilege`; being an administrator is
not sufficient by itself. Key owners and permissions are not layered:
disabling a layer does not undo a descriptor change.

## Export and backup

**Export** creates a reviewable registry document of keys and values.
**Back up** includes security descriptors and tagged layer entries.
They are not interchangeable recovery formats. A backup's layer manifest
does not recreate missing layer definitions on its own.

**Import** writes the selected document into the chosen layer in a
transaction. **Restore** replaces the target's contents and subtree,
including its descriptor, rather than merging into the current contents.
Backup and restore have their own privilege requirements.

For a controlled edit, follow
[Changing Registry Values](/peios/using-peios/registry/changing-registry-values.md). The command
reference is `gxwi-registry-editor(1)`; the registry's shared semantics
remain owned by its own documentation.

---

# Changing Values in Registry Editor

_Peios / Using Peios / The Registry_

> Choose the write layer and verify both storage and application.

A registry edit changes stored configuration. To establish that the change
worked, verify both the resulting entry and the component that reads it.

## Before you start

You need Registry Editor and access to the exact key and destination
layer. Record the existing value, type, layer, and relevant permissions.
Choose an export or backup suited to the recovery you need.

## Edit one value

1. Open **Registry Editor** and navigate to the key, or enter its path and
   select **Go**.
2. Select the value and read its registry manual, including valid values
   and when a change takes effect.
3. Check **Writes go to**. Confirm the selected destination even when a
   different layer supplies the displayed value.
4. Open **Edit**, enter the intended data, and select **Save**. For a
   documented but absent value, use **Set**.
5. If the editor reports a concurrent change, refresh and inspect the new
   state before submitting another edit.

## Check the result

Use **Refresh** or **F5**. Inspect the value, type, and winning layer.
Then inspect the consuming component at the time its manual requires.
A conditional write protects the destination layer's entry, not every
possible change to a winner in another layer.

## Deleting and recovering

Deleting a key removes its subtree in one transaction or fails. Large
subtrees can exceed transaction or open-handle limits. Agree the intended
smaller scope before splitting a failed deletion, because several
transactions are not one atomic operation.

Deleting a value can reveal a surviving entry from another layer. A saved
change or deletion does not by itself select the consumer's compiled
default.

Read an import or restore target before confirming it. After a timeout or
source failure, inspect current state before retrying: an error alone does
not prove that a transaction was rolled back. Changing permissions affects
future opens; existing handles retain rights already granted.

---

# Changing System Settings

_Peios / Using Peios / The Registry_

> Change a machine setting and check its application timing.

System Settings changes machine-wide time, locale, startup, and identity
settings. Personal account choices belong to My Settings, and shell
appearance belongs to Desktop Settings.

## Before you start

You need access to write the relevant registry key or configuration file.
Some immediate operations also require a daemon control right. Record the
existing setting before a change that needs a restart or affects access.

## Change a setting

1. Open **System Settings** and choose the relevant section: **Time &
   Date**, **Language & Keyboard**, **Startup & Shutdown**, or **About**.
2. Inspect the current value and its scope. A switch or list choice
   applies when selected; typed values use the associated **Apply**,
   **Save**, or **Set Clock** action.
3. Make one intended change and read the status line. A refused immediate
   choice is put back.

## Check the result

The window rereads state every five seconds. Verify the consuming service
or the next session as appropriate, not only the stored field.

Time settings are read by timed; setting the clock manually needs its
control right and automatic time disabled. Console keyboard changes try to
restart the keymap service when permitted; otherwise they take effect at
boot. Machine locale defaults affect new sessions. The machine name is
applied by netd.

Startup settings include peinit stage timing, console automatic sign-in,
and selected kernel-command-line options when dynamic boot is available.
Changing the next boot image's inputs does not change the running kernel.
See `gxwi-system-settings(1)` and each setting's registry manual.

The language and format selections save `LANG` with the time, number, money,
measurement, and paper categories. Use `reg` when changing one independently
configured category. For personal precedence and new-session checks, follow
[Choosing Session Locales](/peios/using-peios/command-line-basics/session-locales.md).

---

# Removing Registry Entries

_Peios / Using Peios / The Registry_

> Choose withdrawal, masking, or hiding and verify which value or key becomes visible.

Decide whether the intended result is to withdraw one layer's contribution
or make a name absent despite contributions beneath it. These are different
operations.

## Choose the operation

| Intended result | Operation |
|---|---|
| Withdraw a layer's value entry | `reg delvalue` |
| Keep a value absent over lower entries | `reg mask` |
| Withdraw a layer's key-existence claim | `reg delkey` |
| Hide a key over lower claims | `reg hidekey` |
| Remove the corresponding absence marker | `reg unmask` or `reg unhidekey` |

`reg mask --all` creates a blanket value mask. It does not delete every
stored value. Use `reg(1)` for exact arguments and layer selection.

1. Inspect the target and winning layer, then save the recovery data needed
   for that scope.
2. Select the destination layer explicitly. Do not assume withdrawing its
   entry makes the name absent: another layer can become visible.
3. Run the operation appropriate to the intended result.
4. Reopen the path, inspect the effective state, and verify the consumer.
   Removing an absence marker can reveal data that has changed since masking.

Key deletion requires key deletion rights; value changes need value-write
rights. Both also require applicable layer access. Hive roots cannot be
hidden or deleted through these operations.

## Recursive removal and existing handles

`reg del -r` uses one transaction and does not follow registry links during
its recursive walk. Resource and transaction limits still apply; a large
walk can fail. Terminal confirmation is not shown with redirected input.

A lost commit reply leaves the outcome uncertain. Read state before retrying
rather than assuming nothing changed. Existing handles can continue to
refer to an orphaned key after its path disappears. A replacement at that
path is a different object; reopening is necessary to inspect or watch it.

---

# Applying a Registry Batch

_Peios / Using Peios / The Registry_

> Apply related registry changes atomically within one hive and handle uncertain commit outcomes.

Use a reviewed JSON registry document when several entries must become
visible together. A transaction provides registry atomicity, not simultaneous
application by every service that consumes the settings.

## Review, apply, and verify

1. Review every operation and its destination layer. All operations must
   target one hive, even when several hives share one source. Descriptor
   changes are security changes and require their own review and rights.
2. Save recovery data appropriate to the changes. A JSON export contains
   visible keys and effective values, not every descriptor or layer entry.
3. Apply the document:

   ```sh
   reg apply reviewed.json
   ```

4. Inspect the affected entries and verify consuming services. If a commit
   times out or loses its source reply, inspect state before resubmitting:
   storage can have committed despite the reported failure.

Text export is for review; text batch input is not implemented. `reg(1)`
defines the supported document schema.

## Boundaries of the transaction

`reg apply --dir DIR` applies each file as a separate transaction. A directory
import is not one atomic unit. Transactions have bounded time and size, no
nesting or savepoints, and require source support. Splitting a failed batch
can break the consistency requirement that motivated it.

Readers outside a transaction do not see its intermediate writes. Bound
reads see that transaction's pending changes. This does not provide
value-level conflict detection: if a write depends on an unchanged entry,
use `--expected-seq` with the destination layer's own sequence. `reg get -L`
only exposes that sequence when the destination is the effective winner.

A layer makes entries removable later; a transaction publishes related
changes together. Neither is an undo history, and removing a layer does not
reverse descriptor changes. A late successful commit can still notify
watchers after the caller's timeout. Closing an uncommitted transaction
aborts it, but cannot undo an already-dispatched successful commit.

---

# Backing Up Registry Configuration

_Peios / Using Peios / The Registry_

> Choose a reviewable export or a privileged subtree backup and verify replacement recovery.

Choose the format according to the recovery requirement. JSON exchange and
opaque registry backups preserve different information.

| Need | Mechanism | Limit |
|---|---|---|
| Review visible configuration | `reg export --json KEY FILE`, then `reg apply FILE` | Does not preserve key descriptors or the complete layered store. |
| Restore a subtree with its descriptors and tagged entries | `reg backup KEY FILE`, then `reg restore KEY FILE` | Privileged replacement, not merge. |
| Withdraw a managed bundle | Its role or policy workflow | Layer removal cannot undo permissions or consumer side effects. |

Registry Editor exposes the corresponding **Export…**, **Import…**,
**Back up…**, and **Restore…** actions. Text export cannot be reapplied as a
text batch.

## Capture a recovery copy

1. Identify the subtree and the permissions, layers, and consumers that
   recovery must preserve. Choose protected storage: backup privilege can
   expose data unavailable through ordinary reads.
2. Capture the subtree, for example:

   ```sh
   reg backup Machine/System/KMES kmes.snap
   ```

3. Confirm success and retain the file with its original path and purpose.
   Interrupted output is not a verified recovery copy.
4. Check whether required layer definitions are also backed up. A stream's
   layer manifest records metadata for validation but does not recreate
   definitions. Their keys under `Machine\System\Registry\Layers` must be
   included or recovered separately.

Backup uses a consistent snapshot while other writes continue. It includes
key descriptors, layer-tagged entries, and absence markers. Integrity checks
detect corruption; they do not make an untrusted backup safe to restore.

## Restore and verify

1. Confirm the trusted backup matches the intended target. Save current
   state if recovery from the restore itself is required.
2. Review replacement scope, restored permissions, needed layer definitions,
   and consumer application timing. The backup root's immutable volatile
   and link flags must match the target.
3. With replacement approved, restore the earlier example:

   ```sh
   reg restore Machine/System/KMES kmes.snap
   ```

4. Reopen paths and inspect representative values, descriptors, and
   `reg layer ls -l`. Then verify consumers and their events. Existing
   handles retain their granted rights, so use fresh opens to test access.

Restore keeps the target key object, replaces its mutable fields and
contents, and replaces descendants. It uses one transaction. Rejection before
commit leaves no partial restored subtree; a timeout after dispatch can
leave an uncertain outcome. Inspect before retrying. Terminal input prompts
for confirmation; redirected input proceeds without that prompt.

Entries whose layer definitions are missing remain inactive until metadata
exists. Restored entries also receive fresh ordering; recovery is not a way
to restore the global write counter.

## Required authority

Backup and restore use `SeBackupPrivilege` and `SeRestorePrivilege`, bypass
ordinary per-key checks, and are audited independently of key audit policy.
Restore can rewrite owners and permissions, including the target key's own
descriptor. Positive-precedence layers in the manifest or existing metadata
also require `SeTcbPrivilege`; restoring their metadata has its own gate.

Read the kernel's [backup and restore
reference](/kernel/internals/lcs/backup-and-restore/overview.md) before building
a recovery tool. A global-hive backup does not include an unrelated private
hive shadowing the same path for another credential scope.

---

# Recovering a Registry Layer

_Peios / Using Peios / The Registry_

> Inspect the effective winner and withdraw a configuration layer without mistaking it for a full rollback.

A layer keeps a bundle's entries identifiable and removable. It is not a
snapshot of everything the bundle changed. Prefer the owning role or policy
tool when it also manages files, service actions, or other state.

## Inspect and recover

1. Record the effective value, its winning layer, and its sequence with
   `reg get KEY NAME -L`. Inspect the layer inventory with `reg layer ls -l`.
2. Identify the layer's owner and recovery procedure. Save required data and
   layer metadata before changing it. A narrow subtree backup need not
   include the definitions that make its layer entries active.
3. If the owner's workflow permits it, disable the named layer first:

   ```sh
   reg layer set NAME --disable
   ```

4. Reread representative values, check the newly winning layer, and verify
   each affected consumer at its documented application point. Re-enable
   with `--enable` if the trial does not produce the intended result.
5. Delete a layer only after its owner confirms it is unneeded and the
replacement
   state is verified. `reg layer del NAME` is destructive. Its terminal
   confirmation is absent with redirected input.

Replace `KEY`, `NAME`, and the value name with the reviewed targets. The
built-in base layer cannot be disabled or deleted.

## Limits of layer recovery

Disabling a layer removes it from ordinary global resolution. Credentials
that explicitly attach the layer can still see it. Inspect the workload's
effective thread credentials before concluding that it sees the same state
as an administrator's shell.

Removing a layer does not restore key security descriptors, reverse actions
already taken by services, or reconstruct earlier values overwritten within
that layer. Consumers do not necessarily apply the new winner immediately.

An ordinary write into a new layer is different from retaining previous
versions. Equal-precedence layers use write sequence as their tiebreaker,
not a fixed order of role names. See [Registry Reads, Writes, and
Layers](/peios/using-peios/registry/reg.md) for effective reads and authorization.

---

# Operating loregd

_Peios / Using Peios / The Registry_

> Startup requirements, readiness, persistence, and shutdown of the local registry source.

loregd supplies the local registry hives that Peios needs during boot.
peinit selects the hive names and database paths and supervises the daemon.
You normally use the registry through its kernel interfaces rather than
starting loregd yourself.

## Startup requirements

The daemon needs these resources before it can serve the registry:

- A SYSTEM token and `SeTcbPrivilege` for native protection and RSI access.
- A Peios kernel with RSI lifetime extension version 1.
- Writable persistent database paths supplied as hive declarations.
- A tmpfs-backed `/run` where it can create and lock `/run/loregd`.

peinit supplies `Machine=/var/state/loregd/Machine.hive` and
`Users=/var/state/loregd/Users.hive`. loregd itself has no path defaults and
reads no configuration file or registry configuration. The
[command-line reference](/peios/reference/loregd/startup/command-line.md) describes the
accepted declarations.

The runtime lock excludes a second daemon using `/run/loregd`. Do not use
that directory or a live hive for a development test. A daemon restart
removes volatile registry data even if the operating system has not rebooted.

## Readiness and logs

If `NOTIFY_SOCKET` is set, loregd sends `READY=1` after registration. The
complete notification attempt has a one-second deadline. Failure is logged
and serving continues, so a missing readiness message does not by itself
prove that registration failed.

Progress goes to standard output and failures to standard error. peinit
captures these streams during early boot. The daemon does not require
eventd to report an early startup error.

## Persistent and volatile data

Persistent data lives in each named SQLite hive. A hive can have adjacent
WAL and shared-memory files while open. Volatile data lives in fresh,
per-hive databases under `/run/loregd` and is discarded on every restart.

Do not treat the main SQLite file alone as a live backup: committed data
can remain in its WAL. loregd supports read-only RSI snapshots for
higher-level backups, but creates no automatic startup backup. See
[backup and repair limits](/peios/reference/loregd/startup/startup-sequence.md#backup-and-repair-limits).

## Stopping the daemon

`SIGTERM` and `SIGINT` close the source device. loregd drains requests,
releases transaction state, closes hive connections, and removes volatile
stores. The kernel marks the served hives unavailable when their source
disconnects. This can affect sign-in and other services that use the registry.

---

# Diagnosing Registry Storage Failures

_Peios / Using Peios / The Registry_

> Interpreting loregd startup failures, busy responses, storage errors, and recovery limits.

Diagnose a failure from the daemon's captured error output and the failing
operation. Process liveness alone does not establish registry health: loregd
can remain registered while SQLite returns storage errors.

## Startup failures

The failure stage identifies the relevant checks:

| Stage | Check |
|---|---|
| Argument parsing | Every hive declaration contains a nonempty name and absolute path; folded names are unique. |
| Runtime directory | `/run/loregd` is tmpfs-backed and available to the SYSTEM daemon; another instance does not hold its lock. |
| Database preparation | Parent paths are writable, SQLite can use WAL, and the database has supported schema version 1. |
| Device access | The Peios registry device exists and the caller has `SeTcbPrivilege`. |
| Negotiation | The kernel supports RSI lifetime extension version 1. |
| Registration | The hive names and their global registration are accepted by the kernel. |

Argument and startup failures exit with status 1. Readiness notification
failure is a warning and does not terminate serving.

## Busy and storage responses

`RSI_TXN_BUSY` can indicate a competing write transaction, SQLite lock
contention, a blocked checkpoint, or an expired request wait. A read-only
snapshot does not own the write connection, but it can keep WAL pages that
a truncate checkpoint needs to release.

`RSI_STORAGE_ERROR` includes database failures and invalid transaction state.
An interrupted bound transaction requires abort; using its ID again does not
silently start a replacement transaction. A request timeout does not prove
that an already-admitted commit failed. See
[waiting and contention](/peios/reference/loregd/concurrency/waiting-and-contention.md).

## Recovery limits

Startup performs SQLite WAL recovery and removes orphaned persistent keys.
It does not restore a backup, rebuild case-folded columns, or repair an
arbitrary corrupt database. The schema check is not a full integrity check:
it does not validate every existing table definition or detect multiple
version rows.

Preserve the affected files and diagnostics before attempting repair. Use
a verified recovery procedure for the actual backup format. The daemon
has no `--inspector`, `--recover-from-backup`, or
`--dangerously-clear-database` switch.

## Separate a source outage from a denied operation

Record the exact operation, key, and error. `reg` status 3 means access
denied; status 5 includes source and syscall failures. Do not replace a
source database merely because a setting is missing or unreadable.

The `registryd` role names the selected source provider, not another daemon
beside loregd. Its startup paths come from Peinit's boot policy. Inspect the
installed arguments instead of treating a path from an example as a default.
Do not start a second provider against the live databases to investigate.

On source disconnection, handles remain but operations needing source data
fail. Re-registration produces watch overflow recovery: clients must reread
the state they need. A timed-out mutation or commit can already have reached
storage, so inspect live state before repeating it after recovery.

LCS owns access checks, routing, layers, and watches. That does not make a
source untrusted: access checks use descriptors returned by the source, and
structural validation cannot detect every well-formed false descriptor or
entry. Protect the source process, launch configuration, and backing files
as part of the trusted computing base.
