@@ -1633,47 +1633,49 @@ fn find_vmlinuz_initrd_duplicates(digest: &str) -> Result<Option<String>> {
1633
1633
Ok ( symlink_to)
1634
1634
}
1635
1635
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 ,
1639
1640
deployment_id : & Sha256HashValue ,
1640
1641
entry : & UsrLibModulesVmlinuz < Sha256HashValue > ,
1641
1642
repo : & ComposefsRepository < Sha256HashValue > ,
1642
1643
) -> Result < ( ) > {
1643
1644
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) ;
1647
1646
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 ( ) )
1650
1648
. 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" ) ?;
1659
1653
let Some ( initramfs) = & entry. initramfs else {
1660
1654
anyhow:: bail!( "initramfs not found" ) ;
1661
1655
} ;
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
+ }
1662
1664
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" ) ? ;
1677
1679
Ok ( ( ) )
1678
1680
}
1679
1681
@@ -1768,18 +1770,22 @@ pub(crate) fn setup_composefs_bls_boot(
1768
1770
bls_config. title = Some ( id_hex. clone ( ) ) ;
1769
1771
bls_config. sort_key = Some ( "1" . into ( ) ) ;
1770
1772
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" ) ] ;
1773
1775
bls_config. options = Some ( cmdline_refs) ;
1774
1776
bls_config. extra = HashMap :: new ( ) ;
1775
1777
1776
1778
if let Some ( symlink_to) = find_vmlinuz_initrd_duplicates ( & boot_digest) ? {
1777
1779
bls_config. linux = format ! ( "/EFI/Linux/{symlink_to}/vmlinuz" ) ;
1778
1780
bls_config. initrd = vec ! [ format!( "/EFI/Linux/{symlink_to}/initrd" ) ] ;
1779
1781
} else {
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
1780
1786
let efi_dir_utf8 = Utf8PathBuf :: from_path_buf ( efi_dir. clone ( ) )
1781
1787
. 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 ) ?;
1788
+ write_bls_entry_to_esp ( & efi_dir_utf8, & bls_config ) ?;
1783
1789
}
1784
1790
1785
1791
( bls_config, boot_digest)
0 commit comments