Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion crates/lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::io::Write;
use std::os::fd::{AsFd, AsRawFd};
use std::os::unix::process::CommandExt;
use std::path::Path;
use std::process;
use std::process::Command;
use std::str::FromStr;
use std::sync::Arc;
Expand Down Expand Up @@ -624,7 +625,11 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result
}

let sysroot = {
let path = format!("/proc/self/fd/{}", rootfs_dir.as_fd().as_raw_fd());
let path = format!(
"/proc/{}/fd/{}",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with this but I think the real fix here is that everything in ostree should be using fd-relative access.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is that the path passed to ostree here ends up in a commandline when ostree spawns aboot-deploy. I don't see how using fd-relative access inside ostree itself can fix that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how using fd-relative access inside ostree itself can fix that.

Because ostree turns the provided path into a fd which we should be using instead as the above PR does, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens currently (without this change) is that the ostree deploy code will spawn /usr/bin/aboot-deploy -r /proc/self/fd/12. And then when aboot-deploy tries to read this, /proc/self/fd/12 no longer points to the correct thing.

For sure, we could make ostree::Sysroot work with a dirfd for the root path, but it would run into the same problem when it tried to spawn aboot-deploy.

process::id(),
rootfs_dir.as_fd().as_raw_fd()
);
ostree::Sysroot::new(Some(&gio::File::for_path(path)))
};
sysroot.load(cancellable)?;
Expand Down Expand Up @@ -774,6 +779,25 @@ async fn install_container(
)?;
let kargsd = kargsd.iter().map(|s| s.as_str());

// If the target uses aboot, then we need to set that bootloader in the ostree
// config before deploying the commit
if ostree_ext::bootabletree::commit_has_aboot_img(&merged_ostree_root, None)? {
tracing::debug!("Setting bootloader to aboot");
Command::new("ostree")
.args([
"config",
"--repo",
"ostree/repo",
"set",
"sysroot.bootloader",
"aboot",
])
.cwd_dir(root_setup.physical_root.try_clone()?)
.run_capture_stderr()
.context("Setting bootloader config to aboot")?;
sysroot.repo().reload_config(None::<&gio::Cancellable>)?;
}

// Keep this in sync with install/completion.rs for the Anaconda fixups
let install_config_kargs = state
.install_config
Expand Down
15 changes: 15 additions & 0 deletions crates/ostree-ext/src/bootabletree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use ostree::prelude::*;

const MODULES: &str = "usr/lib/modules";
const VMLINUZ: &str = "vmlinuz";
const ABOOT_IMG: &str = "aboot.img";

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

/// Check if there is an aboot image in the kernel tree dir
pub fn commit_has_aboot_img(
root: &gio::File,
cancellable: Option<&gio::Cancellable>,
) -> Result<bool> {
if let Some(kernel_dir) = find_kernel_dir(root, cancellable)? {
Ok(kernel_dir
.resolve_relative_path(ABOOT_IMG)
.query_exists(cancellable))
} else {
Ok(false)
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down