11use std:: fs:: create_dir_all;
22use std:: io:: Write ;
3- use std:: process :: Command ;
3+ use std:: path :: Path ;
44use std:: { ffi:: OsStr , path:: PathBuf } ;
55
66use anyhow:: { anyhow, Context , Result } ;
77use bootc_blockdev:: find_parent_devices;
88use bootc_mount:: inspect_filesystem;
9- use bootc_utils :: CommandRunExt ;
9+ use bootc_mount :: tempmount :: TempMount ;
1010use camino:: { Utf8Path , Utf8PathBuf } ;
1111use cap_std_ext:: {
1212 cap_std:: { ambient_authority, fs:: Dir } ,
@@ -272,8 +272,6 @@ struct BLSEntryPath<'a> {
272272 abs_entries_path : & ' a str ,
273273 /// Where to write the .conf files
274274 config_path : Utf8PathBuf ,
275- /// If we mounted EFI, the target path
276- mount_path : Option < Utf8PathBuf > ,
277275}
278276
279277/// Sets up and writes BLS entries and binaries (VMLinuz + Initrd) to disk
@@ -352,35 +350,23 @@ pub(crate) fn setup_composefs_bls_boot(
352350 entries_path : root_path. join ( "boot" ) ,
353351 config_path : root_path. join ( "boot" ) ,
354352 abs_entries_path : "boot" ,
355- mount_path : None ,
356353 } ,
357354 None ,
358355 ) ,
359356
360357 Bootloader :: Systemd => {
361- let temp_efi_dir = tempfile:: tempdir ( ) . map_err ( |e| {
362- anyhow:: anyhow!( "Failed to create temporary directory for EFI mount: {e}" )
363- } ) ?;
364-
365- let mounted_efi = Utf8PathBuf :: from_path_buf ( temp_efi_dir. path ( ) . to_path_buf ( ) )
366- . map_err ( |_| anyhow:: anyhow!( "EFI dir is not valid UTF-8" ) ) ?;
367-
368- Command :: new ( "mount" )
369- . args ( [ & PathBuf :: from ( & esp_device) , mounted_efi. as_std_path ( ) ] )
370- . log_debug ( )
371- . run_inherited_with_cmd_context ( )
372- . context ( "Mounting EFI" ) ?;
358+ let efi_mount = TempMount :: mount_dev ( & esp_device) . context ( "Mounting ESP" ) ?;
373359
360+ let mounted_efi = Utf8PathBuf :: from ( efi_mount. dir . path ( ) . as_str ( ) ?) ;
374361 let efi_linux_dir = mounted_efi. join ( EFI_LINUX ) ;
375362
376363 (
377364 BLSEntryPath {
378365 entries_path : efi_linux_dir,
379366 config_path : mounted_efi. clone ( ) ,
380367 abs_entries_path : EFI_LINUX ,
381- mount_path : Some ( mounted_efi) ,
382368 } ,
383- Some ( temp_efi_dir ) ,
369+ Some ( efi_mount ) ,
384370 )
385371 }
386372 } ;
@@ -518,14 +504,6 @@ pub(crate) fn setup_composefs_bls_boot(
518504 rustix:: fs:: fsync ( owned_loader_entries_fd) . context ( "fsync" ) ?;
519505 }
520506
521- if let Some ( mounted_efi) = entry_paths. mount_path {
522- Command :: new ( "umount" )
523- . arg ( mounted_efi)
524- . log_debug ( )
525- . run_inherited_with_cmd_context ( )
526- . context ( "Unmounting EFI" ) ?;
527- }
528-
529507 Ok ( boot_digest)
530508}
531509
@@ -537,7 +515,7 @@ fn write_pe_to_esp(
537515 pe_type : PEType ,
538516 uki_id : & String ,
539517 is_insecure_from_opts : bool ,
540- mounted_efi : & PathBuf ,
518+ mounted_efi : impl AsRef < Path > ,
541519) -> Result < Option < String > > {
542520 let efi_bin = read_file ( file, & repo) . context ( "Reading .efi binary" ) ?;
543521
@@ -574,7 +552,7 @@ fn write_pe_to_esp(
574552 }
575553
576554 // Write the UKI to ESP
577- let efi_linux_path = mounted_efi. join ( EFI_LINUX ) ;
555+ let efi_linux_path = mounted_efi. as_ref ( ) . join ( EFI_LINUX ) ;
578556 create_dir_all ( & efi_linux_path) . context ( "Creating EFI/Linux" ) ?;
579557
580558 let final_pe_path = match file_path. parent ( ) {
@@ -768,13 +746,7 @@ pub(crate) fn setup_composefs_uki_boot(
768746 }
769747 } ;
770748
771- let temp_efi_dir = tempfile:: tempdir ( )
772- . map_err ( |e| anyhow:: anyhow!( "Failed to create temporary directory for EFI mount: {e}" ) ) ?;
773- let mounted_efi = temp_efi_dir. path ( ) . to_path_buf ( ) ;
774-
775- Task :: new ( "Mounting ESP" , "mount" )
776- . args ( [ & PathBuf :: from ( & esp_device) , & mounted_efi. clone ( ) ] )
777- . run ( ) ?;
749+ let esp_mount = TempMount :: mount_dev ( & esp_device) . context ( "Mounting ESP" ) ?;
778750
779751 let mut boot_label = String :: new ( ) ;
780752
@@ -793,7 +765,7 @@ pub(crate) fn setup_composefs_uki_boot(
793765 entry. pe_type ,
794766 & id. to_hex ( ) ,
795767 is_insecure_from_opts,
796- & mounted_efi ,
768+ esp_mount . dir . path ( ) ,
797769 ) ?;
798770
799771 if let Some ( label) = ret {
@@ -803,12 +775,6 @@ pub(crate) fn setup_composefs_uki_boot(
803775 } ;
804776 }
805777
806- Command :: new ( "umount" )
807- . arg ( & mounted_efi)
808- . log_debug ( )
809- . run_inherited_with_cmd_context ( )
810- . context ( "Unmounting ESP" ) ?;
811-
812778 match bootloader {
813779 Bootloader :: Grub => {
814780 write_grub_uki_menuentry ( root_path, & setup_type, & boot_label, id, & esp_device) ?
0 commit comments