@@ -1633,47 +1633,49 @@ fn find_vmlinuz_initrd_duplicates(digest: &str) -> Result<Option<String>> {
16331633 Ok ( symlink_to)
16341634}
16351635
1636- #[ context( "Writing BLS entries to disk" ) ]
1637- fn write_bls_boot_entries_to_disk (
1638- boot_dir : & Utf8PathBuf ,
1636+ /// Write vmlinuz and initrd to the rootfs boot directory
1637+ #[ context( "Writing vmlinuz/initrd to rootfs" ) ]
1638+ fn write_vmlinuz_initrd_to_rootfs (
1639+ rootfs_boot_dir : & Utf8PathBuf ,
16391640 deployment_id : & Sha256HashValue ,
16401641 entry : & UsrLibModulesVmlinuz < Sha256HashValue > ,
16411642 repo : & ComposefsRepository < Sha256HashValue > ,
16421643) -> Result < ( ) > {
16431644 let id_hex = deployment_id. to_hex ( ) ;
1644-
1645- // Write the initrd and vmlinuz at /boot/<id>/
1646- let path = boot_dir. join ( & id_hex) ;
1645+ let path = rootfs_boot_dir. join ( & id_hex) ;
16471646 create_dir_all ( & path) ?;
1648-
1649- let entries_dir = cap_std:: fs:: Dir :: open_ambient_dir ( & path, cap_std:: ambient_authority ( ) )
1647+ let dir = cap_std:: fs:: Dir :: open_ambient_dir ( & path, cap_std:: ambient_authority ( ) )
16501648 . with_context ( || format ! ( "Opening {path}" ) ) ?;
1651-
1652- entries_dir
1653- . atomic_write (
1654- "vmlinuz" ,
1655- read_file ( & entry. vmlinuz , & repo) . context ( "Reading vmlinuz" ) ?,
1656- )
1657- . context ( "Writing vmlinuz to path" ) ?;
1658-
1649+ dir. atomic_write (
1650+ "vmlinuz" ,
1651+ read_file ( & entry. vmlinuz , & repo) . context ( "Reading vmlinuz" ) ?,
1652+ ) . context ( "Writing vmlinuz to rootfs" ) ?;
16591653 let Some ( initramfs) = & entry. initramfs else {
16601654 anyhow:: bail!( "initramfs not found" ) ;
16611655 } ;
1656+ dir. atomic_write (
1657+ "initrd" ,
1658+ read_file ( initramfs, & repo) . context ( "Reading initrd" ) ?,
1659+ ) . context ( "Writing initrd to rootfs" ) ?;
1660+ let owned_fd = dir. reopen_as_ownedfd ( ) . context ( "Reopen as owned fd" ) ?;
1661+ rustix:: fs:: fsync ( owned_fd) . context ( "fsync rootfs boot dir" ) ?;
1662+ Ok ( ( ) )
1663+ }
16621664
1663- entries_dir
1664- . atomic_write (
1665- "initrd" ,
1666- read_file ( initramfs , & repo ) . context ( "Reading initrd" ) ? ,
1667- )
1668- . context ( "Writing initrd to path" ) ? ;
1669-
1670- // Can't call fsync on O_PATH fds, so re-open it as a non O_PATH fd
1671- let owned_fd = entries_dir
1672- . reopen_as_ownedfd ( )
1673- . context ( "Reopen as owned fd" ) ? ;
1674-
1675- rustix :: fs :: fsync ( owned_fd) . context ( "fsync " ) ?;
1676-
1665+ /// Write BLS entry to ESP, referencing vmlinuz/initrd in rootfs
1666+ # [ context ( "Writing BLS entry to ESP" ) ]
1667+ fn write_bls_entry_to_esp (
1668+ esp_dir : & Utf8PathBuf ,
1669+ bls_config : & BLSConfig ,
1670+ ) -> Result < ( ) > {
1671+ let entries_dir = cap_std :: fs :: Dir :: open_ambient_dir ( esp_dir , cap_std :: ambient_authority ( ) )
1672+ . with_context ( || format ! ( "Opening {esp_dir}" ) ) ? ;
1673+ entries_dir. atomic_write (
1674+ format ! ( "bootc-composefs-{}.conf" , bls_config . sort_key . as_ref ( ) . unwrap ( ) ) ,
1675+ bls_config . to_string ( ) . as_bytes ( ) ,
1676+ ) ? ;
1677+ let owned_fd = entries_dir . reopen_as_ownedfd ( ) . context ( "Reopen as owned fd " ) ?;
1678+ rustix :: fs :: fsync ( owned_fd ) . context ( "fsync ESP dir" ) ? ;
16771679 Ok ( ( ) )
16781680}
16791681
@@ -1768,18 +1770,24 @@ pub(crate) fn setup_composefs_bls_boot(
17681770 bls_config. title = Some ( id_hex. clone ( ) ) ;
17691771 bls_config. sort_key = Some ( "1" . into ( ) ) ;
17701772 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" ) ] ;
1773+ bls_config. linux = format ! ( "/boot /{id_hex}/vmlinuz" ) ;
1774+ bls_config. initrd = vec ! [ format!( "/boot /{id_hex}/initrd" ) ] ;
17731775 bls_config. options = Some ( cmdline_refs) ;
17741776 bls_config. extra = HashMap :: new ( ) ;
17751777
17761778 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" ) ] ;
1779+ bls_config. linux = format ! ( "/boot /{symlink_to}/vmlinuz" ) ;
1780+ bls_config. initrd = vec ! [ format!( "/boot /{symlink_to}/initrd" ) ] ;
17791781 } 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) ?;
1782+ // Write vmlinuz/initrd to rootfs boot dir
1783+ let rootfs_boot_dir = root_path. join ( "boot" ) ;
1784+ write_vmlinuz_initrd_to_rootfs ( & rootfs_boot_dir, id, usr_lib_modules_vmlinuz, & repo) ?;
1785+ // Write BLS entry to ESP/loader/entries
1786+ let loader_entries_dir = mounted_esp. join ( "loader/entries" ) ;
1787+ create_dir_all ( & loader_entries_dir) . context ( "Creating loader/entries in ESP" ) ?;
1788+ let loader_entries_dir_utf8 = Utf8PathBuf :: from_path_buf ( loader_entries_dir)
1789+ . map_err ( |_| anyhow:: anyhow!( "loader/entries dir is not valid UTF-8" ) ) ?;
1790+ write_bls_entry_to_esp ( & loader_entries_dir_utf8, & bls_config) ?;
17831791 }
17841792
17851793 ( bls_config, boot_digest)
0 commit comments