Skip to content

Comment on A weird CPIO discrepancy

Comments

cpio archives have some very useful properties (you can merge them by concatenation!), but the tooling is quite a PITA.

On unrelated note, is there any usecase for cpio files other than initramfs? Back in the day rpm2cpio was the recommended way to unpack rpm files, but nowadays rpm2archive is much faster.

RPM files are also no longer reliably CPIO compatible. 99.999% are, but as CPIO doesn't allow file sizes larger than 4gb, creating such an RPM will use a custom archive scheme incompatible with CPIO.

However, it's not particularly common practice to stuff a 4gb file into an RPM, so at least at the moment, it's not a very big practical issue.

macOS packages are gzipped cpio archives:

file Diva.au.pkg/Payload

Payload: gzip compressed data, from Unix, original size modulo 2^32 25391104

gzip -dc Diva.au.pkg/Payload > unpacked file unpacked

unpacked: ASCII cpio archive (pre-SVR4 or odc)

A long time ago, when Apple was on the verge of releasing OS X, they ran a series of dev conferences. These were to inform then-current Mac devs on the huge changes from 9 to X.

One slide was "we've come up with a new way to install apps! Just run /bin/sh configure, then make, then make install!". After the wave of consternation swept the assembled devs, the next slide was "only joking". With reassurance that you'll still be able to drag an icon to install.

Very amusing to me that CPIO is underneath the pkg install method/format. I wonder what those old school Mac devs would have thought?

You can also concatenate tar files, you just need to remove the last two zero blocks before gluing the files together (GNU tar has an option to do this for you, it's somewhere in the man, or use head -c-2b) or tell tar to ignore them when extracting.

Beware that tar has some bugs regarding certain kinds of concatenation. I forget the exact details, but double check that the sequence of files/arguments you input gives a valid tarball result. Probably a good idea to always do this when creating an archive, actually.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.