Skip to content

initrd: boot a read-only root on a scattered LwVM partition (16 GB iPad mini 1) - #438

Closed
17xande wants to merge 2 commits into
OrchardLinux:mainfrom
17xande:p105-dm-root
Closed

17xande wants to merge 2 commits into
OrchardLinux:mainfrom
17xande:p105-dm-root

Conversation

@17xande

@17xande 17xande commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Problem

The shared initrd finds its root by root=PARTUUID=, which needs a partition the kernel registers. The kernel's LwVM reader registers only contiguous partitions. The 16 GB iPad mini 1's Linux partition, which iOS laid out, is scattered over three runs of flash chunks, so the system cannot boot it from orchard's initrd. Until now it booted through a hand-typed dm-mod.create table and a private init.

Changes

  • src/orchard/lwvm_root.py (python -m orchard.lwvm_root): from a 4096-byte LwVM header (primary, copy, disk image or block device) and the Linux partition's GUID, derives the boot options: root=PARTUUID=… ro orchard.root=dm orchard.overlay=tmpfs orchard.lwvm_crc=… dm-mod.create="…". It checks the header CRC, descriptor count, unencrypted Linux type, chunk coverage and the armv7 1023-byte command-line limit, and merges contiguous chunks into runs.
  • boot/initramfs/root/init: with orchard.root=dm it waits up to 30 s for the read-only mapper device whose dm UUID is orchard-lwvm-<PARTUUID>, re-reads the backing disk's LwVM header (primary first, backup only if the primary is invalid), checks its CRC and medium size against orchard.lwvm_crc=, mounts read-only and starts the system on a tmpfs overlay (required with orchard.root=dm). On failure it stops and offers a serial-only USB (ACM) rescue shell besides the console, only for this path. Other boots behave as before.
  • docs/boot-contract.md, docs/device-protocol.md: the contract, the options and the rescue behaviour; tests/fixtures/p105-scattered-lwvm.bin is a header of that layout.

The kernel options it needs (CONFIG_MD, CONFIG_BLK_DEV_DM, CONFIG_DM_INIT, all =y) are already in kernel/configs/apple-armv7/config.

Testing

  • bin/orchard python -m unittest discover -s tests: 510 tests, OK (1 skipped), including tests/test_lwvm_root.py and the init script's behaviour under test doubles.

  • Offline, against the captured header of the 16 GB iPad's Linux partition (GUID 1746a46a-ffc1-4a28-844f-0b168b79185f): the generated table is 0 19529728 linear /dev/applesftl0 8978432, 19529728 163840 … 30048256, 19693568 532840 … 30474240, identical to the hand-typed table that booted Omarchy A from that flash on 2026-11-30.

  • On the device, 16 GB iPad mini 1 (P105, iOS 9.3.5), 2026-12-02, kDFU then orchard run --autogo with the reader fix of mtd: apple-sftl: accept iOS 9's flag-1 records on 16 GB media (fixes the -74 refusal) linux#87 and the options from python -m orchard.lwvm_root:

    • First attempt: the kernel created dm-0 orchard-root read-only (dm UUID orchard-lwvm-1746a46a-…) at 9.7 s, then /init stopped before mounting. Cause: the LwVM header check made its temporary file under /newroot/, which mount_root only creates later. The host test had created /newroot itself, so it never failed. The stop took the serial rescue path (USB 05ac:4144), which worked. The temporary file is now made under /dev, and the test sandbox no longer has /newroot: the new test fails on the old code with the device's message.
    • Second attempt: the CRC check passed, the root mounted read-only (dm-0, ro=1) with the tmpfs overlay (overlay rw,…lowerdir=/root-lower,upperdir=/root-overlay/upper), switch_root ran and Omarchy A came up (session ready, system running, no failed units).

Not covered

  • Booted once successfully on one 16 GB iPad mini 1 and once into the rescue shell (the bug above). No other board has booted this path; the 30 s mapper timeout and the CRC-mismatch stop were not triggered on a device.
  • The 16 GB reader refuses the disk on many boots after iOS writes (-74); the fix is mtd: apple-sftl: accept iOS 9's flag-1 records on 16 GB media (fixes the -74 refusal) linux#87, not merged. A boot that hits it ends in the rescue shell, which is the behaviour to check.
  • The installer does not generate these options or populate scattered partitions; this boots an already prepared filesystem. The options must be regenerated whenever the LwVM map changes (the CRC check stops the boot if they are stale).
  • No CHANGELOG edit; propose after review.

Written with LLM assistance (Assisted-by: LLM).

Use a CRC-checked LwVM header to generate a read-only dm-linear map in the
boot arguments. The shared initrd matches the mapping by the root PARTUUID,
verifies the LwVM header checksum of the backing disk before mounting (a
valid primary takes precedence over a stale backup), and starts the system
with an opt-in tmpfs overlay, so writes do not reach the flash. If the
device-mapper root cannot boot, it offers a serial-only USB rescue shell.

Assisted-by: LLM
Signed-off-by: Alexandre Figueiredo <17xande@gmail.com>
CONFIG_MD, CONFIG_BLK_DEV_DM and CONFIG_DM_INIT are built into the armv7
kernel, merged in OrchardLinux/linux and taken into orchard's lock. Document
the generic boot contract and rescue path. The shared initrd's device-mapper
path has not yet booted on a device (one RAM boot is pending), so no
hardware evidence is claimed.

Assisted-by: LLM
Signed-off-by: Alexandre Figueiredo <17xande@gmail.com>
@henrikklee

Copy link
Copy Markdown
Contributor

Thank you, @17xande! linux#89 now does this in the kernel for every 32-bit board: a Linux partition that iOS scattered over the flash shows up as a normal partition with its own PARTUUID, so it boots like any other root, writable too, without an initrd step. orchard main builds that kernel. If your 16 GB iPad mini 1 still doesn't boot its root through m1n1 with it, please reopen this (or comment) with the log, and we pick it up from there.

@henrikklee henrikklee closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants