Skip to content

Ensure ESP is mounted - #127

Merged
openshift-merge-robot merged 2 commits into
coreos:masterfrom
kelvinfan001:kfan-mount-efi
Jan 5, 2021
Merged

openshift-merge-robot merged 2 commits into
coreos:masterfrom
kelvinfan001:kfan-mount-efi

Conversation

@kelvinfan001

@kelvinfan001 kelvinfan001 commented Dec 21, 2020 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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
Copy Markdown
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?

@bgilbert bgilbert left a comment

Copy link
Copy Markdown
Contributor

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.)

Comment thread src/efi.rs Outdated
}

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

Copy link
Copy Markdown
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.

@cgwalters cgwalters Dec 22, 2020 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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.

@cmurf cmurf Dec 26, 2020 •

Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread src/efi.rs Resolved
@kelvinfan001

kelvinfan001 commented Dec 22, 2020 •

Copy link
Copy Markdown
Contributor Author

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.

@cgwalters cgwalters left a comment

Copy link
Copy Markdown
Member

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!

Comment thread src/efi.rs Outdated
}

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

@cgwalters cgwalters Dec 22, 2020 •

Copy link
Copy Markdown
Member

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)

Comment thread src/efi.rs Outdated
}

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

Copy link
Copy Markdown
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).

Comment thread systemd/bootupd.service
ReadOnlyPaths=/usr
PrivateTmp=yes
PrivateNetwork=yes
ProtectClock=yes

Copy link
Copy Markdown
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.

@kelvinfan001
kelvinfan001 force-pushed the kfan-mount-efi branch 4 times, most recently from 0b875d0 to a4b2255 Compare December 24, 2020 19:32
@kelvinfan001 kelvinfan001 changed the title WIP: Ensure ESP is mounted Ensure ESP is mounted Jan 4, 2021
Comment thread src/efi.rs

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

Copy link
Copy Markdown
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.

@cgwalters cgwalters left a comment

Copy link
Copy Markdown
Member

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!

Comment thread tests/kola/data/libtest.sh Outdated
}

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

Copy link
Copy Markdown
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.

Comment thread src/efi.rs Outdated
use openat_ext::OpenatDirExt;

use chrono::prelude::*;
use structopt::lazy_static::lazy_static;

Copy link
Copy Markdown
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.

Comment thread src/efi.rs 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.

@cgwalters cgwalters left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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

Details 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
Copy Markdown
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