@@ -5,12 +5,13 @@ use anyhow::{anyhow, bail, Context, Result};
55use bootc_utils:: CommandRunExt ;
66use camino:: Utf8Path ;
77use cap_std_ext:: cap_std:: fs:: Dir ;
8+ use cap_std_ext:: dirext:: CapStdExtDirExt ;
89use fn_error_context:: context;
910
1011use bootc_blockdev:: { Partition , PartitionTable } ;
1112use bootc_mount as mount;
1213
13- use crate :: bootc_composefs:: boot:: { mount_esp, SecurebootKeys } ;
14+ use crate :: bootc_composefs:: boot:: { get_sysroot_parent_dev , mount_esp, SecurebootKeys } ;
1415use crate :: { discoverable_partition_specification, utils} ;
1516
1617/// The name of the mountpoint for efi (as a subdirectory of /boot, or at the toplevel)
@@ -30,6 +31,42 @@ pub(crate) fn esp_in(device: &PartitionTable) -> Result<&Partition> {
3031 . ok_or ( anyhow:: anyhow!( "ESP not found in partition table" ) )
3132}
3233
34+ /// Get esp partition node based on the root dir
35+ pub ( crate ) fn get_esp_partition_node ( root : & Dir ) -> Result < Option < String > > {
36+ let device = get_sysroot_parent_dev ( & root) ?;
37+ let base_partitions = bootc_blockdev:: partitions_of ( Utf8Path :: new ( & device) ) ?;
38+ let esp = base_partitions. find_partition_of_esp ( ) ?;
39+ Ok ( esp. map ( |v| v. node . clone ( ) ) )
40+ }
41+
42+ /// Mount ESP part at /boot/efi
43+ pub ( crate ) fn mount_esp_part ( root : & Dir , root_path : & Utf8Path , is_ostree : bool ) -> Result < ( ) > {
44+ let efi_path = Utf8Path :: new ( "boot" ) . join ( crate :: bootloader:: EFI_DIR ) ;
45+ let Some ( esp_fd) = root
46+ . open_dir_optional ( & efi_path)
47+ . context ( "Opening /boot/efi" ) ?
48+ else {
49+ return Ok ( ( ) ) ;
50+ } ;
51+
52+ let Some ( false ) = esp_fd. is_mountpoint ( "." ) ? else {
53+ return Ok ( ( ) ) ;
54+ } ;
55+
56+ tracing:: debug!( "Not a mountpoint: /boot/efi" ) ;
57+ // On ostree env with enabled composefs, should be /target/sysroot
58+ let physical_root = if is_ostree {
59+ & root. open_dir ( "sysroot" ) . context ( "Opening /sysroot" ) ?
60+ } else {
61+ root
62+ } ;
63+ if let Some ( esp_part) = get_esp_partition_node ( physical_root) ? {
64+ bootc_mount:: mount ( & esp_part, & root_path. join ( & efi_path) ) ?;
65+ tracing:: debug!( "Mounted {esp_part} at /boot/efi" ) ;
66+ }
67+ Ok ( ( ) )
68+ }
69+
3370/// Determine if the invoking environment contains bootupd, and if there are bootupd-based
3471/// updates in the target root.
3572#[ context( "Querying for bootupd" ) ]
0 commit comments