Skip to content

Commit 554c621

Browse files
authored
Merge pull request #1193 from omertuc/nocleanostree
install: Do not clean boot directories on ostree systems
2 parents 772c134 + c737dfd commit 554c621

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

lib/src/install.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,21 +1596,31 @@ fn remove_all_in_dir_no_xdev(d: &Dir, mount_err: bool) -> Result<()> {
15961596
}
15971597

15981598
#[context("Removing boot directory content")]
1599-
fn clean_boot_directories(rootfs: &Dir) -> Result<()> {
1599+
fn clean_boot_directories(rootfs: &Dir, is_ostree: bool) -> Result<()> {
16001600
let bootdir =
16011601
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+
}
16121621
}
16131622
}
1623+
16141624
Ok(())
16151625
}
16161626

@@ -1731,7 +1741,8 @@ pub(crate) async fn install_to_filesystem(
17311741
// the deployment root.
17321742
let possible_physical_root = fsopts.root_path.join("sysroot");
17331743
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 {
17351746
tracing::debug!(
17361747
"ostree detected in {possible_ostree_dir}, assuming target is a deployment root and using {possible_physical_root}"
17371748
);
@@ -1759,7 +1770,7 @@ pub(crate) async fn install_to_filesystem(
17591770
tokio::task::spawn_blocking(move || remove_all_in_dir_no_xdev(&rootfs_fd, true))
17601771
.await??;
17611772
}
1762-
Some(ReplaceMode::Alongside) => clean_boot_directories(&rootfs_fd)?,
1773+
Some(ReplaceMode::Alongside) => clean_boot_directories(&rootfs_fd, is_already_ostree)?,
17631774
None => require_empty_rootdir(&rootfs_fd)?,
17641775
}
17651776

0 commit comments

Comments
 (0)