Skip to content

bdrung/3cpio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

3cpio

3cpio is a tool to manage initramfs cpio files for the Linux kernel. The Linux kernel's initramfs buffer format is based around the newc or crc 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. 3cpio is tailored to initramfs cpio files and will not gain support for other cpio formats.

As of now, 3cpio supports examining and listing the content of the initramfs cpio.

Note: The Rust crate is named threecpio, because package names are not allowed to start with numbers.

Usage examples

Examine the content of the initramfs cpio on an Ubuntu 24.04 system:

$ 3cpio --examine /boot/initrd.img
0	cpio
77312	cpio
7286272	cpio
85523968	zstd

This initramfs cpio consists of three uncompressed cpio archives followed by a Zstandard-compressed cpio archive.

List the content of the initramfs cpio on an Ubuntu 24.04 system:

$ 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
[...]

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.

Quick examples comparing

Runtime comparison measured with time over five runs on different initramfs cpios:

System Kernel Comp. Size Files 3cpio lsinitramfs lsinitrd
Ryzen 7 5700G 6.5.0-27-generic zstd¹ 102 MB 3496 0.052s 14.243s –³
Ryzen 7 5700G VM 6.8.0-22-generic zstd¹ 63 MB 1934 0.042s 7.239s –³
Ryzen 7 5700G VM 6.8.0-22-generic zstd² 53 MB 1783 0.061s 0.452s 0.560s
RasPi Zero 2W 6.5.0-1012-raspi zstd¹ 24 MB 1538 0.647s 56.253s –³
RasPi Zero 2W 6.5.0-1012-raspi zstd² 30 MB 2028 1.141s 2.286s 6.118s
RasPi Zero 2W 6.8.0-1002-raspi zstd¹ 51 MB 2532 0.713s 164.575s –³
RasPi Zero 2W 6.8.0-1002-raspi zstd -1² 47 MB 2778 1.156s 2.842s 9.508s
RasPi Zero 2W 6.8.0-1002-raspi xz² 41 MB 2778 6.922s 13.451s 35.184s

Legend:

  1. generated by initramfs-tools
  2. generated by dracut --force --${compression}. On Raspberry Pi Zero 2W there is not enough memory for the default zstd -15. So using the default from initramfs-tools there: dracut --force --compress "zstd -1 -q -T0"
  3. lsinitrd only reads the first two cpio archives of the file, but the initramfs consists of four cpios.

Results:

  • 3cpio is 87 to 274 times faster than lsinitramfs for images generated by initramfs-tools.
  • 3cpio is two to eight times faster than lsinitramfs for images generated by dracut.
  • 3cpio five to nine times faster than lsinitrd for images generated by dracut.

Commands used:

3cpio -t /boot/initrd.img-${version} | wc -l
time 3cpio -t /boot/initrd.img-${version} > /dev/null
time lsinitramfs /boot/initrd.img-${version} > /dev/null
time lsinitrd /boot/initrd.img-${version} > /dev/null

Naming and alternatives

The tool is named 3cpio because it is the third cpio tool besides GNU cpio and bsdcpio provided by libarchive. 3cpio is also the third tool that can list the content of initramfs cpio archives besides lsinitramfs from initramfs-tools and lsinitrd from dracut.

About

manage initrd cpio archives

Resources

License

Stars

Watchers

Forks

Packages

No packages published