MCPcopy Create free account
hub / github.com/bootc-dev/bootc / handle_kernel_relocation

Function handle_kernel_relocation

crates/lib/src/container_export.rs:330–379  ·  view source on GitHub ↗

Copy kernel and initramfs to /boot for legacy installers (e.g. Anaconda liveimg).

(
    tar_builder: &mut tar::Builder<W>,
    root_dir: &cap_std_ext::cap_std::fs::Dir,
)

Source from the content-addressed store, hash-verified

328
329/// Copy kernel and initramfs to /boot for legacy installers (e.g. Anaconda liveimg).
330fn handle_kernel_relocation<W: Write>(
331 tar_builder: &mut tar::Builder<W>,
332 root_dir: &cap_std_ext::cap_std::fs::Dir,
333) -> Result<()> {
334 use crate::kernel::KernelType;
335
336 let kernel_info = match crate::kernel::find_kernel(root_dir)? {
337 Some(kernel) => kernel,
338 None => return Ok(()),
339 };
340
341 append_dir_entry(tar_builder, "boot")?;
342 append_dir_entry(tar_builder, "boot/grub2")?;
343
344 // UKIs don't need relocation - they're already in /boot/EFI/Linux
345 if kernel_info.kernel.unified {
346 return Ok(());
347 }
348
349 // Traditional vmlinuz kernels need to be copied to /boot
350 if let KernelType::Vmlinuz { path, initramfs } = &kernel_info.k_type {
351 let version = &kernel_info.kernel.version;
352
353 // Copy vmlinuz
354 if root_dir.try_exists(path)? {
355 let metadata = root_dir.metadata(path)?;
356 let mut header =
357 tar_header_from_meta(tar::EntryType::Regular, metadata.len(), &metadata);
358 let mut file = root_dir.open(path)?;
359 let boot_path = format!("boot/vmlinuz-{}", version);
360 tar_builder
361 .append_data(&mut header, &boot_path, &mut file)
362 .with_context(|| format!("Failed to add kernel: {}", boot_path))?;
363 }
364
365 // Copy initramfs
366 if root_dir.try_exists(initramfs)? {
367 let metadata = root_dir.metadata(initramfs)?;
368 let mut header =
369 tar_header_from_meta(tar::EntryType::Regular, metadata.len(), &metadata);
370 let mut file = root_dir.open(initramfs)?;
371 let boot_path = format!("boot/initramfs-{}.img", version);
372 tar_builder
373 .append_data(&mut header, &boot_path, &mut file)
374 .with_context(|| format!("Failed to add initramfs: {}", boot_path))?;
375 }
376 }
377
378 Ok(())
379}
380
381fn append_dir_entry<W: Write>(tar_builder: &mut tar::Builder<W>, path: &str) -> Result<()> {
382 let mut header = tar_header_dir_root();

Callers 1

export_filesystemFunction · 0.85

Calls 4

find_kernelFunction · 0.85
append_dir_entryFunction · 0.85
tar_header_from_metaFunction · 0.85
openMethod · 0.80

Tested by

no test coverage detected