composefs/grub: Type 1 entry order is arbitrary when os-release has no VERSION_ID/VERSION

未关闭 适合新手
#2,669 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust

调研方向

从 crates/lib/src/bootc_composefs/boot.rs 中 version_opt.unwrap_or_else(|| id.to_hex()) fallback(位于 setup_composefs_bls_boot 内)开始,然后阅读 type1_entry_conf_file_name 和 get_sorted_type1_boot_entries(b.filename.cmp(&a.filename)),看看版本字段如何进入文件名。为排序将摘要替换为常量,同时保留标题中的摘要,然后用两个 BLSConfig 传入 get_sorted_type1_boot_entries_helper(.., Bootloader::Grub) 来复现,并运行 composefs 启动测试。完成意味着无论摘要如何,-1 优先级条目都排在最前面。

由索引模型根据 Issue 内容生成。

描述

Summary

When composefs uses GRUB with Type 1 entries, bootc orders the entries by file name, descending (get_sorted_type1_boot_entries, Bootloader::Grub → b.filename.cmp(&a.filename), see #2221). The file name is bootc_{os_id}-{version}-{priority}.conf (type1_entry_conf_file_name). version comes from VERSION_ID, then VERSION, in /usr/lib/os-release.

Some os-release files have neither key, for example Debian sid/testing and Arch Linux. For those, setup_composefs_bls_boot falls back to the deployment's verity digest:

// crates/lib/src/bootc_composefs/boot.rs (main @ 2a59b59, also v1.16.10)
version_opt.unwrap_or_else(|| id.to_hex()),

As a result, the version field is a random hex string that changes with every deployment, and it sorts before the priority field. After an upgrade:

loader/entries/bootc_debian-3f…(new digest)…-1.conf   # primary (new)
loader/entries/bootc_debian-c0…(old digest)…-0.conf   # secondary (booted)

The descending file-name order puts the old deployment first here, because c > 3. So bootc (and GRUB's blscfg, which uses the same name-version-release order) treats the old deployment as the default, and the upgrade is never booted. With other digests the new one wins. bootc rollback swaps only the priority field, so it is just as arbitrary.

With systemd-boot this does not happen, because the sort-key (bootc-{os_id}-{0,1}) comes first.

Reproducer
  1. bootc install to-disk --composefs-backend --bootloader grub an image whose /usr/lib/os-release has no VERSION_ID and no VERSION. A Debian sid based bootc image works, and so does the stock Arch os-release.
  2. bootc upgrade to a new image, then reboot so that bootc-finalize-staged runs.
  3. ls /sysroot/boot/loader/entries: the two entries differ only in the digest and the priority. The -1 (new) entry is first only when its digest sorts higher.

The logic needs no VM. Feed two BLSConfigs named as above to get_sorted_type1_boot_entries_helper(.., Bootloader::Grub), and the order follows the digests.

Possible fix

When os-release has no version, use a constant (for example 0) in place of the digest. Then the priority (release) field decides between the deployments of one OS, as it does when VERSION_ID stays the same across builds. The title/version shown to the user can keep the digest.

Context

We hit this while booting TunaOS flounder:gnome-sid (Debian sid, bootc 1.16.10, composefs) through a GRUB chain (tuna-os/wootc#768).

主要语言
Rust
星标
2.3k
派生
230
平均合并
2 天 11 小时
30 天内合并 PR
42

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bootc-dev/bootc 的其他 Issue

查看 bootc-dev/bootc 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。