Skip to content

Commit 28e613f

Browse files
committed
install: attempt to use an already mounted ESP at the target
Let's attempt to use an already mounted ESP at the target dest_root if one is already mounted there in a known ESP location, if failed, will fallback to mount ESP partition of the device. See coreos/coreos-assembler#4161
1 parent 766bb80 commit 28e613f

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/efi.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,22 @@ impl Component for Efi {
345345
let srcdir_name = component_updatedirname(self);
346346
let ft = crate::filetree::FileTree::new_from_dir(&src_root.sub_dir(&srcdir_name)?)?;
347347

348-
// Using `blockdev` to find the partition instead of partlabel because
349-
// we know the target install toplevel device already.
350-
let esp_device = blockdev::get_esp_partition(device)?
351-
.ok_or_else(|| anyhow::anyhow!("Failed to find ESP device"))?;
352-
353-
let destpath = &self.ensure_mounted_esp(Path::new(dest_root), Path::new(&esp_device))?;
348+
// Let's attempt to use an already mounted ESP at the target
349+
// dest_root if one is already mounted there in a known ESP location.
350+
let destpath = if let Some(destdir) = self.get_mounted_esp(Path::new(dest_root))? {
351+
destdir
352+
} else {
353+
// Using `blockdev` to find the partition instead of partlabel because
354+
// we know the target install toplevel device already.
355+
if device.is_empty() {
356+
anyhow::bail!("Got device is empty");
357+
}
358+
let esp_device = blockdev::get_esp_partition(device)?
359+
.ok_or_else(|| anyhow::anyhow!("Failed to find ESP device"))?;
360+
self.mount_esp_device(Path::new(dest_root), Path::new(&esp_device))?
361+
};
354362

355-
let destd = &openat::Dir::open(destpath)
363+
let destd = &openat::Dir::open(&destpath)
356364
.with_context(|| format!("opening dest dir {}", destpath.display()))?;
357365
validate_esp_fstype(destd)?;
358366

0 commit comments

Comments
 (0)