From 3cb315d6e9b4f2168927bded8b326b55c92f0e84 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Sat, 4 Jan 2025 23:33:50 +0000 Subject: [PATCH] blsforme: Respect sysroot when loading kernel specific cmdline This ensures nvidia parameters are still added. Signed-off-by: Ikey Doherty --- blsforme/src/bootloader/systemd_boot/mod.rs | 6 +---- blsforme/src/entry.rs | 17 ++++++++++++++ blsforme/src/kernel.rs | 26 +-------------------- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/blsforme/src/bootloader/systemd_boot/mod.rs b/blsforme/src/bootloader/systemd_boot/mod.rs index 65ed5a8..2481fc4 100644 --- a/blsforme/src/bootloader/systemd_boot/mod.rs +++ b/blsforme/src/bootloader/systemd_boot/mod.rs @@ -120,16 +120,12 @@ impl<'a, 'b> Loader<'a, 'b> { .filter(|c| !exclusions.contains(&c.name)) .map(|c| c.snippet.clone()) .collect::>(); - let mut full_cmdline = base_cmdline + let full_cmdline = base_cmdline .iter() .chain(entry_cmdline.iter()) .cloned() .collect::>(); - // kernel specific cmdline - if let Some(k_cmdline) = entry.kernel.cmdline.as_ref() { - full_cmdline.push(k_cmdline.clone()); - } let installed = self.install(&full_cmdline.join(" "), entry)?; installed_entries.push(installed); } diff --git a/blsforme/src/entry.rs b/blsforme/src/entry.rs index b096f1d..fb0d74e 100644 --- a/blsforme/src/entry.rs +++ b/blsforme/src/entry.rs @@ -44,6 +44,23 @@ impl<'a> Entry<'a> { /// Load cmdline snippets from the system root for this entry's sysroot pub fn load_cmdline_snippets(&mut self, config: &Configuration) -> Result<(), super::Error> { let sysroot = self.sysroot.clone().unwrap_or(config.root.path().into()); + + // Load local cmdline snippets for this kernel entry + for snippet in self + .kernel + .extras + .iter() + .filter(|e| matches!(e.kind, crate::AuxiliaryKind::Cmdline)) + { + if let Ok(cmdline) = cmdline_snippet(sysroot.join(&snippet.path)) { + self.cmdline.push(CmdlineEntry { + name: snippet.path.file_name().unwrap().to_string_lossy().to_string(), + snippet: cmdline, + }); + } + } + + // Globals let cmdline_d = sysroot.join("usr").join("lib").join("kernel").join("cmdline.d"); if !cmdline_d.exists() { diff --git a/blsforme/src/kernel.rs b/blsforme/src/kernel.rs index fdb1748..adbd105 100644 --- a/blsforme/src/kernel.rs +++ b/blsforme/src/kernel.rs @@ -11,7 +11,7 @@ use std::{ use serde::Deserialize; -use crate::{file_utils::cmdline_snippet, os_release::OsRelease, Error}; +use crate::{os_release::OsRelease, Error}; /// Control kernel discovery mechanism #[derive(Debug)] @@ -70,8 +70,6 @@ pub struct Kernel { /// Recorded variant type pub variant: Option, - - pub cmdline: Option, } /// Denotes the kind of auxiliary file @@ -119,24 +117,6 @@ impl Schema<'_> { } } - fn load_cmdline(kernel: &Kernel) -> Result { - // Load local cmdline snippets for this kernel entry - let mut cmdline = String::new(); - for snippet in kernel - .extras - .iter() - .filter(|e| matches!(e.kind, crate::AuxiliaryKind::Cmdline)) - { - let snippet = cmdline_snippet(&snippet.path)?; - cmdline.push_str(&snippet); - cmdline.push(' '); - } - - log::trace!("kernel-specific cmdline for {:?}: {cmdline}", kernel.image); - - Ok(cmdline.trim().to_string()) - } - /// Discover any legacy kernels fn legacy_kernels( namespace: &'static str, @@ -171,7 +151,6 @@ impl Schema<'_> { initrd: vec![], extras: vec![], variant: Some(variant.to_string()), - cmdline: None, }, ); } @@ -266,7 +245,6 @@ impl Schema<'_> { kernel .extras .sort_by_key(|e| e.path.display().to_string().to_lowercase()); - kernel.cmdline = Self::load_cmdline(kernel).ok().filter(|s| !s.is_empty()); } Ok(kernels.into_values().collect::>()) } @@ -289,7 +267,6 @@ impl Schema<'_> { initrd: vec![], extras: vec![], variant: None, - cmdline: None, }, )) }) @@ -350,7 +327,6 @@ impl Schema<'_> { kernel .extras .sort_by_key(|e| e.path.display().to_string().to_lowercase()); - kernel.cmdline = Self::load_cmdline(kernel).ok().filter(|s| !s.is_empty()); } }