@@ -98,6 +98,8 @@ use bootc_mount::{inspect_filesystem, Filesystem};
98
98
99
99
/// The toplevel boot directory
100
100
const BOOT : & str = "boot" ;
101
+ /// The EFI Linux directory
102
+ const EFI_LINUX : & str = "EFI/Linux" ;
101
103
/// Directory for transient runtime state
102
104
#[ cfg( feature = "install-to-disk" ) ]
103
105
const RUN_BOOTC : & str = "/run/bootc" ;
@@ -1691,7 +1693,7 @@ pub(crate) fn setup_composefs_bls_boot(
1691
1693
) -> Result < String > {
1692
1694
let id_hex = id. to_hex ( ) ;
1693
1695
1694
- let ( root_path , esp_device, cmdline_refs) = match setup_type {
1696
+ let ( esp_device, cmdline_refs) = match setup_type {
1695
1697
BootSetupType :: Setup ( ( root_setup, state) ) => {
1696
1698
// root_setup.kargs has [root=UUID=<UUID>, "rw"]
1697
1699
let mut cmdline_options = String :: from ( root_setup. kargs . join ( " " ) ) ;
@@ -1713,11 +1715,7 @@ pub(crate) fn setup_composefs_bls_boot(
1713
1715
. find ( |p| p. parttype . as_str ( ) == ESP_GUID )
1714
1716
. ok_or_else ( || anyhow:: anyhow!( "ESP partition not found" ) ) ?;
1715
1717
1716
- (
1717
- root_setup. physical_root_path . clone ( ) ,
1718
- esp_part. node . clone ( ) ,
1719
- cmdline_options,
1720
- )
1718
+ ( esp_part. node . clone ( ) , cmdline_options)
1721
1719
}
1722
1720
1723
1721
BootSetupType :: Upgrade => {
@@ -1731,7 +1729,6 @@ pub(crate) fn setup_composefs_bls_boot(
1731
1729
} ;
1732
1730
1733
1731
(
1734
- sysroot,
1735
1732
get_esp_partition ( & parent) ?. 0 ,
1736
1733
vec ! [
1737
1734
format!( "root=UUID={DPS_UUID}" ) ,
@@ -1743,18 +1740,20 @@ pub(crate) fn setup_composefs_bls_boot(
1743
1740
}
1744
1741
} ;
1745
1742
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 ( ) ;
1750
1746
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" ) ?;
1754
1752
1755
1753
let is_upgrade = matches ! ( setup_type, BootSetupType :: Upgrade ) ;
1756
1754
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" ) ) ?;
1758
1757
let ( bls_config, boot_digest) = match & entry {
1759
1758
ComposefsBootEntry :: Type1 ( ..) => unimplemented ! ( ) ,
1760
1759
ComposefsBootEntry :: Type2 ( ..) => unimplemented ! ( ) ,
@@ -1768,18 +1767,16 @@ pub(crate) fn setup_composefs_bls_boot(
1768
1767
bls_config. title = Some ( id_hex. clone ( ) ) ;
1769
1768
bls_config. sort_key = Some ( "1" . into ( ) ) ;
1770
1769
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" ) ] ;
1773
1772
bls_config. options = Some ( cmdline_refs) ;
1774
1773
bls_config. extra = HashMap :: new ( ) ;
1775
1774
1776
1775
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" ) ] ;
1779
1778
} 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) ?;
1783
1780
}
1784
1781
1785
1782
( bls_config, boot_digest)
@@ -1792,12 +1789,12 @@ pub(crate) fn setup_composefs_bls_boot(
1792
1789
1793
1790
// This will be atomically renamed to 'loader/entries' on shutdown/reboot
1794
1791
(
1795
- mounted_esp . join ( format ! ( "loader/{STAGED_BOOT_LOADER_ENTRIES}" ) ) ,
1792
+ mounted_efi . join ( format ! ( "loader/{STAGED_BOOT_LOADER_ENTRIES}" ) ) ,
1796
1793
Some ( booted_bls) ,
1797
1794
)
1798
1795
} else {
1799
1796
(
1800
- mounted_esp . join ( format ! ( "loader/{BOOT_LOADER_ENTRIES}" ) ) ,
1797
+ mounted_efi . join ( format ! ( "loader/{BOOT_LOADER_ENTRIES}" ) ) ,
1801
1798
None ,
1802
1799
)
1803
1800
} ;
@@ -1836,16 +1833,11 @@ pub(crate) fn setup_composefs_bls_boot(
1836
1833
rustix:: fs:: fsync ( owned_loader_entries_fd) . context ( "fsync" ) ?;
1837
1834
}
1838
1835
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" ) ?;
1849
1841
1850
1842
Ok ( boot_digest)
1851
1843
}
@@ -1920,13 +1912,12 @@ pub(crate) fn setup_composefs_uki_boot(
1920
1912
}
1921
1913
} ;
1922
1914
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 ( ) ;
1927
1918
1928
1919
Task :: new ( "Mounting ESP" , "mount" )
1929
- . args ( [ & PathBuf :: from ( & esp_device) , & mounted_esp . clone ( ) ] )
1920
+ . args ( [ & PathBuf :: from ( & esp_device) , & mounted_efi . clone ( ) ] )
1930
1921
. run ( ) ?;
1931
1922
1932
1923
let boot_label = match entry {
@@ -1968,7 +1959,7 @@ pub(crate) fn setup_composefs_uki_boot(
1968
1959
}
1969
1960
1970
1961
// 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 ) ;
1972
1963
create_dir_all ( & efi_linux_path) . context ( "Creating EFI/Linux" ) ?;
1973
1964
1974
1965
let efi_linux =
@@ -1990,16 +1981,11 @@ pub(crate) fn setup_composefs_uki_boot(
1990
1981
}
1991
1982
} ;
1992
1983
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" ) ?;
2003
1989
2004
1990
let boot_dir = root_path. join ( "boot" ) ;
2005
1991
create_dir_all ( & boot_dir) . context ( "Failed to create boot dir" ) ?;
0 commit comments