Skip to content

os image: explicit live mode + 1bit-selftest (prove the engine from a given boot) - #515

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
1bit/os-live-mode
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
1bit/os-live-mode

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

1bit OS already ran entirely from RAM and never mounted an internal disk — but nothing said so on screen, and proving the engine answered from a given boot meant hand-typing a wget. Both are now part of the image, which is what makes a live USB test something you (or an agent) can actually do before the final install.

Live mode, stated

init.sh now prints, before the hardware lines:

MODE: LIVE - everything runs from RAM; no internal disk is mounted and nothing is installed.
      Reboot to discard everything; only /data on the stick persists.

…and drops /etc/1bit/live so the mode is checkable. There is no installer in the image at all, so nothing can be installed over a working disk by accident.

1bit-selftest

New os/mini/selftest.sh, installed as /bin/1bit-selftest: mode, kernel, GPU/NPU devices, NPU firmware, the USB4/Thunderbolt module, model list from Lemonade, then one question to the local lemond with the answer and decode rate, appended to /data/selftest.log so the evidence outlives the live boot. Non-zero exit on failure, so it also works in a script and inside CI's 1bit.check path.

Verified

Booted the signed image in QEMU and read the graphical console:

1bit OS  -  LIVE MODE  (v2026.43)
runs from RAM - nothing installed
internal disks are never mounted

1bit OS self-test  2026-10-22T15:49:38Z
  mode      : LIVE - RAM only, nothing installed, internal disks never mounted
  kernel    : 7.3.0-rc4-1bit-perfopt
  GPU / NPU : /dev/kfd
  NPU fw    : present
  USB4/TB   : thunderbolt.ko.xz
  IP        : 10.0.2.15/24
  Lemonade  : answers; testing model 'Qwen3-0.6B-Q4_K_M'
  answer    : NPU OK
  timings   : decode 125.1 tok/s
RESULT: PASS - the engine answered from this live boot

(CPU/llamacpp — a VM has no NPU; on the box the same command goes through onebit:npu.)

Two bugs the self-test caught in itself, fixed here

  • a stray /d line left by an earlier sed whose pattern contained n/a, so the / ended the regex early;
  • a model-id parse that silently returned "" — it now tries id then model_name and fails loudly when no model is present.

Also bakes an optional SSH key (AUTHORIZED_KEYS=) so the box can be driven remotely during a live test; the key is not in the repo.

1bit OS already ran entirely from RAM and never mounted an internal disk, but nothing said so on
screen, and there was no way to prove the engine answers from a given boot without hand-typing a
wget. Both are now part of the image.

init.sh prints a LIVE banner (RAM only, nothing installed, internal disks never mounted), drops
/etc/1bit/live, and points at the new command. 1bit-selftest (os/mini/selftest.sh, installed as
/bin/1bit-selftest) reports mode, kernel, GPU/NPU devices, NPU firmware, the USB4/Thunderbolt
module, the model list from Lemonade, then asks the local lemond one question and prints the answer
and decode rate, appending everything to /data/selftest.log so the evidence outlives the live boot.
It exits non-zero on failure, so it works in a script or in CI's 1bit.check path.

Verified by booting the signed image in QEMU and reading the graphical console: the banner is on
screen and 1bit-selftest reports PASS - model Qwen3-0.6B-Q4_K_M, answer "NPU OK", decode ~125 tok/s
(CPU/llamacpp: a VM has no NPU). Two defects it caught in itself are fixed here: a stray "/d" line
left by an earlier sed whose pattern contained n/a, and a model-id parse that silently returned "";
the parse now tries id then model_name and fails loudly when no model is present.
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential Incomplete Model Selection Logic

The model selection logic in selftest.sh may not reliably choose a valid model for testing. It attempts to pick a model with a '-1bit' suffix, but if none is found, it falls back to picking any model. This could lead to selecting a model that is not actually compatible with the 1bit engine or is not properly configured, potentially causing the test to fail even if the engine is functioning correctly.

pick() { printf '%s' "$MODELS" | tr ',' '\n' | sed -n "s/.*\"$1\":\"\($2\)\".*/\1/p" | head -1; }
NAME=$(pick id '[^"]*-1bit')
[ -n "$NAME" ] || NAME=$(pick model_name '[^"]*-1bit')
[ -n "$NAME" ] || NAME=$(pick id '[^"]*')
[ -n "$NAME" ] || NAME=$(pick model_name '[^"]*')
[ -n "$NAME" ] || { say "  models    : Lemonade answers but lists none - put a GGUF or an NPU model dir in /data/models"; say "RESULT: FAIL - no model to test"; exit 1; }
Possible Race Condition in Test Execution

The selftest.sh script relies on lemond being fully initialized and serving requests before attempting to query it. If the service is not yet ready, the test will fail. While the script does check for a response, it does not implement a retry mechanism or wait for the service to be ready, which could lead to flaky test results in environments with slower startup times.

MODELS=$(wget -q -O - "http://127.0.0.1:$PORT/api/v1/models" 2>/dev/null)
if [ -z "$MODELS" ]; then
    say "  Lemonade  : no answer on 127.0.0.1:$PORT (see /tmp/lemond.log)"
    say "  hint      : run 'lemonade list' once lemond is up; models go in /data/models"
    exit 1
fi

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Superseded: every commit of this PR is in #517, merged as e7e5a9e with the real-hardware boot + NPU proof.

@bong-water-water-bong
bong-water-water-bong deleted the 1bit/os-live-mode branch October 23, 2026 11:03
bong-water-water-bong added a commit that referenced this pull request Oct 23, 2026
)

1bit OS boots live from a stick and there was no way to put it on a machine
(the #515 image says so plainly: no installer at all). This adds the installer
and proves the whole sequence in QEMU, so the owner's install is a known run of
commands rather than an experiment.

- os/mini/install.sh (new), shipped as /bin/1bit-install: installs onto ONE
  internal disk named explicitly. Before it writes anything it refuses: no
  --yes, a partition instead of a whole disk, a removable device, the disk this
  live boot runs from (the 1BIT-DATA partition's parent, via sysfs), a disk
  with anything mounted, a missing GPT tool. Then it prints the disk's
  model/size/partition table and waits 10 s. Past that: GPT with a 512 MB ESP
  (the live ESP copied byte for byte - the same shim, signed grub, vmlinuz,
  initramfs, grub.cfg, so the MOK enrolment on the machine is unchanged) and a
  1BIT-DATA ext4 partition filling the disk carrying the stick's models,
  Lemonade backends/config/cache, the NPU kernel sets and the SSH keys, plus
  /data/.installed.
- os/mini/init.sh: /data/.installed selects the installed mode - INSTALLED
  banner instead of LIVE, /etc/1bit/installed instead of /etc/1bit/live, and no
  stick menu (there is nothing to choose). Same initramfs and signed chain
  either way. Also define say() before its first use: it sat below the NPU
  kernel-link line, so that line died as "say: not found" on the console.
- os/mini/mkimage.sh: ship install.sh and sfdisk (busybox fdisk is MBR-only;
  the installer lays the target out with the same sfdisk script the build uses
  for the stick, so a stick and an installed disk are one layout), and ship and
  load nvme + ahci. Without them the live system had no NVMe driver at all and
  could not see the disk an install target always is.
- os/mini/vmtest.sh: an install pass - a sparse qcow2 virtual NVMe attached to
  the live VM, the refusal matrix, the install, poweroff, then a second boot
  from the installed disk alone with clean NVRAM and no USB attached, asserting
  the INSTALLED banner, /etc/1bit/installed, /data on the disk, Lemonade with
  its key answering a chat, and 1bit-selftest reporting INSTALLED.
- os/README.md: the owner's sequence as commands, the Secure Boot/MOK note, how
  to get back to the live stick, and what the VM proves vs what only the real
  machine can.

Three bugs the VM found, all invisible to a stick that never needs a second disk:
the image shipped no nvme/ahci module; new_part() decided a partition's name by
asking whether the node already existed (right after sfdisk it does not), so it
wrote /dev/nvme0n11 on a disk whose name ends in a digit; and "mke2fs" was not
mke2fs. The image shipped only busybox's applet, which is ext2-only and rejects
-t, so the data partition was never created ("1bit-install: mke2fs failed").
Shipping the real e2fsprogs binary was not enough on its own: this is a busybox
shell with CONFIG_FEATURE_SH_STANDALONE, so a name it knows as an applet is
answered by the shell before PATH is consulted, and the real /bin/mke2fs was
still skipped (measured in the guest: `type mke2fs` -> "mke2fs is mke2fs", while
/bin/mke2fs printed the e2fsprogs usage). The installer now names the tools it
needs by absolute path - /bin/sfdisk and /bin/mke2fs - and mkimage.sh ships the
real mke2fs with its libraries and /etc/mke2fs.conf. install.sh also reads the
partition table back with sfdisk, not busybox fdisk, which cannot read a GPT.

Two more the same runs found. Mounting the ESP failed with EINVAL and the kernel
said why: "FAT-fs (nvme0n1p1): codepage cp437 not found" - the image ships
nls_cp437 but init loaded vfat and not the codepage, so no vfat mount could
succeed. And the live disk was found with `findfs LABEL=1BIT-DATA`, which after
an install answers with the *installed* disk, whose own partition carries that
label: the installer then refused the target as "the disk this live boot runs
from" (blocking every reinstall) and would have copied the wrong ESP. Both the
live disk and the live ESP are now taken from what /data is actually mounted
from, in /proc/mounts.

Booting the installed disk and asking it (not guessing) found the last two: 1bit-selftest
printed "mode: LIVE" unconditionally, so on an installed machine it contradicted the
banner and the installer's own "selftest reports INSTALLED" check could never pass - it
now reads /etc/1bit/installed vs /etc/1bit/live. And /etc/1bit did not exist at all on
any boot, because mkimage.sh creates it after it packs the initramfs; init makes the
directory itself now, so the marker is not silently lost. That ordering in mkimage.sh
(/etc/1bit/libhsa and /opt/1bit-llama are also added after the pack) is pre-existing and
left alone here.

Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant