lib/install: Use mounted ESP for install to-filesystem#1953
lib/install: Use mounted ESP for install to-filesystem#1953Guara92 wants to merge 5 commits intobootc-dev:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the handling of the EFI System Partition (ESP) across the codebase. Key changes include introducing a new open_target_root function to abstract opening the target root directory and a require_boot_efi_mount function to validate and retrieve the mounted ESP's source. The require_boot_efi_mount function replaces previous logic for finding and mounting the ESP, ensuring /boot/efi is a valid, mounted vfat/fat filesystem. Consequently, functions like setup_composefs_bls_boot, setup_composefs_uki_boot, install_via_bootupd, install_systemd_boot, and clean_boot_directories are updated to utilize these new helper functions and pass Dir objects for root access. A review comment specifically points out that several parameters (_device, _rootfs, _configopts, _deployment_path) in the install_systemd_boot function are now unused and should be removed for clarity, along with updating their call sites.
crates/lib/src/bootloader.rs
Outdated
| _device: &PartitionTable, | ||
| _rootfs: &Utf8Path, | ||
| _configopts: &crate::install::InstallConfigOpts, | ||
| _deployment_path: Option<&str>, |
There was a problem hiding this comment.
22641b1 to
4ed589c
Compare
cgwalters
left a comment
There was a problem hiding this comment.
Thank you so much for your contribution!
Previously, bootc install to-filesystem determined the ESP by scanning the partition table of the disk hosting the target root. This logic failed to respect an explicit /boot/efi mount if it was different from the first ESP on the disk.
Can you explain in what circumstances this happens?
| ) | ||
| } | ||
|
|
||
| fn open_target_root(root_setup: &RootSetup) -> Result<Dir> { |
There was a problem hiding this comment.
Slightly cleaner as a method on impl RootSetup I'd say
crates/lib/src/install/baseline.rs
Outdated
| boot, | ||
| kargs, | ||
| skip_finalize: false, | ||
| require_esp_mount: true, |
There was a problem hiding this comment.
Hmm...I would say arguably to-disk should not mount the ESP and we should ensure that it's autodiscovered properly.
There was a problem hiding this comment.
Very reasonable, thanks for the feedback, implemented 8d870fc
crates/lib/src/bootloader.rs
Outdated
| let base_partitions = bootc_blockdev::partitions_of(Utf8Path::new(&device))?; | ||
| let esp = base_partitions.find_partition_of_esp()?; | ||
| Ok(esp.map(|v| v.node.clone())) | ||
| fn normalize_esp_source(source: String) -> String { |
There was a problem hiding this comment.
"normalize" here could use a definition.
Also if we're trying to micro-optimize this it can return a Cow<str>
There was a problem hiding this comment.
Cow used and added some rustdoc on the function f3def47, is it clear enough now?
crates/lib/src/bootloader.rs
Outdated
| return Ok(()); | ||
| }; | ||
| if !esp_fd.is_mountpoint(".")?.unwrap_or(false) { | ||
| anyhow::bail!("/boot/efi is not a mountpoint. This is required for installation."); |
There was a problem hiding this comment.
I don't want to make /boot/efi strictly hard required - among other things the DPS suggests mounting at /efi which makes sense to me and we should handle.
There was a problem hiding this comment.
Thanks for pointing me to the spec, those low-level stuff are kinda new to me, I implemented a lookup by priority based on DPS f3def47.
Am I still missing something?
Previously, `bootc install to-filesystem` determined the ESP by scanning the partition table of the disk hosting the target root. This logic failed to respect an explicit `/boot/efi` mount if it was different from the first ESP on the disk. This change updates the installation logic (both for systemd-boot and bootupd paths) to strictly require that `/boot/efi` is mounted under the target root. It inspects this mountpoint to determine the correct backing device, ensuring the installation targets the intended ESP. Assisted-by: Zed Agent (GPT-5.2-Codex) Signed-off-by: Daniele Guarascio <guarascio.daniele@gmail.com>
The strict ESP mount enforcement previously introduced caused regressions in scenarios, specifically in CI environments running inside containers (tmt/podman). In these contexts, bind mounts often mask `/boot/efi`, causing `is_mountpoint` checks to fail even when the configuration is valid. This patch introduces a `require_esp_mount` field to `RootSetup`. When targeting an existing root (host), we now utilize a permissive mode: if the explicit mount check fails, logic falls back to scanning the partition table. This restores compatibility with containerized installs while maintaining strict safety checks for `to-filesystem` and `to-disk` modes. Signed-off-by: Daniele Guarascio <guarascio.daniele@gmail.com>
bae675d to
67361c4
Compare
Basically whenever the active mount (/boot/efi) disagreed with the first physical candidate on the disk. Some of the circumstances where the old "scan-the-disk" logic would fail:
|
Currently, the installation requires the ESP to be explicitly mounted.
This change allows the bootloader logic to locate the ESP by scanning
the partition table if the mount check fails.
This change also updates 'get_esp_device' to return 'Cow<str>' to avoid
unnecessary allocations when returning a reference to the partition node.
The baseline installation path is updated to allow this fallback,
improving robustness when the filesystem is not fully mounted.
Signed-off-by: Daniele Guarascio <guarascio.daniele@gmail.com>
9ebefc1 to
8d870fc
Compare
Move the open_target_root helper from bootc_composefs/boot.rs to install.rs as a method on the RootSetup struct. Signed-off-by: Daniele Guarascio <guarascio.daniele@gmail.com>
Update the ESP discovery logic to explicitly check for mounts at /efi (per DPS) and /boot (shared ESP), in addition to the traditional /boot/efi. This ensures correct handling of cleanup, bootloader installation, and composefs setup when the ESP is mounted in these alternative locations. Also updates unit tests to verify Cow usage in ESP source normalization. Signed-off-by: Daniele Guarascio <guarascio.daniele@gmail.com>
Previously,
bootc install to-filesystemdetermined the ESP by scanning the partition table of the disk hosting the target root. This logic failed to respect an explicit/boot/efimount if it was different from the first ESP on the disk.This change updates the installation logic (both for systemd-boot and bootupd paths) to strictly require that
/boot/efiis mounted under the target root. It inspects this mountpoint to determine the correct backing device, ensuring the installation targets the intended ESP.Assisted-by: Zed Agent (GPT-5.2-Codex)
Fixes: #1929