Skip to content

Commit e4b7a71

Browse files
committed
efi: during installation using blockdev to find esp partition
instead of `partlabel` Copy Dusty's comment from https://github.com/coreos/bootupd/pull/932/files#r2112567301: During `bootc install to-disk` the esp device is not mounted but we can call `get_esp_device()` and it will find the device via the `/dev/disk/by-partlabel/` symlink. When running `cosa build` and building a disk image using `OSBuild` the EFI partitions is mounted but no udev `/dev/disk/by-partlabel/` symlinks exist because it's just a chroot and not a full linux environment. In that case fallback to using `blockdev` to find the partition. Even better, get rid of `self.get_esp_device()` altogether and just use `blockdev`
1 parent 53db0e9 commit e4b7a71

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/bootupd.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,21 @@ pub(crate) fn status() -> Result<Status> {
328328
// Process the remaining components not installed
329329
log::trace!("Remaining known components: {}", known_components.len());
330330
for (name, _) in known_components {
331-
// Only run `query_adopt_state()` is enough
332-
// When do adopt and update for each component, will check more
331+
// To determine if not-installed components can be adopted:
332+
//
333+
// `query_adopt_state()` checks for existing installation state,
334+
// such as a `version` in `/sysroot/.coreos-aleph-version.json`,
335+
// or the presence of `/ostree/deploy`.
336+
//
337+
// `component.query_adopt()` performs additional checks,
338+
// including hardware/device requirements.
339+
// For example, it will skip BIOS adoption if the system is booted via EFI
340+
// and lacks a BIOS_BOOT partition.
341+
//
342+
// Once a component is determined to be adoptable, it is added to the
343+
// adoptable list, and adoption proceeds automatically.
344+
//
345+
// Therefore, calling `query_adopt_state()` alone is sufficient.
333346
if let Some(adopt_ver) = crate::component::query_adopt_state()? {
334347
ret.adoptable.insert(name.to_string(), adopt_ver);
335348
} else {

src/efi.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,6 @@ pub(crate) struct Efi {
6161
}
6262

6363
impl Efi {
64-
// Get esp device via EFI partlabel
65-
fn get_esp_device(&self) -> Option<PathBuf> {
66-
let esp_devices = [COREOS_ESP_PART_LABEL, ANACONDA_ESP_PART_LABEL]
67-
.into_iter()
68-
.map(|p| Path::new("/dev/disk/by-partlabel/").join(p));
69-
let mut esp_device = None;
70-
for path in esp_devices {
71-
if path.exists() {
72-
esp_device = Some(path);
73-
break;
74-
}
75-
}
76-
return esp_device;
77-
}
78-
7964
// Get mounted point for esp
8065
pub(crate) fn get_mounted_esp(&self, root: &Path) -> Result<Option<PathBuf>> {
8166
// First check all potential mount points without holding the borrow
@@ -321,11 +306,13 @@ impl Component for Efi {
321306
log::debug!("Found metadata {}", meta.version);
322307
let srcdir_name = component_updatedirname(self);
323308
let ft = crate::filetree::FileTree::new_from_dir(&src_root.sub_dir(&srcdir_name)?)?;
324-
// get esp device via /dev/disk/by-partlabel
325-
let esp_device = self
326-
.get_esp_device()
309+
310+
// Using `blockdev` to find the partition instead of partlabel because
311+
// we know the target install toplevel device already.
312+
let esp_device = blockdev::get_esp_partition(device)?
327313
.ok_or_else(|| anyhow::anyhow!("Failed to find ESP device"))?;
328-
let destpath = &self.ensure_mounted_esp(Path::new(dest_root), &esp_device)?;
314+
315+
let destpath = &self.ensure_mounted_esp(Path::new(dest_root), Path::new(&esp_device))?;
329316

330317
let destd = &openat::Dir::open(destpath)
331318
.with_context(|| format!("opening dest dir {}", destpath.display()))?;

0 commit comments

Comments
 (0)