1
1
use std:: fs:: create_dir_all;
2
2
use std:: io:: Write ;
3
- use std:: process :: Command ;
3
+ use std:: path :: Path ;
4
4
use std:: { ffi:: OsStr , path:: PathBuf } ;
5
5
6
6
use anyhow:: { anyhow, Context , Result } ;
7
7
use bootc_blockdev:: find_parent_devices;
8
8
use bootc_mount:: inspect_filesystem;
9
- use bootc_utils :: CommandRunExt ;
9
+ use bootc_mount :: tempmount :: TempMount ;
10
10
use camino:: { Utf8Path , Utf8PathBuf } ;
11
11
use cap_std_ext:: {
12
12
cap_std:: { ambient_authority, fs:: Dir } ,
@@ -272,8 +272,6 @@ struct BLSEntryPath<'a> {
272
272
abs_entries_path : & ' a str ,
273
273
/// Where to write the .conf files
274
274
config_path : Utf8PathBuf ,
275
- /// If we mounted EFI, the target path
276
- mount_path : Option < Utf8PathBuf > ,
277
275
}
278
276
279
277
/// Sets up and writes BLS entries and binaries (VMLinuz + Initrd) to disk
@@ -352,35 +350,23 @@ pub(crate) fn setup_composefs_bls_boot(
352
350
entries_path : root_path. join ( "boot" ) ,
353
351
config_path : root_path. join ( "boot" ) ,
354
352
abs_entries_path : "boot" ,
355
- mount_path : None ,
356
353
} ,
357
354
None ,
358
355
) ,
359
356
360
357
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" ) ?;
373
359
360
+ let mounted_efi = Utf8PathBuf :: from ( efi_mount. dir . path ( ) . as_str ( ) ?) ;
374
361
let efi_linux_dir = mounted_efi. join ( EFI_LINUX ) ;
375
362
376
363
(
377
364
BLSEntryPath {
378
365
entries_path : efi_linux_dir,
379
366
config_path : mounted_efi. clone ( ) ,
380
367
abs_entries_path : EFI_LINUX ,
381
- mount_path : Some ( mounted_efi) ,
382
368
} ,
383
- Some ( temp_efi_dir ) ,
369
+ Some ( efi_mount ) ,
384
370
)
385
371
}
386
372
} ;
@@ -518,14 +504,6 @@ pub(crate) fn setup_composefs_bls_boot(
518
504
rustix:: fs:: fsync ( owned_loader_entries_fd) . context ( "fsync" ) ?;
519
505
}
520
506
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
-
529
507
Ok ( boot_digest)
530
508
}
531
509
@@ -537,7 +515,7 @@ fn write_pe_to_esp(
537
515
pe_type : PEType ,
538
516
uki_id : & String ,
539
517
is_insecure_from_opts : bool ,
540
- mounted_efi : & PathBuf ,
518
+ mounted_efi : impl AsRef < Path > ,
541
519
) -> Result < Option < String > > {
542
520
let efi_bin = read_file ( file, & repo) . context ( "Reading .efi binary" ) ?;
543
521
@@ -574,7 +552,7 @@ fn write_pe_to_esp(
574
552
}
575
553
576
554
// 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 ) ;
578
556
create_dir_all ( & efi_linux_path) . context ( "Creating EFI/Linux" ) ?;
579
557
580
558
let final_pe_path = match file_path. parent ( ) {
@@ -768,13 +746,7 @@ pub(crate) fn setup_composefs_uki_boot(
768
746
}
769
747
} ;
770
748
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" ) ?;
778
750
779
751
let mut boot_label = String :: new ( ) ;
780
752
@@ -793,7 +765,7 @@ pub(crate) fn setup_composefs_uki_boot(
793
765
entry. pe_type ,
794
766
& id. to_hex ( ) ,
795
767
is_insecure_from_opts,
796
- & mounted_efi ,
768
+ esp_mount . dir . path ( ) ,
797
769
) ?;
798
770
799
771
if let Some ( label) = ret {
@@ -803,12 +775,6 @@ pub(crate) fn setup_composefs_uki_boot(
803
775
} ;
804
776
}
805
777
806
- Command :: new ( "umount" )
807
- . arg ( & mounted_efi)
808
- . log_debug ( )
809
- . run_inherited_with_cmd_context ( )
810
- . context ( "Unmounting ESP" ) ?;
811
-
812
778
match bootloader {
813
779
Bootloader :: Grub => {
814
780
write_grub_uki_menuentry ( root_path, & setup_type, & boot_label, id, & esp_device) ?
0 commit comments