Skip to content

Commit 662cdee

Browse files
authored
Merge pull request #1532 from alexlarsson/aboot-support
install: Automatically configure aboot
2 parents 2cb3ef2 + 7d276a2 commit 662cdee

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

crates/lib/src/install.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::io::Write;
1919
use std::os::fd::{AsFd, AsRawFd};
2020
use std::os::unix::process::CommandExt;
2121
use std::path::Path;
22+
use std::process;
2223
use std::process::Command;
2324
use std::str::FromStr;
2425
use std::sync::Arc;
@@ -624,7 +625,11 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result
624625
}
625626

626627
let sysroot = {
627-
let path = format!("/proc/self/fd/{}", rootfs_dir.as_fd().as_raw_fd());
628+
let path = format!(
629+
"/proc/{}/fd/{}",
630+
process::id(),
631+
rootfs_dir.as_fd().as_raw_fd()
632+
);
628633
ostree::Sysroot::new(Some(&gio::File::for_path(path)))
629634
};
630635
sysroot.load(cancellable)?;
@@ -774,6 +779,25 @@ async fn install_container(
774779
)?;
775780
let kargsd = kargsd.iter().map(|s| s.as_str());
776781

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+
777801
// Keep this in sync with install/completion.rs for the Anaconda fixups
778802
let install_config_kargs = state
779803
.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)