-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: kernel-install integration #5097
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
//! Integration with the systemd-owned /sbin/kernel-install tooling. | ||
//! | ||
//! Note that there's two different phases of kernel handling: | ||
//! | ||
//! - build time | ||
//! - deployment time (owned by ostree) | ||
//! | ||
//! This code is wholly concerned with "build time" today. The | ||
//! "deployment time" logic is owned entirely by ostree. | ||
//! | ||
|
||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
use std::process::Command; | ||
|
||
use anyhow::{Context, Result}; | ||
use cap_std::fs::Dir; | ||
use cap_std_ext::cap_std; | ||
use cap_std_ext::dirext::CapStdExtDirExt; | ||
use fn_error_context::context; | ||
|
||
/// Parsed by kernel-install and set in the environment | ||
const LAYOUT_VAR: &str = "KERNEL_INSTALL_LAYOUT"; | ||
/// The value we expect to find for layout | ||
const LAYOUT_OSTREE: &str = "ostree"; | ||
/// What we should emit to skip further processing | ||
const SKIP: u8 = 77; | ||
/// The path to the kernel modules | ||
const MODULES: &str = "usr/lib/modules"; | ||
/// The default name for the initramfs. | ||
const INITRAMFS: &str = "initramfs.img"; | ||
|
||
#[context("Adding kernel")] | ||
fn add(root: &Dir, argv: &[&str]) -> Result<()> { | ||
let mut argv_it = argv.iter().copied(); | ||
let Some(kver) = argv_it.next() else { | ||
anyhow::bail!("No kernel version provided"); | ||
}; | ||
println!("Generating initramfs"); | ||
crate::initramfs::run_dracut(root, &kver)?; | ||
println!("Running depmod"); | ||
let st = Command::new("depmod") | ||
.args(["-a", kver]) | ||
.status() | ||
.context("Invoking depmod")?; | ||
if !st.success() { | ||
anyhow::bail!("Failed to run depmod: {st:?}"); | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[context("Removing kernel")] | ||
fn remove(root: &Dir, kver: &str) -> Result<()> { | ||
let kdir = format!("{MODULES}/{kver}"); | ||
let Some(kernel_dir) = root.open_dir_optional(&kdir)? else { | ||
return Ok(()); | ||
}; | ||
// We generate the initramfs, so remove it if it exists. | ||
kernel_dir.remove_file_optional(INITRAMFS)?; | ||
Ok(()) | ||
} | ||
|
||
/// Primary entrypoint to `/usr/lib/kernel-install.d/05-rpmostree.install`. | ||
#[context("rpm-ostree kernel-install")] | ||
pub fn main(argv: &[&str]) -> Result<u8> { | ||
let Some(layout) = std::env::var_os(LAYOUT_VAR) else { | ||
return Ok(0); | ||
}; | ||
if !matches!(layout.to_str(), Some(LAYOUT_OSTREE)) { | ||
return Ok(0); | ||
} | ||
if !ostree_ext::container_utils::is_ostree_container()? { | ||
eprintln!( | ||
"warning: confused state: {LAYOUT_VAR}={LAYOUT_OSTREE} but not in an ostree container" | ||
); | ||
return Ok(0); | ||
} | ||
let root = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?; | ||
match argv { | ||
["add", rest @ ..] => { | ||
add(root, rest)?; | ||
// In the case of adding a new kernel, we intercept everything else | ||
// today. In the future we can try to ensure we reuse what bits are there. | ||
Ok(SKIP) | ||
} | ||
["remove", kver] => { | ||
remove(root, kver)?; | ||
Ok(0) | ||
} | ||
_ => Ok(0), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error is triggered now, I am testing with this container file:
Trying to workaround that next.