Skip to content

cpio image generation silently fails if cpio cli tool not installed #320

@hnez

Description

@hnez

I have recently tried building initramfs images with genimage inside a container. This seemingly just worked, but when I later tried using the initramfs it turned out to be empty.

After a bit of investigation I found out that I have missed this message on stderr while building the initramfs:

INFO: cpio(install.img): cmd: "(cd '/var/tmp/ptxdist.LwUO9c/genimage.2MOKvB/root' && find . | cpio -H 'newc'  -o | zstd -T0 -19) > '…/platform-x86_64/images/install.img'" (stderr):
/bin/sh: 1: cpio: not found
INFO: cmd: "rm -rf "/var/tmp/ptxdist.LwUO9c/genimage.2MOKvB"/*" (stderr):
finished target install.img

The generated install.img was just 13 bytes in size and if I had to guess just consisted of the zstd file header. Installing the cpio package in the container fixed the problem.

It would be preferable if the genimage call failed in this case.


I guess this piece of code should be modified to contain something like set -o pipefail:

genimage/image-cpio.c

Lines 32 to 36 in ff7da92

ret = systemp(image, "(cd '%s' && find . | %s -H '%s' %s -o %s %s) > '%s'",
mountpath(image),
get_opt("cpio"),
format, extraargs, comp[0] != '\0' ? "|" : "", comp,
imageoutfile(image));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions