'\" t .\" Title: 3cpio .\" Author: Benjamin Drung .\" Generator: Asciidoctor 2.0.23 .\" Date: 2025-08-29 .\" Manual: 3cpio .\" Source: 3cpio 0.5.1 .\" Language: English .\" .TH "3CPIO" "1" "2025-08-29" "3cpio 0.5.1" "3cpio" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 .nh .ad l .de URL \fI\\$2\fP <\\$1>\\$3 .. .als MTO URL .if \n[.g] \{\ . mso www.tmac . am URL . ad l . . . am MTO . ad l . . . LINKSTYLE blue R < > .\} .SH "NAME" 3cpio \- manage initrd cpio archives .SH "SYNOPSIS" .sp \fB3cpio\fP \fB\-\-count\fP \fIARCHIVE\fP .sp \fB3cpio\fP {\fB\-c\fP|\fB\-\-create\fP} [\fB\-v\fP|\fB\-\-debug\fP] [\fB\-C\fP \fIDIR\fP] [\fB\-\-data\-align\fP \fIALIGNMENT\fP] [\fIARCHIVE\fP] < \fImanifest\fP .sp \fB3cpio\fP {\fB\-e\fP|\fB\-\-examine\fP} [\fB\-\-raw\fP] \fIARCHIVE\fP .sp \fB3cpio\fP {\fB\-t\fP|\fB\-\-list\fP} [\fB\-v\fP|\fB\-\-debug\fP] [\fB\-P\fP \fILIST\fP] \fIARCHIVE\fP [\fIpattern\fP...] .sp \fB3cpio\fP {\fB\-x\fP|\fB\-\-extract\fP} [\fB\-v\fP|\fB\-\-debug\fP] [\fB\-C\fP \fIDIR\fP] [\fB\-P\fP \fILIST\fP] [\fB\-p\fP] [\fB\-s\fP \fINAME\fP] [\fB\-\-to\-stdout\fP] [\fB\-\-force\fP] \fIARCHIVE\fP [\fIpattern\fP...] .sp \fB3cpio\fP {\fB\-V\fP|\fB\-\-version\fP} .sp \fB3cpio\fP {\fB\-h\fP|\fB\-\-help\fP} .SH "DESCRIPTION" .sp \fB3cpio\fP is a tool to manage initramfs cpio files for the Linux kernel. The Linux kernel\(cqs \c .URL "https://www.kernel.org/doc/html/latest/driver\-api/early\-userspace/buffer\-format.html" "initramfs buffer format" is based around the \f(CRnewc\fP or \f(CRcrc\fP cpio formats. Multiple cpio archives can be concatenated and the last archive can be compressed. Different compression algorithms can be used depending on what support was compiled into the Linux kernel. \fB3cpio\fP is tailored to initramfs cpio files and will not gain support for other cpio formats. .sp Following compression formats are supported: bzip2, gzip, lz4, lzma, lzop, xz, zstd. .SH "MODES" .sp \fB\-\-count\fP \fIARCHIVE\fP .RS 4 Print the number of concatenated cpio archives. .RE .sp \fB\-c\fP, \fB\-\-create\fP [\fIARCHIVE\fP] .RS 4 Create a new cpio archive. Read the manifest from the standard input. See the MANIFEST section for the description of the manifest format. Write the cpio archive to standard output or to the specified \fIARCHIVE\fP file if provided. The permission of the \fIARCHIVE\fP file will be determined by the permission of the input files (to avoid leaking sensitive information). .RE .sp \fB\-e\fP, \fB\-\-examine\fP \fIARCHIVE\fP .RS 4 List the offsets of the cpio archives and their compression in a formatted table. SI prefixes are used for the size unit (e. g. 1 kB = 1000 bytes). Do not rely on the output to have a specific layout. Use the \fB\-\-raw\fP option for a machine\-readable output. Then each line will contain these five values tab\-separated: .sp Start .RS 4 The beginning of the cpio archive in bytes. .RE .sp End .RS 4 The end of the cpio archive in bytes. .RE .sp Size .RS 4 The on\-disk size of the cpio archive in bytes (end \- start). .RE .sp Compression .RS 4 Compression of the cpio archive (\f(CRcpio\fP in case it is not compressed). .RE .sp Extracted size .RS 4 Size of the files inside the cpio archive in bytes. .RE .RE .sp \fB\-t\fP, \fB\-\-list\fP \fIARCHIVE\fP [\fIpattern\fP...] .RS 4 List the contents of the cpio archives. By default only the file names are printed. If \fB\-\-verbose\fP is specified, the long listing format is used (similar to ls \-\-long). If \fB\-\-debug\fP is specified, the inode is printed in addition to the long format. If one or more \fIpattern\fPs are supplied, list only file names matching at least one of those \fIpattern\fPs. These \fIpattern\fPs are shell wildcard patterns (see \fBglob\fP(7)). .RE .sp \fB\-x\fP, \fB\-\-extract\fP \fIARCHIVE\fP [\fIpattern\fP...] .RS 4 Extract cpio archives. If one or more \fIpattern\fPs are supplied, extract only files matching at least one of those \fIpattern\fPs. These \fIpattern\fPs are shell wildcard patterns (see \fBglob\fP(7)). .RE .sp \fB\-V\fP, \fB\-\-version\fP .RS 4 Print version number. .RE .sp \fB\-h\fP, \fB\-\-help\fP .RS 4 Print help message. .RE .SH "OPTIONS" .sp \fB\-\-data\-align\fP \fIALIGNMENT\fP .RS 4 When creating a cpio archive, pad the cpio metadata to align the file data on \fIALIGNMENT\fP in bytes. This option is useful to reflink cpio file data on file systems that support reflinks. This padding/alignment will be skipped for files that are smaller than \fIALIGNMENT\fP, files where the padded namesize field would exceed \f(CRPATH_MAX\fP, and for cpio archives that are compressed. \fIALIGNMENT\fP must be a multiple of 4 bytes. This option is only taken into account in the \fB\-\-create\fP mode. .sp The resulting cpio archive may be highly fragmented, which can lead to performance degradation when reading/extracting the image from devices with slow random IO (e.g. spinning disk). .sp \fBNote\fP: Using this option will "bend" the cpio newc spec a bit to inject zeros after the filename to provide data segment alignment. These zeros are accounted for in the namesize, but some applications may only expect a single zero\-terminator (and 4 byte alignment). GNU cpio and Linux initramfs handle this fine as long as \f(CRPATH_MAX\fP is not exceeded. .sp The following command can be used to determine the optimal transfer size of the file system (where \fI$path\fP is the path the cpio archive will be written to): .sp .if n .RS 4 .nf .fam C stat \-\-file\-system \-c "%s" \-\- "$path" .fam .fi .if n .RE .RE .sp \fB\-C\fP \fIDIR\fP, \fB\-\-directory\fP=\fIDIR\fP .RS 4 Change directory before performing any operation, but after opening the \fIARCHIVE\fP. This option is only taken into account in the \fB\-\-extract\fP mode. .RE .sp \fB\-\-make\-directories\fP: Create leading directories where needed. This option is only taken into account in the \fB\-\-extract\fP mode. .sp \fB\-P\fP \fILIST\fP, \fB\-\-parts\fP \fILIST\fP .RS 4 Only operate on the cpio archives that matches \fILIST\fP. This option is only taken into account in the \fB\-\-list\fP and \fB\-\-extract\fP modes. \fILIST\fP is made up of one range, or many ranges separated by commas. Each range is one of: .sp N .RS 4 N\(cqth cpio archive, counted from 1 .RE .sp N\- .RS 4 from N\(cqth (included) to last cpio archive .RE .sp N\-M .RS 4 from N\(cqth to M\(cqth (included) cpio archive .RE .sp \-M .RS 4 from first to M\(cqth (included) cpio archive .RE .RE .sp \fB\-p\fP, \fB\-\-preserve\-permissions\fP .RS 4 Set permissions of extracted files to those recorded in the archive (default for superuser). This option is only taken into account in the \fB\-\-extract\fP mode. .RE .sp \fB\-\-raw\fP .RS 4 Use a machine\-readable output format. This format is designed for easy parsing and is intended for being used in scripts. This option is only taken into account in the \fB\-\-examine\fP mode. .RE .sp \fB\-s\fP \fINAME\fP, \fB\-\-subdir\fP=\fINAME\fP .RS 4 Extract the cpio archives into separate sub\-directories (using the given \fINAME\fP plus an incrementing number). This option is only taken into account in the \fB\-\-extract\fP mode. .RE .sp \fB\-\-to\-stdout\fP .RS 4 Extract files to standard output. Only the content of the files will be written to stdout. Directories and symlinks will be ignored. This option is only taken into account in the \fB\-\-extract\fP mode. .RE .sp \fB\-v\fP, \fB\-\-verbose\fP .RS 4 Verbose output. This option is only taken into account in the \fB\-\-extract\fP and \fB\-\-list\fP modes. .RE .sp \fB\-\-debug\fP .RS 4 Debug output. This option is only taken into account in the \fB\-\-extract\fP and \fB\-\-list\fP modes. .RE .sp \fB\-\-force\fP .RS 4 Force overwriting existing files. This option is only taken into account in the \fB\-\-extract\fP mode. .RE .SH "MANIFEST" .sp When generating initrd cpio archives, following manifest format will be used. The manifest is a text format that is parsed line by line. .sp If the line starts with \fI#cpio\fP it is interpreted as section marker to start a new cpio. A compression may be specified by adding a colon followed by the compression format and an optional compression level. Example for a Zstandard\-compressed cpio with compression level 9: .sp .if n .RS 4 .nf .fam C #cpio: zstd \-9 .fam .fi .if n .RE .sp All lines starting with \fI#\fP excluding \fI#cpio\fP (see above) will be treated as comments and will be ignored. .sp Each element in the line is separated by a tab and is expected to be one of the following file types: .sp .if n .RS 4 .nf .fam C file dir block char link fifo sock .fam .fi .if n .RE .sp fifo is also known as named pipe (see fifo(7)). .sp In case an element is empty or equal to \- it is treated as not specified and it is derived from the input file. .sp .RS 4 Path of the input file. It can be left unspecified in case all other needed fields are specified (and the file is otherwise empty). \fBLimitation\fP: The path must not start with #, be equal to \-, or contain tabs. .RE .sp .RS 4 Path of the file inside the cpio. If the name is left unspecified it will be derived from . \fBLimitation\fP: The path must not be equal to \- or contain tabs. .RE .sp .RS 4 File mode specified in octal. .RE .sp .RS 4 User ID (owner) of the file specified in decimal. .RE .sp .RS 4 Group ID of the file specified in decimal. .RE .sp .RS 4 Modification time of the file specified as seconds since the Epoch (1970\-01\-01 00:00 UTC). The specified time might be clamped by the time set in the SOURCE_DATE_EPOCH environment variable. .RE .sp .RS 4 Size of the input file in bytes. 3cpio will fail in case the input file is smaller than the provided file size. .RE .sp .RS 4 Major block/character device number in decimal. .RE .sp .RS 4 Minor block/character device number in decimal. .RE .sp .RS 4 Target of the symbolic link. \fBLimitation\fP: The target path must not be equal to \- or contain tabs. .RE .sp \fBLimitations\fP: Files cannot start with # (will be treated as comment), be equal to \- (will be treated as not specified), or contain tabs (will be split by tabs). These limitations of the manifest file are not expected to cause problems in practice. .SH "ENVIRONMENT VARIABLES" .sp SOURCE_DATE_EPOCH .RS 4 This environment variable will be taken into account when creating cpio archive. All modification times that are newer than the time specified in "SOURCE_DATE_EPOCH" will be clamped. Compressors will run with only one thread in case their multithreading implementation is not reproducible. The created cpio archive will be reproducible across multiple runs. .RE .SH "EXIT STATUS" .sp \fB0\fP .RS 4 Success. .RE .sp \fB1\fP .RS 4 Failure. .RE .sp \fB2\fP .RS 4 Failure during command line argument parsing. .RE .SH "EXAMPLES" .sp List the number of cpio archives that an initramfs file contains: .sp .if n .RS 4 .nf .fam C $ 3cpio \-\-count /boot/initrd.img 4 .fam .fi .if n .RE .sp Examine the content of the initramfs cpio on an Ubuntu 24.04 system: .sp .if n .RS 4 .nf .fam C $ 3cpio \-\-examine /boot/initrd.img Start\& End\& Size\& Compr.\& Extracted 0 B\& 148 kB\& 148 kB\& cpio\& 147 kB 148 kB\& 13.3 MB\& 13.1 MB\& cpio\& 13.1 MB 13.3 MB\& 55.2 MB\& 41.9 MB\& cpio\& 41.7 MB 55.2 MB\& 62.0 MB\& 6.74 MB\& zstd\& 15.6 MB .fam .fi .if n .RE .sp There is also a machine\-readable output format available: .sp .if n .RS 4 .nf .fam C $ 3cpio \-\-examine \-\-raw /boot/initrd.img 0\& 148480\& 148480\& cpio\& 147350 148480\& 13275136\& 13126656\& cpio\& 13125632 13275136\& 55215104\& 41939968\& cpio\& 41692226 55215104\& 61956920\& 6741816\& zstd\& 15616306 .fam .fi .if n .RE .sp This initramfs cpio consists of three uncompressed cpio archives followed by a Zstandard\-compressed cpio archive. .sp List the content of the initramfs cpio on an Ubuntu 24.04 system: .sp .if n .RS 4 .nf .fam C $ 3cpio \-\-list /boot/initrd.img \&. kernel kernel/x86 kernel/x86/microcode kernel/x86/microcode/AuthenticAMD.bin kernel kernel/x86 kernel/x86/microcode kernel/x86/microcode/.enuineIntel.align.0123456789abc kernel/x86/microcode/GenuineIntel.bin \&. usr usr/lib usr/lib/firmware usr/lib/firmware/3com usr/lib/firmware/3com/typhoon.bin.zst [...] .fam .fi .if n .RE .sp The first cpio contains only the AMD microcode. The second cpio contains only the Intel microcode. The third cpio contains firmware files and kernel modules. .sp Extract the content of the initramfs cpio to the initrd subdirectory on an Ubuntu 24.04 system: .sp .if n .RS 4 .nf .fam C $ 3cpio \-\-extract \-C initrd /boot/initrd.img $ ls initrd bin\& cryptroot\& init\& lib\& lib.usr\-is\-merged\& run\& scripts\& var conf\& etc\& kernel\& lib64\& libx32\& sbin\& usr .fam .fi .if n .RE .sp Create a cpio archive similar to the other cpio tools using the \f(CRfind\fP command: .sp .if n .RS 4 .nf .fam C $ cd inputdir && find . | sort | 3cpio \-\-create ../example.cpio .fam .fi .if n .RE .sp Due to its manifest file format support, 3cpio can create cpio archives without the need of copying files into a temporary directory first. Example for creating an early microcode cpio image directly using the system installed files: .sp .if n .RS 4 .nf .fam C $ cat manifest \-\& kernel\& dir\& 755\& 0\& 0\& 1751654557 \-\& kernel/x86\& dir\& 755\& 0\& 0\& 1752011622 /usr/lib/firmware/amd\-ucode\& kernel/x86/microcode /usr/lib/firmware/amd\-ucode/microcode_amd_fam19h.bin\& kernel/x86/microcode/AuthenticAMD.bin $ 3cpio \-\-create amd\-ucode.img < manifest $ 3cpio \-\-list \-\-verbose amd\-ucode.img drwxr\-xr\-x\& 2 root\& root\& 0 Jul\& 4 20:42 kernel drwxr\-xr\-x\& 2 root\& root\& 0 Jul\& 8 23:53 kernel/x86 drwxr\-xr\-x\& 2 root\& root\& 0 Jun 10 10:51 kernel/x86/microcode \-rw\-r\-\-r\-\-\& 1 root\& root\& 100684 Mar 23 22:42 kernel/x86/microcode/AuthenticAMD.bin .fam .fi .if n .RE .sp Example for creating an initrd image containing of an uncompressed early microcode cpio followed by a Zstandard\-compressed cpio: .sp .if n .RS 4 .nf .fam C $ cat manifest #cpio \-\& kernel\& dir\& 755\& 0\& 0\& 1751654557 \-\& kernel/x86\& dir\& 755\& 0\& 0\& 1752011622 /usr/lib/firmware/amd\-ucode\& kernel/x86/microcode /usr/lib/firmware/amd\-ucode/microcode_amd_fam19h.bin\& kernel/x86/microcode/AuthenticAMD.bin #cpio: zstd \-9 / /bin /usr /usr/bin /usr/bin/bash # This is a comment. Leaving the remaining files as task for the reader. $ 3cpio \-\-create initrd.img < manifest $ 3cpio \-\-examine initrd.img Start\& End\& Size\& Compr.\& Extracted 0 B\& 101 kB\& 101 kB\& cpio\& 101 kB 101 kB\& 786 kB\& 685 kB\& zstd\& 1.45 MB $ 3cpio \-\-list \-\-verbose initrd.img drwxr\-xr\-x\& 2 root\& root\& 0 Jul\& 4 20:42 kernel drwxr\-xr\-x\& 2 root\& root\& 0 Jul\& 8 23:53 kernel/x86 drwxr\-xr\-x\& 2 root\& root\& 0 Jun 10 10:51 kernel/x86/microcode \-rw\-r\-\-r\-\-\& 1 root\& root\& 100684 Mar 23 22:42 kernel/x86/microcode/AuthenticAMD.bin drwxr\-xr\-x\& 2 root\& root\& 0 Jun\& 5 14:11 . lrwxrwxrwx\& 1 root\& root\& 7 Mar 20\& 2022 bin \-> usr/bin drwxr\-xr\-x\& 2 root\& root\& 0 Apr 20\& 2023 usr drwxr\-xr\-x\& 2 root\& root\& 0 Jul\& 9 09:56 usr/bin \-rwxr\-xr\-x\& 1 root\& root\& 1446024 Mar 31\& 2024 usr/bin/bash .fam .fi .if n .RE .SH "SEE ALSO" .sp bsdcpio(1), cpio(1), lsinitramfs(8), lsinitrd(1) .SH "COPYING" .sp Copyright \(co 2024\-2025 Benjamin Drung. Free use of this software is granted under the terms of the ISC License. .SH "AUTHOR" .sp Benjamin Drung