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

Ensure ESP is mounted #127

Merged
merged 2 commits into from
Jan 5, 2021

Conversation

kelvinfan001
Copy link
Member

@kelvinfan001 kelvinfan001 commented Dec 21, 2020

Following coreos/fedora-coreos-config#794,
the ESP will no longer be mounted by default in FCOS. Mount the
ESP at a directory with a random name in bootupd's sandboxed /tmp
ourselves before reading from/writing to it.

Note that ESPs on redundant disks is not yet supported, this commit
simply mounts the device with part-label EFI-SYSTEM if one exists.

ProtectClock=yes in bootupd.service is preventing the ESP from
being mounted, remove that for now.

@kelvinfan001
Copy link
Member Author

Kola tests pass with a local FCOS build with coreos/fedora-coreos-config#794.

@kelvinfan001 kelvinfan001 force-pushed the kfan-mount-efi branch 4 times, most recently from 9dc090a to 2359f12 Compare December 21, 2020 23:20
@bgilbert
Copy link
Contributor

No longer ProtectClock=yes in bootupd.service to allow bootupd to mount the ESP.

Hmm, could you expand on this? Why do these conflict?

Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately there are deeper architectural consequences to having multiple ESPs. Every operation will need to iterate over all ESPs, and cannot assume that the ESPs are all in the same state. (There's a reasonable argument that if the ESPs get desynced, fixing it isn't our responsibility, but it'd be better UX if we handled it anyway.)

src/efi.rs Outdated
let sysroot = openat::Dir::open("/")?;
let esp = sysroot.sub_dir(&self.esp_path())?;
Ok(esp)
}

fn ensure_mounted_esp(&self) -> Result<()> {
let mount_point = &Path::new("/").join(MOUNT_PATH);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should create a temporary directory to use as a mountpoint, and then clean it up afterward.

Copy link
Member

@cgwalters cgwalters Dec 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add PrivateTmp=yes too. (EDIT: already is there)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah if we use PrivateTmp then we can rely on systemd to clean up our tempdir.
Then I'd use https://docs.rs/tempfile/3.1.0/tempfile/struct.TempDir.html#method.into_path (i.e. make a tempdir, mount on it and then return the path).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about only updating ESP's that are listed in NVRAM? Non-UEFI is trickier, risky to step on all BIOS Boot or MBR gaps with grub-install.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For CoreOS, at least, we can make some simplifying assumptions. We own the whole system, so we can update every ESP and BIOS Boot partition we see. CoreOS boots via Default Boot Behavior and doesn't set Boot NVRAM variables at all.

If bootupd is going to generalize beyond CoreOS, of course, those assumptions may no longer be workable.

Copy link

@cmurf cmurf Dec 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'm thinking the idea to rebase Silverblue on CoreOS.

That use case includes dual boot, so I think "fair game" includes overwriting the MBR gap, BIOS Boot, and ESP:/EFI/fedora/ on the drive that contains the current active /; but not anything else. i.e. EFI/fedora is owned but not the entire ESP. There's a low, but non-zero, chance of USB sticks, SD Cards, external drives or even other internal drives, are present and used to boot another OS; and also can't be touched.

Another possible use case is Silverblue (or Workstation) running from an SD Card or USB stick. It's a use case we're more seriously considering for Workstation as a way to maybe reduce dependency on dual-boot installations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so far bootupd is Fedora CoreOS specific but the idea from the start is it could generalize indeed to other rpm-ostree systems (i.e. not necessarily coreos-assembler generated) as well as even not rpm-ostree systems (traditional yum/dnf/zypper/apt).

It's still not clear to me that the latter effort is really worth it but I don't want to exclude it.

src/efi.rs Show resolved Hide resolved
@kelvinfan001
Copy link
Member Author

kelvinfan001 commented Dec 22, 2020

Hmm, could you expand on this? Why do these conflict?

Admittedly, it was just trial and error. The tests passed when I removed this; otherwise, there were some permission issues.

Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

src/efi.rs Outdated
let sysroot = openat::Dir::open("/")?;
let esp = sysroot.sub_dir(&self.esp_path())?;
Ok(esp)
}

fn ensure_mounted_esp(&self) -> Result<()> {
let mount_point = &Path::new("/").join(MOUNT_PATH);
Copy link
Member

@cgwalters cgwalters Dec 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add PrivateTmp=yes too. (EDIT: already is there)

src/efi.rs Outdated
let sysroot = openat::Dir::open("/")?;
let esp = sysroot.sub_dir(&self.esp_path())?;
Ok(esp)
}

fn ensure_mounted_esp(&self) -> Result<()> {
let mount_point = &Path::new("/").join(MOUNT_PATH);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah if we use PrivateTmp then we can rely on systemd to clean up our tempdir.
Then I'd use https://docs.rs/tempfile/3.1.0/tempfile/struct.TempDir.html#method.into_path (i.e. make a tempdir, mount on it and then return the path).

@@ -19,7 +19,6 @@ ProtectHome=yes
ReadOnlyPaths=/usr
PrivateTmp=yes
PrivateNetwork=yes
ProtectClock=yes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably something going wrong in the seccomp policy systemd makes. It's...about time...we looked at that.


fn ensure_mounted_esp(&self) -> Result<()> {
let mount_point = &Path::new("/").join(&*MOUNT_PATH);
let output = std::process::Command::new("mountpoint")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't bad, but now that we know our process is the only one doing the mount (in our mount namespace), I think it'd be better to have a something like Arc<Mutex<Option<PathBuf>>> or...actually there's a lazy_init crate for that even.

Basically do the tempdir creation + mount as a single locked unit instead.

Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor must fix for the crate ref, everything else is optional or can be followup.

Thanks for working on this!

@@ -81,3 +81,10 @@ assert_not_file_has_content_literal () {
done
}

# Mount the EFI partition at a temporary location.
tmpefimount=/tmp/efi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just the test suite, but I try as a general rule to avoid predictably named temporary files. We could have this code mirror the main logic and use e.g. $(mktemp -d) and "return" it by printing, so
callers do e.g.:
tmpefimount=$(mount_tmp_efi)
etc.

Not a blocker, just noting.

src/efi.rs Outdated
@@ -14,6 +14,7 @@ use anyhow::{bail, Context, Result};
use openat_ext::OpenatDirExt;

use chrono::prelude::*;
use structopt::lazy_static::lazy_static;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add the dependency to Cargo.toml directly; it looks like a bug that structopt is re-exporting it.

src/efi.rs Show resolved Hide resolved
Following coreos/fedora-coreos-config#794,
the ESP will no longer be mounted by default in FCOS. Mount the
ESP at a directory with a random name in bootupd's sandboxed /tmp
ourselves before reading from/writing to it.

Note that ESPs on redundant disks is not yet supported, this commit
simply mounts the device with part-label `EFI-SYSTEM` if one exists.

`ProtectClock=yes` in `bootupd.service` is preventing the ESP from
being mounted, remove that for now.
Following coreos/fedora-coreos-config#794,
the ESP will no longer be mounted in /boot. Adjust tests to mount
it before reading from it.
Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cgwalters, kelvinfan001

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [cgwalters,kelvinfan001]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cgwalters
Copy link
Member

Moved the ProtectClock issue to systemd/systemd#18142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants