@@ -1596,21 +1596,31 @@ fn remove_all_in_dir_no_xdev(d: &Dir, mount_err: bool) -> Result<()> {
1596
1596
}
1597
1597
1598
1598
#[ context( "Removing boot directory content" ) ]
1599
- fn clean_boot_directories ( rootfs : & Dir ) -> Result < ( ) > {
1599
+ fn clean_boot_directories ( rootfs : & Dir , is_ostree : bool ) -> Result < ( ) > {
1600
1600
let bootdir =
1601
1601
crate :: utils:: open_dir_remount_rw ( rootfs, BOOT . into ( ) ) . context ( "Opening /boot" ) ?;
1602
- // This should not remove /boot/efi note.
1603
- remove_all_in_dir_no_xdev ( & bootdir, false ) ?;
1604
- // TODO: Discover the ESP the same way bootupd does it; we should also
1605
- // support not wiping the ESP.
1606
- if ARCH_USES_EFI {
1607
- if let Some ( efidir) = bootdir
1608
- . open_dir_optional ( crate :: bootloader:: EFI_DIR )
1609
- . context ( "Opening /boot/efi" ) ?
1610
- {
1611
- remove_all_in_dir_no_xdev ( & efidir, false ) ?;
1602
+
1603
+ if is_ostree {
1604
+ // On ostree systems, the boot directory already has our desired format, we should only
1605
+ // remove the bootupd-state.json file to avoid bootupctl complaining it already exists.
1606
+ bootdir
1607
+ . remove_file_optional ( "bootupd-state.json" )
1608
+ . context ( "removing bootupd-state.json" ) ?;
1609
+ } else {
1610
+ // This should not remove /boot/efi note.
1611
+ remove_all_in_dir_no_xdev ( & bootdir, false ) ?;
1612
+ // TODO: Discover the ESP the same way bootupd does it; we should also
1613
+ // support not wiping the ESP.
1614
+ if ARCH_USES_EFI {
1615
+ if let Some ( efidir) = bootdir
1616
+ . open_dir_optional ( crate :: bootloader:: EFI_DIR )
1617
+ . context ( "Opening /boot/efi" ) ?
1618
+ {
1619
+ remove_all_in_dir_no_xdev ( & efidir, false ) ?;
1620
+ }
1612
1621
}
1613
1622
}
1623
+
1614
1624
Ok ( ( ) )
1615
1625
}
1616
1626
@@ -1731,7 +1741,8 @@ pub(crate) async fn install_to_filesystem(
1731
1741
// the deployment root.
1732
1742
let possible_physical_root = fsopts. root_path . join ( "sysroot" ) ;
1733
1743
let possible_ostree_dir = possible_physical_root. join ( "ostree" ) ;
1734
- if possible_ostree_dir. exists ( ) {
1744
+ let is_already_ostree = possible_ostree_dir. exists ( ) ;
1745
+ if is_already_ostree {
1735
1746
tracing:: debug!(
1736
1747
"ostree detected in {possible_ostree_dir}, assuming target is a deployment root and using {possible_physical_root}"
1737
1748
) ;
@@ -1759,7 +1770,7 @@ pub(crate) async fn install_to_filesystem(
1759
1770
tokio:: task:: spawn_blocking ( move || remove_all_in_dir_no_xdev ( & rootfs_fd, true ) )
1760
1771
. await ??;
1761
1772
}
1762
- Some ( ReplaceMode :: Alongside ) => clean_boot_directories ( & rootfs_fd) ?,
1773
+ Some ( ReplaceMode :: Alongside ) => clean_boot_directories ( & rootfs_fd, is_already_ostree ) ?,
1763
1774
None => require_empty_rootdir ( & rootfs_fd) ?,
1764
1775
}
1765
1776
0 commit comments