Skip to content

Commit eee1e67

Browse files
Johan-Liebert1cgwalters
authored andcommitted
composefs/bls: Properly reuse kernel + initrd duplicates
Function `find_vmlinuz_initrd_duplicates` returns all the deployment ids that match the current deployment's kernel + initrd SHA256 sum, but only would actually exist on disk, every other deployment's BLS Config would simply be pointing to one single directory. We were incorrectly picking the first entry out of the returned list, which might or might not exist as an actual directory containing the kernel. Fix the bug by iterating over all directory entries in `/boot` or `/EFI/Linux` and checking if the deployment id in the list actually exists on the disk or not Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent 3ad82d0 commit eee1e67

File tree

1 file changed

+38
-6
lines changed
  • crates/lib/src/bootc_composefs

1 file changed

+38
-6
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,19 +504,51 @@ pub(crate) fn setup_composefs_bls_boot(
504504
});
505505

506506
match find_vmlinuz_initrd_duplicates(&boot_digest)? {
507-
Some(symlink_to) => {
508-
let symlink_to = &symlink_to[0];
507+
Some(shared_entries) => {
508+
// Multiple deployments could be using the same kernel + initrd, but there
509+
// would be only one available
510+
//
511+
// Symlinking directories themselves would be better, but vfat does not support
512+
// symlinks
513+
514+
let mut shared_entry: Option<String> = None;
515+
516+
let entries =
517+
Dir::open_ambient_dir(entry_paths.entries_path, ambient_authority())
518+
.context("Opening entries path")?
519+
.entries_utf8()
520+
.context("Getting dir entries")?;
521+
522+
for ent in entries {
523+
let ent = ent?;
524+
// We shouldn't error here as all our file names are UTF-8 compatible
525+
let ent_name = ent.file_name()?;
526+
527+
if shared_entries.contains(&ent_name) {
528+
shared_entry = Some(ent_name);
529+
break;
530+
}
531+
}
532+
533+
let shared_entry = shared_entry.ok_or_else(|| {
534+
anyhow::anyhow!("Could not get symlink to BLS boot entry")
535+
})?;
509536

510537
match bls_config.cfg_type {
511538
BLSConfigType::NonEFI {
512539
ref mut linux,
513540
ref mut initrd,
514541
..
515542
} => {
516-
*linux = entry_paths.abs_entries_path.join(&symlink_to).join(VMLINUZ);
517-
518-
*initrd =
519-
vec![entry_paths.abs_entries_path.join(&symlink_to).join(INITRD)];
543+
*linux = entry_paths
544+
.abs_entries_path
545+
.join(&shared_entry)
546+
.join(VMLINUZ);
547+
548+
*initrd = vec![entry_paths
549+
.abs_entries_path
550+
.join(&shared_entry)
551+
.join(INITRD)];
520552
}
521553

522554
_ => unreachable!(),

0 commit comments

Comments
 (0)