Skip to content

Commit af13b84

Browse files
Johan-Liebert1travier
authored andcommitted
composefs-backend: Fix bootc status for BLS complaint bootloader
For BLS complaint bootloaders, just systemd for now, we were still looking for entries in `boot/loader/entries` which was failing as entries for these bootloaders will be stored in the ESP. Also, refactor to use `TempMount::mount_dev` for mounting ESP Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent e6fab79 commit af13b84

File tree

3 files changed

+34
-47
lines changed

3 files changed

+34
-47
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::fs::create_dir_all;
22
use std::io::Write;
3-
use std::process::Command;
3+
use std::path::Path;
44
use std::{ffi::OsStr, path::PathBuf};
55

66
use anyhow::{anyhow, Context, Result};
77
use bootc_blockdev::find_parent_devices;
88
use bootc_mount::inspect_filesystem;
9-
use bootc_utils::CommandRunExt;
9+
use bootc_mount::tempmount::TempMount;
1010
use camino::{Utf8Path, Utf8PathBuf};
1111
use cap_std_ext::{
1212
cap_std::{ambient_authority, fs::Dir},
@@ -272,8 +272,6 @@ struct BLSEntryPath<'a> {
272272
abs_entries_path: &'a str,
273273
/// Where to write the .conf files
274274
config_path: Utf8PathBuf,
275-
/// If we mounted EFI, the target path
276-
mount_path: Option<Utf8PathBuf>,
277275
}
278276

279277
/// Sets up and writes BLS entries and binaries (VMLinuz + Initrd) to disk
@@ -352,35 +350,23 @@ pub(crate) fn setup_composefs_bls_boot(
352350
entries_path: root_path.join("boot"),
353351
config_path: root_path.join("boot"),
354352
abs_entries_path: "boot",
355-
mount_path: None,
356353
},
357354
None,
358355
),
359356

360357
Bootloader::Systemd => {
361-
let temp_efi_dir = tempfile::tempdir().map_err(|e| {
362-
anyhow::anyhow!("Failed to create temporary directory for EFI mount: {e}")
363-
})?;
364-
365-
let mounted_efi = Utf8PathBuf::from_path_buf(temp_efi_dir.path().to_path_buf())
366-
.map_err(|_| anyhow::anyhow!("EFI dir is not valid UTF-8"))?;
367-
368-
Command::new("mount")
369-
.args([&PathBuf::from(&esp_device), mounted_efi.as_std_path()])
370-
.log_debug()
371-
.run_inherited_with_cmd_context()
372-
.context("Mounting EFI")?;
358+
let efi_mount = TempMount::mount_dev(&esp_device).context("Mounting ESP")?;
373359

360+
let mounted_efi = Utf8PathBuf::from(efi_mount.dir.path().as_str()?);
374361
let efi_linux_dir = mounted_efi.join(EFI_LINUX);
375362

376363
(
377364
BLSEntryPath {
378365
entries_path: efi_linux_dir,
379366
config_path: mounted_efi.clone(),
380367
abs_entries_path: EFI_LINUX,
381-
mount_path: Some(mounted_efi),
382368
},
383-
Some(temp_efi_dir),
369+
Some(efi_mount),
384370
)
385371
}
386372
};
@@ -518,14 +504,6 @@ pub(crate) fn setup_composefs_bls_boot(
518504
rustix::fs::fsync(owned_loader_entries_fd).context("fsync")?;
519505
}
520506

521-
if let Some(mounted_efi) = entry_paths.mount_path {
522-
Command::new("umount")
523-
.arg(mounted_efi)
524-
.log_debug()
525-
.run_inherited_with_cmd_context()
526-
.context("Unmounting EFI")?;
527-
}
528-
529507
Ok(boot_digest)
530508
}
531509

@@ -537,7 +515,7 @@ fn write_pe_to_esp(
537515
pe_type: PEType,
538516
uki_id: &String,
539517
is_insecure_from_opts: bool,
540-
mounted_efi: &PathBuf,
518+
mounted_efi: impl AsRef<Path>,
541519
) -> Result<Option<String>> {
542520
let efi_bin = read_file(file, &repo).context("Reading .efi binary")?;
543521

@@ -574,7 +552,7 @@ fn write_pe_to_esp(
574552
}
575553

576554
// Write the UKI to ESP
577-
let efi_linux_path = mounted_efi.join(EFI_LINUX);
555+
let efi_linux_path = mounted_efi.as_ref().join(EFI_LINUX);
578556
create_dir_all(&efi_linux_path).context("Creating EFI/Linux")?;
579557

580558
let final_pe_path = match file_path.parent() {
@@ -768,13 +746,7 @@ pub(crate) fn setup_composefs_uki_boot(
768746
}
769747
};
770748

771-
let temp_efi_dir = tempfile::tempdir()
772-
.map_err(|e| anyhow::anyhow!("Failed to create temporary directory for EFI mount: {e}"))?;
773-
let mounted_efi = temp_efi_dir.path().to_path_buf();
774-
775-
Task::new("Mounting ESP", "mount")
776-
.args([&PathBuf::from(&esp_device), &mounted_efi.clone()])
777-
.run()?;
749+
let esp_mount = TempMount::mount_dev(&esp_device).context("Mounting ESP")?;
778750

779751
let mut boot_label = String::new();
780752

@@ -793,7 +765,7 @@ pub(crate) fn setup_composefs_uki_boot(
793765
entry.pe_type,
794766
&id.to_hex(),
795767
is_insecure_from_opts,
796-
&mounted_efi,
768+
esp_mount.dir.path(),
797769
)?;
798770

799771
if let Some(label) = ret {
@@ -803,12 +775,6 @@ pub(crate) fn setup_composefs_uki_boot(
803775
};
804776
}
805777

806-
Command::new("umount")
807-
.arg(&mounted_efi)
808-
.log_debug()
809-
.run_inherited_with_cmd_context()
810-
.context("Unmounting ESP")?;
811-
812778
match bootloader {
813779
Bootloader::Grub => {
814780
write_grub_uki_menuentry(root_path, &setup_type, &boot_label, id, &esp_device)?

crates/lib/src/bootc_composefs/status.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use std::{io::Read, sync::OnceLock};
1+
use std::{io::Read, sync::OnceLock, u16};
22

33
use anyhow::{Context, Result};
44
use bootc_kernel_cmdline::utf8::Cmdline;
5+
use bootc_mount::tempmount::TempMount;
56
use fn_error_context::context;
67

78
use crate::{
8-
bootc_composefs::boot::BootType,
9+
bootc_composefs::boot::{get_esp_partition, get_sysroot_parent_dev, BootType},
910
composefs_consts::{BOOT_LOADER_ENTRIES, COMPOSEFS_CMDLINE, USER_CFG},
1011
parsers::{
1112
bls_config::{parse_bls_config, BLSConfig},
@@ -351,7 +352,27 @@ pub(crate) async fn composefs_deployment_status() -> Result<Host> {
351352
anyhow::bail!("Could not determine boot type");
352353
};
353354

354-
let boot_dir = sysroot.open_dir("boot").context("Opening boot dir")?;
355+
let booted = host.require_composefs_booted()?;
356+
357+
let (boot_dir, _temp_guard) = match booted.bootloader {
358+
Bootloader::Grub => (sysroot.open_dir("boot").context("Opening boot dir")?, None),
359+
360+
// TODO: This is redundant as we should already have ESP mounted at `/efi/` accoding to
361+
// spec; currently we do not
362+
//
363+
// See: https://uapi-group.org/specifications/specs/boot_loader_specification/#mount-points
364+
Bootloader::Systemd => {
365+
let parent = get_sysroot_parent_dev()?;
366+
let (esp_part, ..) = get_esp_partition(&parent)?;
367+
368+
let esp_mount = TempMount::mount_dev(&esp_part)?;
369+
370+
let dir = esp_mount.fd.try_clone().context("Cloning fd")?;
371+
let guard = Some(esp_mount);
372+
373+
(dir, guard)
374+
}
375+
};
355376

356377
match boot_type {
357378
BootType::Bls => {

crates/lib/src/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub(crate) const ARCH_USES_EFI: bool = cfg!(any(target_arch = "x86_64", target_a
9090
#[cfg(any(feature = "composefs-backend", feature = "install-to-disk"))]
9191
pub(crate) const ESP_GUID: &str = "C12A7328-F81F-11D2-BA4B-00A0C93EC93B";
9292
#[cfg(any(feature = "composefs-backend", feature = "install-to-disk"))]
93-
pub(crate) const DPS_UUID: &str = "6523f8ae-3eb1-4e2a-a05a-18b695ae656f";
93+
pub(crate) const DPS_UUID: &str = "4f68bce3-e8cd-4db1-96e7-fbcaf984b709";
9494

9595
const DEFAULT_REPO_CONFIG: &[(&str, &str)] = &[
9696
// Default to avoiding grub2-mkconfig etc.

0 commit comments

Comments
 (0)