fix(autoconfigure): pair kernels with initramfs files ending in .img

Linux autoconfiguration only looked for an initramfs named with the
kernel suffix, like initrd.img-6.1 or initramfs-lts. Arch Linux
(initramfs-linux.img), and Fedora or Gentoo using dracut without BLS
(initramfs-<version>.img) add .img to the name, so their kernels were
booted without an initramfs and failed to mount the root filesystem.
Also try each candidate with .img added.
This commit is contained in:
alex authored and Alex Zenla committed 2026-09-26 20:52:15 -07:00
1 parent c54a597917
commit 9438c99c38
1 file changed
+50 -10
+50 -10
View File
@@ -140,14 +140,24 @@ pub fn match_kernel_prefix<'a>(name: &str, kernel_prefixes: &[&'a str]) -> Optio
} }
/// Generate initramfs candidate filenames by combining each entry of `initramfs_prefixes` /// Generate initramfs candidate filenames by combining each entry of `initramfs_prefixes`
/// with `suffix`. The caller is expected to check which candidates actually exist. /// with `suffix`, and then with `suffix` followed by `.img`, which many distributions use.
pub fn initramfs_candidates<'a>( /// For example, Arch Linux pairs `vmlinuz-linux` with `initramfs-linux.img`.
suffix: &'a str, /// The caller is expected to check which candidates actually exist.
initramfs_prefixes: &'a [&'a str], pub fn initramfs_candidates(
) -> impl Iterator<Item = String> + 'a { suffix: &str,
initramfs_prefixes initramfs_prefixes: &[&str],
.iter() ) -> impl Iterator<Item = String> {
.map(move |prefix| format!("{}{}", prefix, suffix)) let mut candidates: Vec<String> = Vec::new();
for extension in ["", ".img"] {
for prefix in initramfs_prefixes {
let candidate = format!("{}{}{}", prefix, suffix, extension);
// Skip duplicates, like "initrd" with ".img" when "initrd.img" is also a prefix.
if !candidates.contains(&candidate) {
candidates.push(candidate);
}
}
}
candidates.into_iter()
} }
#[cfg(test)] #[cfg(test)]
@@ -399,14 +409,44 @@ mod tests {
let candidates: Vec<_> = initramfs_candidates("-6.1.0", LINUX_INITRAMFS_PREFIXES).collect(); let candidates: Vec<_> = initramfs_candidates("-6.1.0", LINUX_INITRAMFS_PREFIXES).collect();
assert_eq!( assert_eq!(
candidates, candidates,
&["initramfs-6.1.0", "initrd-6.1.0", "initrd.img-6.1.0"] &[
"initramfs-6.1.0",
"initrd-6.1.0",
"initrd.img-6.1.0",
"initramfs-6.1.0.img",
"initrd-6.1.0.img",
"initrd.img-6.1.0.img",
]
);
}
#[test]
fn initramfs_candidates_include_img_extension() {
// Arch Linux, and Fedora or Gentoo with dracut, add .img to the initramfs name.
let arch: Vec<_> = initramfs_candidates("-linux", LINUX_INITRAMFS_PREFIXES).collect();
assert!(arch.iter().any(|c| c == "initramfs-linux.img"));
let fedora: Vec<_> =
initramfs_candidates("-6.8.5-301.fc40.x86_64", LINUX_INITRAMFS_PREFIXES).collect();
assert!(
fedora
.iter()
.any(|c| c == "initramfs-6.8.5-301.fc40.x86_64.img")
); );
} }
#[test] #[test]
fn initramfs_candidates_empty_suffix() { fn initramfs_candidates_empty_suffix() {
let candidates: Vec<_> = initramfs_candidates("", LINUX_INITRAMFS_PREFIXES).collect(); let candidates: Vec<_> = initramfs_candidates("", LINUX_INITRAMFS_PREFIXES).collect();
assert_eq!(candidates, &["initramfs", "initrd", "initrd.img"]); assert_eq!(
candidates,
&[
"initramfs",
"initrd",
"initrd.img",
"initramfs.img",
"initrd.img.img"
]
);
} }
#[test] #[test]