Skip to content

fix(fde): resolve default GRUB menuentry when grubenv has no saved_entry#126

Closed
Wilbert957 wants to merge 2 commits into
openanolis:masterfrom
0gfoundation:fix/show-reference-value-no-saved-entry
Closed

fix(fde): resolve default GRUB menuentry when grubenv has no saved_entry#126
Wilbert957 wants to merge 2 commits into
openanolis:masterfrom
0gfoundation:fix/show-reference-value-no-saved-entry

Conversation

@Wilbert957

Copy link
Copy Markdown

Problem

cryptpilot-fde show-reference-value fails on a freshly built image that has
never been booted:

saved_entry not found in GRUB environment

load_kernel_artifacts (src/cmd/fde/disk.rs) hard-requires saved_entry
from the GRUB environment block:

let saved_entry = grub_vars
    .get("saved_entry")
    .ok_or_else(|| anyhow::anyhow!("saved_entry not found in GRUB environment"))?;

But a never-booted image (a normal state for an image produced by
cryptpilot-convert) has an empty grubenvsaved_entry is only written at
runtime by savedefault. GRUB's selection order is
next_entry > saved_entry > set default, and these images boot the default
entry (set default="0", i.e. the first menuentry). So the reference-value
extractor cannot determine the boot entry and errors out.

Fix

When saved_entry is absent, fall back to GRUB's default entry by resolving the
first menuentry id from grub.cfg (matching set default="0"), instead of
failing. No image mutation is required.

  • New module-level helper default_menuentry_id(grub_cfg) extracts the id (the
    quoted token before the entry's opening brace), skipping non-entry lines such
    as menuentry_id_option=....
  • load_kernel_artifacts uses the existing saved_entry when present, otherwise
    this fallback.

Testing

cargo check passes. Verified against a GCP/Ubuntu 24.04 image converted with
cryptpilot-convert whose grubenv is empty and whose grub.cfg uses
set default="0".

🤖 Generated with Claude Code

`show-reference-value` (load_kernel_artifacts) aborted with
"saved_entry not found in GRUB environment" on freshly built / never-booted
images, whose GRUB environment block is empty.

GRUB's default selection order is next_entry > saved_entry > `set default`.
On such images GRUB boots the default entry (`set default="0"`, i.e. the first
menuentry), so fall back to resolving the first menuentry id from grub.cfg
instead of failing. This lets reference values be computed for images that
have not been booted yet, without mutating the image to fabricate a
saved_entry.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shankailun-aliyun

Copy link
Copy Markdown

@Wilbert957 ,您好,您的请求已接收,请耐心等待结果。

@shankailun-aliyun

Copy link
Copy Markdown

@Wilbert957 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start

Wilbert957 pushed a commit to 0gfoundation/0g-tapp that referenced this pull request Jun 24, 2026
…nce-value

Document how to compute remote-attestation reference values from the built
image with `cryptpilot-fde show-reference-value --disk`, including:
- the prerequisite cryptpilot-fde fix (openanolis/cryptpilot#126) so it works
  on never-booted images (empty grubenv) without the convert workaround
- how to build the fixed cryptpilot-fde from the 0gfoundation fork branch
- flags (--disk, --hash-algo, --stage) and the AAEL reference-value outputs

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
load_from_grub_cfg only matched `linuxefi`/`initrdefi` and split on spaces,
so it failed on Ubuntu grub.cfg, which uses `linux`/`initrd` directives that
are tab-separated (`linux\t/vmlinuz... root=...`). The kernel path ended up
empty and show-reference-value aborted with "Failed to read kernel file at
/boot/ (Is a directory)".

Match the directive by its first whitespace-delimited token (linux|linuxefi,
initrd|initrdefi) and split paths/cmdline on any whitespace, so both the
alinux UEFI (linuxefi) and Ubuntu (linux) layouts work.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Wilbert957

Copy link
Copy Markdown
Author

Superseded: re-done against current master (0.8.0) at the correct location cryptpilot-fde/src/disk/grub.rs. The earlier branch was based on a stale 0.2.7 checkout.

@Wilbert957 Wilbert957 closed this Jun 24, 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