Skip to content

Commit f6ef3d1

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 f6ef3d1

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
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 & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ pub(crate) const SHIM: &str = "shimx64.efi";
4040
#[cfg(target_arch = "riscv64")]
4141
pub(crate) const SHIM: &str = "shimriscv64.efi";
4242

43-
/// The ESP partition label on Fedora CoreOS derivatives
44-
pub(crate) const COREOS_ESP_PART_LABEL: &str = "EFI-SYSTEM";
45-
pub(crate) const ANACONDA_ESP_PART_LABEL: &str = "EFI\\x20System\\x20Partition";
46-
4743
/// Systemd boot loader info EFI variable names
4844
const LOADER_INFO_VAR_STR: &str = "LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f";
4945
const STUB_INFO_VAR_STR: &str = "StubInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f";
@@ -61,21 +57,6 @@ pub(crate) struct Efi {
6157
}
6258

6359
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-
7960
// Get mounted point for esp
8061
pub(crate) fn get_mounted_esp(&self, root: &Path) -> Result<Option<PathBuf>> {
8162
// First check all potential mount points without holding the borrow
@@ -321,11 +302,13 @@ impl Component for Efi {
321302
log::debug!("Found metadata {}", meta.version);
322303
let srcdir_name = component_updatedirname(self);
323304
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()
305+
306+
// Using `blockdev` to find the partition instead of partlabel because
307+
// we know the target install toplevel device already.
308+
let esp_device = blockdev::get_esp_partition(device)?
327309
.ok_or_else(|| anyhow::anyhow!("Failed to find ESP device"))?;
328-
let destpath = &self.ensure_mounted_esp(Path::new(dest_root), &esp_device)?;
310+
311+
let destpath = &self.ensure_mounted_esp(Path::new(dest_root), Path::new(&esp_device))?;
329312

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

0 commit comments

Comments
 (0)