Skip to content

Commit 586b538

Browse files
committed
install: Do not clean boot directories on ostree systems
On ostree systems, the boot directory already has our desired format, we should only remove the bootupd-state.json file to avoid bootupctl complaining about it already existing. The motivation is that this will preserve the boot entry for the original deployment, allowing the user to boot into it if they want to. This also makes sure `ostree admin status` continues working - since if we're in a booted ostree system but `ostree` can't find its physically (through boot entries) it complains.
1 parent f9790e6 commit 586b538

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

lib/src/install.rs

+28-17
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<()> {
1600-
// let bootdir =
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)?;
1612-
// }
1613-
// }
1599+
fn clean_boot_directories(rootfs: &Dir, is_ostree: bool) -> Result<()> {
1600+
let bootdir =
1601+
crate::utils::open_dir_remount_rw(rootfs, BOOT.into()).context("Opening /boot")?;
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+
}
1621+
}
1622+
}
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)