Skip to content

Commit 9dc090a

Browse files
committed
Ensure ESP is mounted
Following coreos/fedora-coreos-config#794, the mount unit for `/boot/efi` will be dropped, since there is no longer going to be a "canonical ESP" to mount. No longer `ProtectClock=yes` in `bootupd.service` to allow bootupd to mount the ESP.
1 parent 5a298e6 commit 9dc090a

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/efi.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use crate::util::CommandRunExt;
2424

2525
/// The path to the ESP mount
2626
pub(crate) const MOUNT_PATH: &str = "boot/efi";
27+
/// The ESP partition label
28+
pub(crate) const ESP_PART_LABEL: &str = "EFI-SYSTEM";
2729

2830
#[derive(Default)]
2931
pub(crate) struct EFI {}
@@ -33,16 +35,47 @@ impl EFI {
3335
Path::new(MOUNT_PATH).join("EFI")
3436
}
3537

38+
fn esp_device(&self) -> PathBuf {
39+
Path::new("/dev/disk/by-partlabel/").join(ESP_PART_LABEL)
40+
}
41+
3642
fn open_esp_optional(&self) -> Result<Option<openat::Dir>> {
43+
self.ensure_mounted_esp()?;
3744
let sysroot = openat::Dir::open("/")?;
3845
let esp = sysroot.sub_dir_optional(&self.esp_path())?;
3946
Ok(esp)
4047
}
4148
fn open_esp(&self) -> Result<openat::Dir> {
49+
self.ensure_mounted_esp()?;
4250
let sysroot = openat::Dir::open("/")?;
4351
let esp = sysroot.sub_dir(&self.esp_path())?;
4452
Ok(esp)
4553
}
54+
55+
fn ensure_mounted_esp(&self) -> Result<()> {
56+
let mount_point = &Path::new("/").join(MOUNT_PATH);
57+
let output = std::process::Command::new("mountpoint")
58+
.arg(mount_point)
59+
.output()
60+
.expect("Failed to determine if EFI mounted");
61+
if !output.status.success() {
62+
let status = std::process::Command::new("mkdir")
63+
.arg("-p")
64+
.arg(mount_point)
65+
.status()?;
66+
if !status.success() {
67+
anyhow::bail!("Failed to create directory {:?}", mount_point);
68+
}
69+
let status = std::process::Command::new("mount")
70+
.arg(&self.esp_device())
71+
.arg(mount_point)
72+
.status()?;
73+
if !status.success() {
74+
anyhow::bail!("Failed to mount {:?}", &self.esp_device());
75+
}
76+
};
77+
Ok(())
78+
}
4679
}
4780

4881
impl Component for EFI {
@@ -112,6 +145,7 @@ impl Component for EFI {
112145
};
113146
let srcdir_name = component_updatedirname(self);
114147
let ft = crate::filetree::FileTree::new_from_dir(&src_root.sub_dir(&srcdir_name)?)?;
148+
self.ensure_mounted_esp()?;
115149
let destdir = Path::new(dest_root).join(MOUNT_PATH);
116150
{
117151
let destd = openat::Dir::open(&destdir)
@@ -151,6 +185,7 @@ impl Component for EFI {
151185
.context("opening update dir")?;
152186
let updatef = filetree::FileTree::new_from_dir(&updated).context("reading update dir")?;
153187
let diff = currentf.diff(&updatef)?;
188+
self.ensure_mounted_esp()?;
154189
let destdir = openat::Dir::open(&Path::new("/").join(MOUNT_PATH).join("EFI"))
155190
.context("opening EFI dir")?;
156191
validate_esp(&destdir)?;
@@ -178,7 +213,8 @@ impl Component for EFI {
178213
std::fs::remove_dir_all(&p)?;
179214
}
180215
}
181-
216+
217+
self.ensure_mounted_esp()?;
182218
let efisrc = ostreebootdir.join("efi/EFI");
183219
if !efisrc.exists() {
184220
bail!("Failed to find {:?}", &efisrc);
@@ -256,6 +292,7 @@ impl Component for EFI {
256292
.filetree
257293
.as_ref()
258294
.ok_or_else(|| anyhow::anyhow!("No filetree for installed EFI found!"))?;
295+
self.ensure_mounted_esp()?;
259296
let efidir = openat::Dir::open(&Path::new("/").join(MOUNT_PATH).join("EFI"))?;
260297
let diff = currentf.relative_diff_to(&efidir)?;
261298
let mut errs = Vec::new();

systemd/bootupd.service

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ ProtectHome=yes
1919
ReadOnlyPaths=/usr
2020
PrivateTmp=yes
2121
PrivateNetwork=yes
22-
ProtectClock=yes
2322
ProtectHostname=yes
2423
ProtectControlGroups=yes
2524
RestrictSUIDSGID=yes

0 commit comments

Comments
 (0)