Skip to content

os/v3/puppy: every reboot leaves its kernel log tail in EFI pstore, and the next boot files it (engine#3287) - #3306

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-release/pstore-shutdown-record
Nov 22, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-release/pstore-shutdown-record

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Part of #3287 (the c35 installer's reboot froze the box and left no log).

What the box showed (read-only, AI MAX+ 395, c35 installed, 22 Nov):

  • The stick boot the installer ran from (/dev/sda2 logs/20261122T113620-70c2a31d) wrote its shutdown marker at 11:37:29Z. Its messages/dmesg tail (sshd TERM, bluetoothd exit, deregistering interface driver snd-usb-audio) is the same as three reboots that came back (stick 10:31Z, stick 14:23Z, NVMe 14:18Z). Everything on /data comes from userspace, so the freeze happened after our last save and nothing there can say where.
  • efi_pstore is loaded (pstore: Registered efi_pstore as persistent store backend at 4.19 s) and the store is empty. Without printk.always_kmsg_dump it records only oopses and panics. In the 7.4 source, efi_pstore leaves max_reason undefined, so with the parameter on, kernel_restart() calls kmsg_dump(KMSG_DUMP_SHUTDOWN) right after reboot: Restarting system.

Change

  • mkimage.sh: adds printk.always_kmsg_dump=1 to every grub entry. The build is refused without it, like the other boot-line guards. The installer copies the stick's grub.cfg, so installed disks get it too.
  • 1bit-logs pstore [dir]: copies each /sys/fs/pstore record into <boot>/pstore/ and deletes it only after cmp passes. Deleting a record frees its EFI variable, so NVRAM does not fill up. It writes one line to markers:
    • ends in the kernel's own reset line: the kernel finished the reboot, so any hang after that is in the firmware.
    • a CRASH: …: an oops or panic.
    • no record: the previous shutdown never reached the kernel's reset, or the power was cut.
      The daemon runs it once per boot, after the mount wait.
  • tests/pstore_harvest_test.sh: 9 checks on fake records (ONEBIT_PSTORE), no root needed. Registered as ctest pstore_harvest.

Measured

  • sh tests/pstore_harvest_test.sh: 9/9 ok on ryzen.
  • The new 1bit-logs pstore /data/dev/cl-release/boot on the box mounted pstore and wrote pstore: no record from the previous shutdown. That is correct, because the parameter was off for that boot.
  • Not run on hardware yet: a reboot with the parameter on, to show this board writes the shutdown record. That needs a reboot of the appliance and waits on the orchestrator's go.

scripts/pre-pr-checks.sh --base origin/main: 16 green, 3 skipped (no gpu-kernels tree / submodules), and cmake_configure_check could not tell (configure did not finish within 300 s on ryzen).

🤖 Generated with Claude Code

…nd the next boot files it (engine#3287)

The c35 installer's reboot froze the AI MAX+ 395 and left nothing to read: the stick boot it ran from logged its
`shutdown` snap at 11:37:29Z with a tail identical to three good reboots, and efi_pstore (loaded, registered at
4.2 s) held no record, because without printk.always_kmsg_dump it records only oopses and panics.

- mkimage.sh: printk.always_kmsg_dump=1 on every entry (REFUSED without it). kernel_restart() then dumps the log
  tail after "reboot: Restarting system", into NVRAM, which survives the power-cycle a freeze needs.
- 1bit-logs pstore [dir]: copies /sys/fs/pstore records into <boot>/pstore/, deletes each only after cmp, and writes
  a markers verdict: the kernel's own reset line (firmware hang after it), a crash, or no record (never reached the
  reset). The daemon runs it once per boot.
- tests/pstore_harvest_test.sh (9 rows, no root).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3287 - Partially compliant

Compliant requirements:

  • Every reboot now leaves its kernel log tail in EFI pstore
  • The c35 installer's reboot issue is addressed with printk.always_kmsg_dump=1
  • The fix ensures kernel logs are preserved across reboots for debugging
  • printk.always_kmsg_dump=1 is added to grub entries and enforced
  • A mechanism to copy pstore records into boot directories is implemented
  • Records are deleted only after successful copy to prevent NVRAM overflow
  • Markers are provided indicating the nature of the shutdown

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential race condition in pstore handling

The pstore function in 1bit-logs copies files from /sys/fs/pstore to the boot directory and then deletes them. If a new record is created in /sys/fs/pstore between the copy and delete operations, it could lead to data loss or inconsistency. This is a potential race condition that could be problematic in a high-frequency logging environment.

cp -p "$f" "$d/pstore/$b" 2> /dev/null && cmp -s "$f" "$d/pstore/$b" || continue
rm -f "$f" 2> /dev/null
Incomplete error handling for pstore directory creation

The pstore function in 1bit-logs creates the pstore directory with mkdir -p "$d/pstore" 2> /dev/null || return 1. While it returns on failure, the error message in case of mount failure is written to the markers file, but there's no explicit logging of the failure itself. This could make debugging harder if the directory creation fails for reasons other than permissions.

mkdir -p "$d/pstore" 2> /dev/null || return 1
b=${f##*/}

@bong-water-water-bong
bong-water-water-bong merged commit 8fa1148 into main Nov 22, 2026
11 of 12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-release/pstore-shutdown-record branch November 22, 2026 15:48
bong-water-water-bong pushed a commit that referenced this pull request Nov 24, 2026
…rs - it now takes the new release's own line

The other slot's GRUB `linux` line was built from the RUNNING slot's line with only psubdir= replaced
(os/v3/puppy/embed/usr/local/bin/1bit-update:774-777 before this change). So every kernel parameter a release added,
dropped or changed after the machine was installed was lost by update. Measured on the issue's installed v2026.48
(updated from c35): /proc/cmdline carried no printk.always_kmsg_dump=1, although mkimage.sh puts it on every image's
line and refuses an image without it (os/v3/puppy/mkimage.sh:146,214) - that boot therefore left no pstore record for
#3306. An install carries the parameters of the release it was installed from for the machine's whole life.

The release now carries its own headless parameters beside the set it ships, and the update builds the other slot's
entries from THAT line, putting back only the keys that name this machine:

- os/v3/puppy/mkimage.sh:152: ONE variable builds the image's `linux` lines and the release's own line; :244 writes it
  to /1bit/cmdline on the set the data partition ships (not in SHA256SUMS - it is a line of text an update reads, not a
  bootable file it installs), so the image's grub.cfg and the file cannot disagree. A release directory made from that
  /1bit carries it too.
- 1bit-update:490 boot_param / :496 release_headless / :506 slot_params read it - bare parameters or a whole
  `linux <kernel> <params>` line, CRLF and #/blank lines included - and merge: the release's parameters as they are,
  with this machine's `pupsfs=UUID=`, `1bit.data=UUID=` and `psubdir=<target>` taken from the running entry, and
  `pfix=copy` -> `pfix=nocopy` for an installed disk, exactly the set 1bit-install.sh rewrites
  (os/v3/puppy/1bit-install.sh:206-211). A release that names a UUID pin the running line cannot fill in is refused by
  name: the image's own UUID would point the new slot at the release stick's partition.
- 1bit-update:836-912 writes the slot's headless AND serial entries from that line. An entry that already exists is
  rewritten in place and keeps its own kernel path; a missing one is appended, so a slot written by 1bit-install stops
  booting the installed release's parameters after an update and no entry accumulates. The image's desktop and
  install-to-disk entries are its own boot modes and are not touched. The written line is read back and compared with
  what this run wrote before `set default` moves (:912); a mismatch restores grub.cfg.
- A release cut before this (no /1bit/cmdline) is updated exactly as before, and the update warns that a parameter this
  release changed does not arrive.

Evidence (ryzen, configured Release tree; no device, no VM, no reboot):

1. CONTROL - origin/main's 1bit-update (sha256 9b38558c2da05e41...) with THIS branch's test file (new test, old code):

   $ git show origin/main:os/v3/puppy/embed/usr/local/bin/1bit-update > ~/.cache/scratch-3374/oldroot-3374/.../1bit-update
   $ sudo env ONEBIT_E2E_TMP=~/.cache/scratch-3374/e2e sh tests/update_e2e_loop_test.sh <that script>
   ...
   FAIL the /1bit-alt boot line carries the NEW release's added parameter (printk.always_kmsg_dump=1; the installed line had none)
   FAIL the /1bit-alt serial root shell entry carries it too
   FAIL the update says where the /1bit-alt line came from
   FAIL GRUB's default is /1bit and its line carries the parameter release B CHANGED (log_buf_len=64M, not 32M)
   FAIL with this machine's UUID pin (not release B's) and release B's added parameter
   FAIL the /1bit serial entry got the changed value too
   FAIL the /1bit line is not the one 1bit-install wrote any more
   FAIL the update says it rewrote the existing entries
   control_rc=1, 26 ok / 8 FAIL
   the line the old script wrote: linux /1bit-alt/vmlinuz pmedia=atahd pupsfs=UUID=x 1bit.data=UUID=x psubdir=1bit-alt
     nvme.quirks=1e49:1081:dmapool_align_512 log_buf_len=32M     (no printk.always_kmsg_dump=1; release A's cmdline had it)

2. BRANCH - same test, same command, the tree's script:

   $ sudo env ONEBIT_E2E_TMP=~/.cache/scratch-3374/e2e sh tests/update_e2e_loop_test.sh
   /1bit-alt headless entry: linux /1bit-alt/vmlinuz pmedia=usbhd pupsfs=UUID=x 1bit.data=UUID=x psubdir=1bit-alt
     log_buf_len=32M printk.always_kmsg_dump=1 pfix=nocopy,nox console=ttyS0,115200 console=tty0
   /1bit headless entry: linux /1bit/vmlinuz pmedia=usbhd pupsfs=UUID=x 1bit.data=UUID=x psubdir=1bit
     log_buf_len=64M printk.always_kmsg_dump=1 pfix=nocopy,nox console=ttyS0,115200 console=tty0   (release B CHANGED 32M->64M)
   ok    the /1bit desktop entry keeps the installed line (1bit-update writes a slot's headless and serial entries only)
   ok    the existing entries were rewritten in place: still 6 menu entries, none duplicated
   fix_rc=0, 34 ok / 0 FAIL
   The fixture ESP is the image's real FOUR-entry menu (headless, desktop, install-to-disk, serial), so the serial line
   rewritten is entry 3 - not the entry next to the headless one - and the two modes 1bit-update does not own are
   asserted byte-identical to what 1bit-install left.

3. UNIT ROWS (tests/one_bit_update_slots_test.sh, sourced functions, no root):
   branch: 33 ok, exit 0.
   control (same rows, origin/main's script in a stub root): 23 ok / 10 FAIL, exit 1 - slot_params/release_headless do
   not exist there.

4. ctest, the two rows this change touches: 55 one_bit_update_slots Passed; 89 update_e2e_loop Passed (as root, with
   ONEBIT_E2E_TMP pointing inside ~/.cache so no scratch lands in /tmp or /var/tmp).

5. scripts/pre-pr-checks.sh --tree-only --base origin/main:
   pre-pr-checks: all 16 check(s) green, 2 skipped, 0 could not be told, 2 open-PR row(s) not run (--tree-only)
   (the 2 skips are hip_f16_audit and kernel_id_selftest: no gpu-kernels tree on this box.)

Refs #3374. The host-side criterion is met; one real update followed by a boot on an installed machine
(/proc/cmdline has the parameter, and the next boot files the pstore record) still needs hardware and a reboot, and was
not run here.
bong-water-water-bong added a commit that referenced this pull request Nov 24, 2026
…rs - it now takes the new release's own line (#3465)

The other slot's GRUB `linux` line was built from the RUNNING slot's line with only psubdir= replaced
(os/v3/puppy/embed/usr/local/bin/1bit-update:774-777 before this change). So every kernel parameter a release added,
dropped or changed after the machine was installed was lost by update. Measured on the issue's installed v2026.48
(updated from c35): /proc/cmdline carried no printk.always_kmsg_dump=1, although mkimage.sh puts it on every image's
line and refuses an image without it (os/v3/puppy/mkimage.sh:146,214) - that boot therefore left no pstore record for
#3306. An install carries the parameters of the release it was installed from for the machine's whole life.

The release now carries its own headless parameters beside the set it ships, and the update builds the other slot's
entries from THAT line, putting back only the keys that name this machine:

- os/v3/puppy/mkimage.sh:152: ONE variable builds the image's `linux` lines and the release's own line; :244 writes it
  to /1bit/cmdline on the set the data partition ships (not in SHA256SUMS - it is a line of text an update reads, not a
  bootable file it installs), so the image's grub.cfg and the file cannot disagree. A release directory made from that
  /1bit carries it too.
- 1bit-update:490 boot_param / :496 release_headless / :506 slot_params read it - bare parameters or a whole
  `linux <kernel> <params>` line, CRLF and #/blank lines included - and merge: the release's parameters as they are,
  with this machine's `pupsfs=UUID=`, `1bit.data=UUID=` and `psubdir=<target>` taken from the running entry, and
  `pfix=copy` -> `pfix=nocopy` for an installed disk, exactly the set 1bit-install.sh rewrites
  (os/v3/puppy/1bit-install.sh:206-211). A release that names a UUID pin the running line cannot fill in is refused by
  name: the image's own UUID would point the new slot at the release stick's partition.
- 1bit-update:836-912 writes the slot's headless AND serial entries from that line. An entry that already exists is
  rewritten in place and keeps its own kernel path; a missing one is appended, so a slot written by 1bit-install stops
  booting the installed release's parameters after an update and no entry accumulates. The image's desktop and
  install-to-disk entries are its own boot modes and are not touched. The written line is read back and compared with
  what this run wrote before `set default` moves (:912); a mismatch restores grub.cfg.
- A release cut before this (no /1bit/cmdline) is updated exactly as before, and the update warns that a parameter this
  release changed does not arrive.

Evidence (ryzen, configured Release tree; no device, no VM, no reboot):

1. CONTROL - origin/main's 1bit-update (sha256 9b38558c2da05e41...) with THIS branch's test file (new test, old code):

   $ git show origin/main:os/v3/puppy/embed/usr/local/bin/1bit-update > ~/.cache/scratch-3374/oldroot-3374/.../1bit-update
   $ sudo env ONEBIT_E2E_TMP=~/.cache/scratch-3374/e2e sh tests/update_e2e_loop_test.sh <that script>
   ...
   FAIL the /1bit-alt boot line carries the NEW release's added parameter (printk.always_kmsg_dump=1; the installed line had none)
   FAIL the /1bit-alt serial root shell entry carries it too
   FAIL the update says where the /1bit-alt line came from
   FAIL GRUB's default is /1bit and its line carries the parameter release B CHANGED (log_buf_len=64M, not 32M)
   FAIL with this machine's UUID pin (not release B's) and release B's added parameter
   FAIL the /1bit serial entry got the changed value too
   FAIL the /1bit line is not the one 1bit-install wrote any more
   FAIL the update says it rewrote the existing entries
   control_rc=1, 26 ok / 8 FAIL
   the line the old script wrote: linux /1bit-alt/vmlinuz pmedia=atahd pupsfs=UUID=x 1bit.data=UUID=x psubdir=1bit-alt
     nvme.quirks=1e49:1081:dmapool_align_512 log_buf_len=32M     (no printk.always_kmsg_dump=1; release A's cmdline had it)

2. BRANCH - same test, same command, the tree's script:

   $ sudo env ONEBIT_E2E_TMP=~/.cache/scratch-3374/e2e sh tests/update_e2e_loop_test.sh
   /1bit-alt headless entry: linux /1bit-alt/vmlinuz pmedia=usbhd pupsfs=UUID=x 1bit.data=UUID=x psubdir=1bit-alt
     log_buf_len=32M printk.always_kmsg_dump=1 pfix=nocopy,nox console=ttyS0,115200 console=tty0
   /1bit headless entry: linux /1bit/vmlinuz pmedia=usbhd pupsfs=UUID=x 1bit.data=UUID=x psubdir=1bit
     log_buf_len=64M printk.always_kmsg_dump=1 pfix=nocopy,nox console=ttyS0,115200 console=tty0   (release B CHANGED 32M->64M)
   ok    the /1bit desktop entry keeps the installed line (1bit-update writes a slot's headless and serial entries only)
   ok    the existing entries were rewritten in place: still 6 menu entries, none duplicated
   fix_rc=0, 34 ok / 0 FAIL
   The fixture ESP is the image's real FOUR-entry menu (headless, desktop, install-to-disk, serial), so the serial line
   rewritten is entry 3 - not the entry next to the headless one - and the two modes 1bit-update does not own are
   asserted byte-identical to what 1bit-install left.

3. UNIT ROWS (tests/one_bit_update_slots_test.sh, sourced functions, no root):
   branch: 33 ok, exit 0.
   control (same rows, origin/main's script in a stub root): 23 ok / 10 FAIL, exit 1 - slot_params/release_headless do
   not exist there.

4. ctest, the two rows this change touches: 55 one_bit_update_slots Passed; 89 update_e2e_loop Passed (as root, with
   ONEBIT_E2E_TMP pointing inside ~/.cache so no scratch lands in /tmp or /var/tmp).

5. scripts/pre-pr-checks.sh --tree-only --base origin/main:
   pre-pr-checks: all 16 check(s) green, 2 skipped, 0 could not be told, 2 open-PR row(s) not run (--tree-only)
   (the 2 skips are hip_f16_audit and kernel_id_selftest: no gpu-kernels tree on this box.)

Refs #3374. The host-side criterion is met; one real update followed by a boot on an installed machine
(/proc/cmdline has the parameter, and the next boot files the pstore record) still needs hardware and a reboot, and was
not run here.

Co-authored-by: bong-water-water-bong <[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