Skip to content

Commit 8d870fc

Browse files
committed
lib: Fallback to partition table for ESP
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>
1 parent 67361c4 commit 8d870fc

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@ pub(crate) async fn setup_composefs_boot(
12911291
&state.config_opts,
12921292
None,
12931293
get_secureboot_keys(&mounted_fs, BOOTC_AUTOENROLL_PATH)?,
1294+
root_setup.require_esp_mount,
12941295
)?;
12951296
}
12961297

crates/lib/src/bootloader.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Cow;
12
use std::fs::create_dir_all;
23
use std::process::Command;
34

@@ -72,6 +73,28 @@ pub(crate) fn require_boot_efi_mount(root: &Dir) -> Result<String> {
7273
Ok(source)
7374
}
7475

76+
/// Helper to find the ESP device, either via mount or partition table scan
77+
pub(crate) fn get_esp_device<'a>(
78+
root: &Dir,
79+
device_info: &'a PartitionTable,
80+
require_mount: bool,
81+
) -> Result<Cow<'a, str>> {
82+
if require_mount {
83+
Ok(Cow::Owned(require_boot_efi_mount(root)?))
84+
} else {
85+
match require_boot_efi_mount(root) {
86+
Ok(p) => Ok(Cow::Owned(p)),
87+
Err(e) => {
88+
tracing::debug!(
89+
"ESP mount check failed in permissive mode: {e}; falling back to partition table scan"
90+
);
91+
let esp = esp_in(device_info)?;
92+
Ok(Cow::Borrowed(&esp.node))
93+
}
94+
}
95+
}
96+
}
97+
7598
/// Determine if the invoking environment contains bootupd, and if there are bootupd-based
7699
/// updates in the target root.
77100
#[context("Querying for bootupd")]
@@ -180,13 +203,14 @@ pub(crate) fn install_via_bootupd(
180203
#[context("Installing bootloader")]
181204
pub(crate) fn install_systemd_boot(
182205
root: &Dir,
183-
_device: &PartitionTable,
206+
device: &PartitionTable,
184207
_rootfs: &Utf8Path,
185208
_configopts: &crate::install::InstallConfigOpts,
186209
_deployment_path: Option<&str>,
187210
autoenroll: Option<SecurebootKeys>,
211+
require_mount: bool,
188212
) -> Result<()> {
189-
let esp_device = require_boot_efi_mount(root)?;
213+
let esp_device = get_esp_device(root, device, require_mount)?;
190214

191215
let esp_mount = mount_esp(&esp_device).context("Mounting ESP")?;
192216
let esp_path = Utf8Path::from_path(esp_mount.dir.path())

crates/lib/src/install/baseline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,6 @@ pub(crate) fn install_create_rootfs(
496496
boot,
497497
kargs,
498498
skip_finalize: false,
499-
require_esp_mount: true,
499+
require_esp_mount: false,
500500
})
501501
}

0 commit comments

Comments
 (0)