cpio: Create and Extract cpio Archives
cpio reads a list of file names on stdin and copies them into (or out of) an archive stream, the format behind initramfs images and RPM payloads.
cpio is less common than tar but shows up in boot images and package internals. In CI you mostly extract cpio payloads; -i with -H newc covers the modern format.
What it does
cpio -o (copy-out) reads file names from stdin and writes an archive to stdout. cpio -i (copy-in) reads an archive from stdin and extracts it. cpio -t lists contents. The -H flag selects the format; newc is the portable ASCII format used by initramfs.
Common usage
find . -depth -print | cpio -o -H newc > files.cpio # create
cpio -i -d < files.cpio # extract, make dirs
cpio -t < files.cpio # list contents
# initramfs style: gzip on top
find . | cpio -o -H newc | gzip > initramfs.cpio.gzOptions
| Flag | What it does |
|---|---|
| -o / --create | Copy-out: build an archive from stdin names |
| -i / --extract | Copy-in: extract an archive from stdin |
| -t / --list | List the archive contents |
| -H <fmt> | Archive format (newc is the modern portable one) |
| -d / --make-directories | Create leading directories on extract |
| -v / --verbose | List files as they are processed |
In CI
cpio reads names from stdin, so it pairs with find: find . | cpio -o. For initramfs work, wrap it with gzip or zstd (the kernel accepts both). Add -d on extract or files land without their parent directories.
Common errors in CI
"cpio: premature end of archive" means a truncated stream. "cpio: <name>: Cannot open: No such file or directory" on extract without -d means a missing parent directory. "cpio: Malformed number" usually means a format mismatch; specify -H newc explicitly when the archive is the newc ASCII format.