Skip to content

Commit 7d276a2

Browse files
committed
install: Detect aboot images and enable the correct bootloader
Aboot images need to have the ostree bootloader backend set to "aboot", otherwise the deploy during bootc install will not create the correct boot A/B symlinks, and additionally once booted will not correctly deploy to the aboot partition during an update. To see whethere an image is using aboot, we look for the "aboot.img" file in the kernel modules dir. NOTE: In order to correctly handle running bootc from a different container than the to-be-installed container we look for aboot.img in the actual commit, not just in the running container.
1 parent 6d2eb2a commit 7d276a2

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

crates/lib/src/install.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,25 @@ async fn install_container(
779779
)?;
780780
let kargsd = kargsd.iter().map(|s| s.as_str());
781781

782+
// If the target uses aboot, then we need to set that bootloader in the ostree
783+
// config before deploying the commit
784+
if ostree_ext::bootabletree::commit_has_aboot_img(&merged_ostree_root, None)? {
785+
tracing::debug!("Setting bootloader to aboot");
786+
Command::new("ostree")
787+
.args([
788+
"config",
789+
"--repo",
790+
"ostree/repo",
791+
"set",
792+
"sysroot.bootloader",
793+
"aboot",
794+
])
795+
.cwd_dir(root_setup.physical_root.try_clone()?)
796+
.run_capture_stderr()
797+
.context("Setting bootloader config to aboot")?;
798+
sysroot.repo().reload_config(None::<&gio::Cancellable>)?;
799+
}
800+
782801
// Keep this in sync with install/completion.rs for the Anaconda fixups
783802
let install_config_kargs = state
784803
.install_config

crates/ostree-ext/src/bootabletree.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use ostree::prelude::*;
1212

1313
const MODULES: &str = "usr/lib/modules";
1414
const VMLINUZ: &str = "vmlinuz";
15+
const ABOOT_IMG: &str = "aboot.img";
1516

1617
/// Find the kernel modules directory in a bootable OSTree commit.
1718
/// The target directory will have a `vmlinuz` file representing the kernel binary.
@@ -88,6 +89,20 @@ pub fn find_kernel_dir_fs(root: &Dir) -> Result<Option<Utf8PathBuf>> {
8889
Ok(r)
8990
}
9091

92+
/// Check if there is an aboot image in the kernel tree dir
93+
pub fn commit_has_aboot_img(
94+
root: &gio::File,
95+
cancellable: Option<&gio::Cancellable>,
96+
) -> Result<bool> {
97+
if let Some(kernel_dir) = find_kernel_dir(root, cancellable)? {
98+
Ok(kernel_dir
99+
.resolve_relative_path(ABOOT_IMG)
100+
.query_exists(cancellable))
101+
} else {
102+
Ok(false)
103+
}
104+
}
105+
91106
#[cfg(test)]
92107
mod test {
93108
use super::*;

0 commit comments

Comments
 (0)