Introduction
cpio is a Unix archive format from the 1970s, a little older than
tar and simpler. The cpio
command reads a list of file names and copies the files into or out of an archive. It is
seldom used directly today, but it sits inside common formats: the Linux kernel’s
initramfs is a cpio archive, RPM packages carry their files as a compressed cpio
archive, and macOS installer packages hold a cpio payload.
Structure
An archive is a series of entries, each a header, the file name and the file’s data.
The last entry is named TRAILER!!! and has no data. There are several
header formats, told apart by the magic at the start of each header:
| Format | Magic | Header | Notes |
|---|---|---|---|
| Old binary | 070707 octal as a 16-bit number (C7 71 or 71 C7) | 26 bytes | 16-bit fields in the writer’s byte order; name and data padded to an even length |
| odc (portable ASCII) | 070707 as text | 76 bytes | POSIX.1: fields as octal text; no padding |
| newc (SVR4) | 070701 as text | 110 bytes | fields as 8 hexadecimal digits; header with name, and data, padded to 4 bytes |
| crc | 070702 as text | 110 bytes | newc with a simple checksum of the data |
Each header gives the inode number, mode, owner, group, link count, modification time, device numbers, name length and file size. Hard links are recognised by a shared inode number.
Links
Software
- GNU cpio (Linux, macOS)
- bsdcpio and bsdtar, from libarchive, built into macOS
- 7-Zip, extract only (Windows)
Developers
- libarchive, C library that reads and writes every cpio format
Reference
- pax, the POSIX description, which includes the odc cpio format