Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

efi: Rework mount order #546

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::util::CommandRunExt;
use crate::{component::*, packagesystem};

/// Well-known paths to the ESP that may have been mounted external to us.
pub(crate) const ESP_MOUNTS: &[&str] = &["boot", "boot/efi", "efi"];
pub(crate) const ESP_MOUNTS: &[&str] = &["boot/efi", "efi", "boot"];

/// The ESP partition label on Fedora CoreOS derivatives
pub(crate) const COREOS_ESP_PART_LABEL: &str = "EFI-SYSTEM";
Expand Down Expand Up @@ -54,7 +54,7 @@ impl Efi {
Ok(esp)
}

fn ensure_mounted_esp(&self, root: &Path) -> Result<PathBuf> {
pub(crate) fn ensure_mounted_esp(&self, root: &Path) -> Result<PathBuf> {
let mut mountpoint = self.mountpoint.borrow_mut();
if let Some(mountpoint) = mountpoint.as_deref() {
return Ok(mountpoint.to_owned());
Expand Down Expand Up @@ -84,16 +84,22 @@ impl Efi {
}
}
let esp_device = esp_device.ok_or_else(|| anyhow::anyhow!("Failed to find ESP device"))?;
let tmppath = tempfile::tempdir_in("/tmp")?.into_path();
let status = std::process::Command::new("mount")
.arg(&esp_device)
.arg(&tmppath)
.status()?;
if !status.success() {
anyhow::bail!("Failed to mount {:?}", esp_device);
for &mnt in ESP_MOUNTS.iter() {
let mnt = root.join(mnt);
if !mnt.exists() {
continue;
}
let status = std::process::Command::new("mount")
.arg(&esp_device)
.arg(&mnt)
.status()?;
if !status.success() {
anyhow::bail!("Failed to mount {:?}", esp_device);
}
log::debug!("Mounted at {mnt:?}");
*mountpoint = Some(mnt);
break;
}
log::debug!("Mounted at {tmppath:?}");
*mountpoint = Some(tmppath);
Ok(mountpoint.as_deref().unwrap().to_owned())
}

Expand Down Expand Up @@ -380,6 +386,7 @@ impl Component for Efi {

impl Drop for Efi {
fn drop(&mut self) {
log::debug!("Unmounting");
let _ = self.unmount();
}
}
Expand Down