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

Function build_ukify

crates/lib/src/ukify.rs:30–141  ·  view source on GitHub ↗
(
    rootfs: &Utf8Path,
    extra_kargs: &[String],
    args: &[OsString],
    kernel: Option<KernelInternal>,
    allow_missing_fsverity: bool,
    write_dumpfile_to: Option<&Utf8Path>,
)

Source from the content-addressed store, hash-verified

28/// 6. Invokes ukify with computed arguments plus any pass-through args
29#[context("Building UKI")]
30pub(crate) async fn build_ukify(
31 rootfs: &Utf8Path,
32 extra_kargs: &[String],
33 args: &[OsString],
34 kernel: Option<KernelInternal>,
35 allow_missing_fsverity: bool,
36 write_dumpfile_to: Option<&Utf8Path>,
37) -> Result<()> {
38 // Warn if --karg is used (temporary workaround)
39 if !extra_kargs.is_empty() {
40 tracing::warn!(
41 "The --karg flag is temporary and will be removed as soon as possible \
42 (https://github.com/bootc-dev/bootc/issues/1826)"
43 );
44 }
45
46 // Verify ukify is available
47 if !crate::utils::have_executable("ukify")? {
48 anyhow::bail!(
49 "ukify executable not found in PATH. Please install systemd-ukify or equivalent."
50 );
51 }
52
53 // Open the rootfs directory
54 let root = Dir::open_ambient_dir(rootfs, cap_std_ext::cap_std::ambient_authority())
55 .with_context(|| format!("Opening rootfs {rootfs}"))?;
56
57 let kernel_final = match kernel {
58 Some(ref kernel) => kernel,
59 None => &crate::kernel::find_kernel(&root)?
60 .ok_or_else(|| anyhow::anyhow!("No kernel found in {rootfs}"))?,
61 };
62
63 // Extract vmlinuz and initramfs paths, or bail if this is already a UKI
64 let (vmlinuz_path, initramfs_path) = match &kernel_final.k_type {
65 crate::kernel::KernelType::Vmlinuz { path, initramfs } => (path, initramfs),
66 crate::kernel::KernelType::Uki { path, .. } => {
67 anyhow::bail!("Cannot build UKI: rootfs already contains a UKI at {path}");
68 }
69 };
70
71 // Verify kernel and initramfs exist
72 //
73 // NOTE: Not using cap_std here as the vmlinuz/initramfs path from
74 // args can be outside of "rootfs"
75 if kernel.is_some() {
76 if !vmlinuz_path.exists() {
77 anyhow::bail!("Kernel not found at {vmlinuz_path}");
78 }
79
80 if !initramfs_path.exists() {
81 anyhow::bail!("Initramfs not found at {initramfs_path}");
82 }
83 } else {
84 if !root
85 .try_exists(&vmlinuz_path)
86 .context("Checking for vmlinuz")?
87 {

Callers 3

run_from_optFunction · 0.85

Calls 10

have_executableFunction · 0.85
find_kernelFunction · 0.85
compute_composefs_digestFunction · 0.85
get_kargs_in_rootFunction · 0.85
existsMethod · 0.80
argMethod · 0.80
argsMethod · 0.80
run_inheritedMethod · 0.80
is_emptyMethod · 0.45
extendMethod · 0.45

Tested by 2