Skip to content

efi: rewrite ensure_mounted_esp() - #932

Merged
HuijingHei merged 7 commits into
coreos:mainfrom
HuijingHei:split-ensure-mounted-esp
Jun 1, 2025
Merged

HuijingHei merged 7 commits into
coreos:mainfrom
HuijingHei:split-ensure-mounted-esp

Conversation

@HuijingHei

@HuijingHei HuijingHei commented May 21, 2025 •

Copy link
Copy Markdown
Contributor

This is the preparation for #855.

The main target for this PR is: "efi: rewrite ensure_mounted_esp()", but find there are much to update consequently.


efi: rewrite ensure_mounted_esp()

Split into 2 parts:

  • get_mounted_esp() to get mounted point esp
  • mount_esp_device() to mount the passed esp device, return
    the mount point

Then in ensure_mounted_esp() call the above 2 functions:
firstly check if esp is already mounted, if not, mount the passed
esp device.


efi: update install() and update() according to split change


adopt_update: pass RootContext as parameter


efi: update validate() according to the split change

@openshift-ci

openshift-ci Bot commented May 21, 2025

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@HuijingHei
HuijingHei force-pushed the split-ensure-mounted-esp branch 5 times, most recently from aacbb09 to d34bf3b Compare May 21, 2025 12:49
@HuijingHei HuijingHei changed the title Split ensure mounted esp efi: rewrite ensure_mounted_esp() May 21, 2025
@HuijingHei
HuijingHei marked this pull request as ready for review May 21, 2025 13:12
Comment thread src/efi.rs Resolved
@HuijingHei

Copy link
Copy Markdown
Contributor Author

Ready for review now, thanks!

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

Looks reasonable to me overall, I just have some nits

Comment thread src/efi.rs Resolved
Comment thread src/efi.rs Resolved
@HuijingHei
HuijingHei force-pushed the split-ensure-mounted-esp branch 2 times, most recently from 9c9c6c7 to a85552e Compare May 23, 2025 14:32

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

It looks like the cosa build is legitimately failing.

@HuijingHei

HuijingHei commented May 26, 2025 •

Copy link
Copy Markdown
Contributor Author

Seems the try_fold() iter all items without return at the first match, checking more fix this with return early.

@HuijingHei
HuijingHei force-pushed the split-ensure-mounted-esp branch 2 times, most recently from 3ff06fe to 950feab Compare May 26, 2025 12:04
@HuijingHei

Copy link
Copy Markdown
Contributor Author

/test test

@HuijingHei
HuijingHei force-pushed the split-ensure-mounted-esp branch from 950feab to ed38ae0 Compare May 26, 2025 13:23
Split into 2 parts:
- `get_mounted_esp()` to get mounted point esp
- `mount_esp_device()` to mount the passed esp device, return
the mount point

Then in `ensure_mounted_esp()` call the above 2 functions:
firstly check if esp is already mounted, if not, mount the passed
esp device.
@HuijingHei
HuijingHei force-pushed the split-ensure-mounted-esp branch from ed38ae0 to 53ea47f Compare May 26, 2025 14:26
Comment thread src/efi.rs
log::debug!("Found metadata {}", meta.version);
let srcdir_name = component_updatedirname(self);
let ft = crate::filetree::FileTree::new_from_dir(&src_root.sub_dir(&srcdir_name)?)?;
let destdir = &self.ensure_mounted_esp(Path::new(dest_root))?;

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.

Why can't we keep calling this one to do the "mount if not mounted" logic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question. After change, the function ensure_mounted_esp() will check if esp is already mounted, else mount the passed esp device, return the mount point and append path /EFI.

For installation, during bootc install to-disk, the esp device is not mounted and will call get_esp_device() to get esp device via /dev/disk/by-partlabel, but when running cosa build, not sure if it would also call bootc, find that esp device is already mounted, and can not find esp device via /dev/disk/by-partlabel (do not why). Before I use esp_device = self.get_esp_device() before ensure_mounted_esp(), but cosa build failed.

@HuijingHei HuijingHei May 28, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If failed get_esp_device() (via /dev/disk/by-partlabel), change to get_esp_partition(device) (via sfdisk).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

According to comment, use blockdev to find the partition, instead of partlabel.

@HuijingHei
HuijingHei force-pushed the split-ensure-mounted-esp branch 2 times, most recently from c17b92c to e0cfb73 Compare May 28, 2025 03:16
Comment thread src/blockdev.rs Resolved
Comment thread src/blockdev.rs Resolved
Comment thread src/bios.rs Resolved
Comment thread src/bootupd.rs Resolved
Comment thread src/component.rs Resolved
Comment thread src/bios.rs Resolved
Comment thread src/efi.rs Resolved
Comment thread src/efi.rs Resolved
Comment thread src/efi.rs Resolved
@HuijingHei
HuijingHei force-pushed the split-ensure-mounted-esp branch 2 times, most recently from d2716e4 to 5998d92 Compare May 29, 2025 02:40

@dustymabe dustymabe 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 - a few small suggestions

Comment thread src/efi.rs Resolved
Comment thread src/efi.rs Resolved
@HuijingHei
HuijingHei force-pushed the split-ensure-mounted-esp branch from 5998d92 to e4b7a71 Compare May 29, 2025 14:50
instead of `partlabel`

Copy Dusty's comment from https://github.com/coreos/bootupd/pull/932/files#r2112567301:

During `bootc install to-disk` the esp device is not mounted but
we can call `get_esp_device()` and it will find the device via
the `/dev/disk/by-partlabel/` symlink. When running `cosa build` and
building a disk image using `OSBuild` the EFI partitions is mounted
but no udev `/dev/disk/by-partlabel/` symlinks exist because it's
just a chroot and not a full linux environment. In that case
fallback to using `blockdev` to find the partition.

Even better, get rid of `self.get_esp_device()` altogether and just
use `blockdev`
@HuijingHei
HuijingHei force-pushed the split-ensure-mounted-esp branch from e4b7a71 to f6ef3d1 Compare May 29, 2025 14:54

@dustymabe dustymabe 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 - merge when ready

@HuijingHei
HuijingHei merged commit 50adce8 into coreos:main Jun 1, 2025
@HuijingHei
HuijingHei deleted the split-ensure-mounted-esp branch June 1, 2025 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants