@@ -98,6 +98,8 @@ use bootc_mount::{inspect_filesystem, Filesystem};
9898
9999/// The toplevel boot directory
100100const BOOT : & str = "boot" ;
101+ /// The EFI Linux directory
102+ const EFI_LINUX : & str = "EFI/Linux" ;
101103/// Directory for transient runtime state
102104#[ cfg( feature = "install-to-disk" ) ]
103105const RUN_BOOTC : & str = "/run/bootc" ;
@@ -1691,7 +1693,7 @@ pub(crate) fn setup_composefs_bls_boot(
16911693) -> Result < String > {
16921694 let id_hex = id. to_hex ( ) ;
16931695
1694- let ( root_path , esp_device, cmdline_refs) = match setup_type {
1696+ let ( esp_device, cmdline_refs) = match setup_type {
16951697 BootSetupType :: Setup ( ( root_setup, state) ) => {
16961698 // root_setup.kargs has [root=UUID=<UUID>, "rw"]
16971699 let mut cmdline_options = String :: from ( root_setup. kargs . join ( " " ) ) ;
@@ -1713,11 +1715,7 @@ pub(crate) fn setup_composefs_bls_boot(
17131715 . find ( |p| p. parttype . as_str ( ) == ESP_GUID )
17141716 . ok_or_else ( || anyhow:: anyhow!( "ESP partition not found" ) ) ?;
17151717
1716- (
1717- root_setup. physical_root_path . clone ( ) ,
1718- esp_part. node . clone ( ) ,
1719- cmdline_options,
1720- )
1718+ ( esp_part. node . clone ( ) , cmdline_options)
17211719 }
17221720
17231721 BootSetupType :: Upgrade => {
@@ -1731,7 +1729,6 @@ pub(crate) fn setup_composefs_bls_boot(
17311729 } ;
17321730
17331731 (
1734- sysroot,
17351732 get_esp_partition ( & parent) ?. 0 ,
17361733 vec ! [
17371734 format!( "root=UUID={DPS_UUID}" ) ,
@@ -1743,18 +1740,20 @@ pub(crate) fn setup_composefs_bls_boot(
17431740 }
17441741 } ;
17451742
1746- let mounted_esp: PathBuf = root_path. join ( "esp" ) . into ( ) ;
1747- let esp_mount_point_existed = mounted_esp. exists ( ) ;
1748-
1749- create_dir_all ( & mounted_esp) . context ( "Failed to create dir {mounted_esp:?}" ) ?;
1743+ let temp_efi_dir = tempfile:: tempdir ( )
1744+ . map_err ( |e| anyhow:: anyhow!( "Failed to create temporary directory for EFI mount: {e}" ) ) ?;
1745+ let mounted_efi = temp_efi_dir. path ( ) . to_path_buf ( ) ;
17501746
1751- Task :: new ( "Mounting ESP" , "mount" )
1752- . args ( [ & PathBuf :: from ( & esp_device) , & mounted_esp. clone ( ) ] )
1753- . run ( ) ?;
1747+ Command :: new ( "mount" )
1748+ . args ( [ & PathBuf :: from ( & esp_device) , & mounted_efi] )
1749+ . log_debug ( )
1750+ . run_inherited_with_cmd_context ( )
1751+ . context ( "Mounting EFI" ) ?;
17541752
17551753 let is_upgrade = matches ! ( setup_type, BootSetupType :: Upgrade ) ;
17561754
1757- let efi_dir = mounted_esp. join ( format ! ( "EFI/Linux" ) ) ;
1755+ let efi_dir = Utf8PathBuf :: from_path_buf ( mounted_efi. join ( "EFI/Linux" ) )
1756+ . map_err ( |_| anyhow:: anyhow!( "EFI dir is not valid UTF-8" ) ) ?;
17581757 let ( bls_config, boot_digest) = match & entry {
17591758 ComposefsBootEntry :: Type1 ( ..) => unimplemented ! ( ) ,
17601759 ComposefsBootEntry :: Type2 ( ..) => unimplemented ! ( ) ,
@@ -1768,18 +1767,16 @@ pub(crate) fn setup_composefs_bls_boot(
17681767 bls_config. title = Some ( id_hex. clone ( ) ) ;
17691768 bls_config. sort_key = Some ( "1" . into ( ) ) ;
17701769 bls_config. machine_id = None ;
1771- bls_config. linux = format ! ( "/EFI/Linux /{id_hex}/vmlinuz" ) ;
1772- bls_config. initrd = vec ! [ format!( "/EFI/Linux /{id_hex}/initrd" ) ] ;
1770+ bls_config. linux = format ! ( "/{EFI_LINUX} /{id_hex}/vmlinuz" ) ;
1771+ bls_config. initrd = vec ! [ format!( "/{EFI_LINUX} /{id_hex}/initrd" ) ] ;
17731772 bls_config. options = Some ( cmdline_refs) ;
17741773 bls_config. extra = HashMap :: new ( ) ;
17751774
17761775 if let Some ( symlink_to) = find_vmlinuz_initrd_duplicates ( & boot_digest) ? {
1777- bls_config. linux = format ! ( "/EFI/Linux /{symlink_to}/vmlinuz" ) ;
1778- bls_config. initrd = vec ! [ format!( "/EFI/Linux /{symlink_to}/initrd" ) ] ;
1776+ bls_config. linux = format ! ( "/{EFI_LINUX} /{symlink_to}/vmlinuz" ) ;
1777+ bls_config. initrd = vec ! [ format!( "/{EFI_LINUX} /{symlink_to}/initrd" ) ] ;
17791778 } else {
1780- let efi_dir_utf8 = Utf8PathBuf :: from_path_buf ( efi_dir. clone ( ) )
1781- . map_err ( |_| anyhow:: anyhow!( "EFI dir is not valid UTF-8" ) ) ?;
1782- write_bls_boot_entries_to_disk ( & efi_dir_utf8, id, usr_lib_modules_vmlinuz, & repo) ?;
1779+ write_bls_boot_entries_to_disk ( & efi_dir, id, usr_lib_modules_vmlinuz, & repo) ?;
17831780 }
17841781
17851782 ( bls_config, boot_digest)
@@ -1792,12 +1789,12 @@ pub(crate) fn setup_composefs_bls_boot(
17921789
17931790 // This will be atomically renamed to 'loader/entries' on shutdown/reboot
17941791 (
1795- mounted_esp . join ( format ! ( "loader/{STAGED_BOOT_LOADER_ENTRIES}" ) ) ,
1792+ mounted_efi . join ( format ! ( "loader/{STAGED_BOOT_LOADER_ENTRIES}" ) ) ,
17961793 Some ( booted_bls) ,
17971794 )
17981795 } else {
17991796 (
1800- mounted_esp . join ( format ! ( "loader/{BOOT_LOADER_ENTRIES}" ) ) ,
1797+ mounted_efi . join ( format ! ( "loader/{BOOT_LOADER_ENTRIES}" ) ) ,
18011798 None ,
18021799 )
18031800 } ;
@@ -1836,16 +1833,11 @@ pub(crate) fn setup_composefs_bls_boot(
18361833 rustix:: fs:: fsync ( owned_loader_entries_fd) . context ( "fsync" ) ?;
18371834 }
18381835
1839- Task :: new ( "Unmounting ESP" , "umount" )
1840- . arg ( & mounted_esp)
1841- . run ( ) ?;
1842-
1843- if !esp_mount_point_existed {
1844- // This shouldn't be a fatal error
1845- if let Err ( e) = std:: fs:: remove_dir ( & mounted_esp) {
1846- tracing:: error!( "Failed to remove mount point '{mounted_esp:?}': {e}" ) ;
1847- }
1848- }
1836+ Command :: new ( "umount" )
1837+ . arg ( & mounted_efi)
1838+ . log_debug ( )
1839+ . run_inherited_with_cmd_context ( )
1840+ . context ( "Unmounting EFI" ) ?;
18491841
18501842 Ok ( boot_digest)
18511843}
@@ -1920,13 +1912,12 @@ pub(crate) fn setup_composefs_uki_boot(
19201912 }
19211913 } ;
19221914
1923- let mounted_esp: PathBuf = root_path. join ( "esp" ) . into ( ) ;
1924- let esp_mount_point_existed = mounted_esp. exists ( ) ;
1925-
1926- create_dir_all ( & mounted_esp) . context ( "Failed to create dir {mounted_esp:?}" ) ?;
1915+ let temp_efi_dir = tempfile:: tempdir ( )
1916+ . map_err ( |e| anyhow:: anyhow!( "Failed to create temporary directory for EFI mount: {e}" ) ) ?;
1917+ let mounted_efi = temp_efi_dir. path ( ) . to_path_buf ( ) ;
19271918
19281919 Task :: new ( "Mounting ESP" , "mount" )
1929- . args ( [ & PathBuf :: from ( & esp_device) , & mounted_esp . clone ( ) ] )
1920+ . args ( [ & PathBuf :: from ( & esp_device) , & mounted_efi . clone ( ) ] )
19301921 . run ( ) ?;
19311922
19321923 let boot_label = match entry {
@@ -1968,7 +1959,7 @@ pub(crate) fn setup_composefs_uki_boot(
19681959 }
19691960
19701961 // Write the UKI to ESP
1971- let efi_linux_path = mounted_esp . join ( "EFI/Linux" ) ;
1962+ let efi_linux_path = mounted_efi . join ( EFI_LINUX ) ;
19721963 create_dir_all ( & efi_linux_path) . context ( "Creating EFI/Linux" ) ?;
19731964
19741965 let efi_linux =
@@ -1990,16 +1981,11 @@ pub(crate) fn setup_composefs_uki_boot(
19901981 }
19911982 } ;
19921983
1993- Task :: new ( "Unmounting ESP" , "umount" )
1994- . arg ( & mounted_esp)
1995- . run ( ) ?;
1996-
1997- if !esp_mount_point_existed {
1998- // This shouldn't be a fatal error
1999- if let Err ( e) = std:: fs:: remove_dir ( & mounted_esp) {
2000- tracing:: error!( "Failed to remove mount point '{mounted_esp:?}': {e}" ) ;
2001- }
2002- }
1984+ Command :: new ( "umount" )
1985+ . arg ( & mounted_efi)
1986+ . log_debug ( )
1987+ . run_inherited_with_cmd_context ( )
1988+ . context ( "Unmounting ESP" ) ?;
20031989
20041990 let boot_dir = root_path. join ( "boot" ) ;
20051991 create_dir_all ( & boot_dir) . context ( "Failed to create boot dir" ) ?;
0 commit comments