Tidbits --- the Second Life of an Archive
Posted: 09/15/2009 Ron Scheckelhoff
Package archives: tbz, deb, pkg, gz, bz2, tgz, zip, ar, rpm ...
Every once in a while I find myself in need of a file or set of files that I know is contained within a binary package, and I want to extract just that particular file or files without installing the package. For some types of packages, the procedure might seem obvious (bunzip2 for FreeBSD packages, for instance). For others, the hint isn't built into the filename extension.
For a recent example, I had a personal need to listen to a particular audio clip using Realplayer1 on FreeBSD. The FreeBSD port for this has a restriction on it because you must get the player from the main Real-Networks1 site, and the player may not be redistributed. As with many restricted ports, there is often an issue having to do with the link to the original site (Real-Networks in this case) being out-of-date. The Real-Networks distribution site has a debian package for the player, and I decided that I would use it and run it under FreeBSD's Linux compatibility layer.
To extract the Debian package into a directory is a fairly simple process. Most folks don't realize it, but a Debian package is just an "ar" archive, and the tools needed to manipulate such a package are available on most *nix systems. To extract the files from a Debian archive, I simply execute a command that is something on the order of:
ar -x thepackagename.deb
On another occasion, I wanted to execute a Linux program (under FreeBSD's Linux emulation), but the program was included within an RPM archive (Redhat package manager) format. FreeBSD ports of linux programs commonly use RPM packages to obtain "source" files, but many people don't realize how easy it is to perform this task manually when using an operating system that does not have (by default) an RPM package manager.
The trick is to dump the contents of the RPM archive into a GNU cpio archive, and then extract the desired file from that archive.
The rpm2cpio package will not exist
within most default FreeBSD installations, so the package for it must usually be fetched and installed:
pkg_add -rK rpm2cpio
The use of the package is shown in the following example ...
Another trick may confound some users, and that is the use of the perl script extension that is not symlinked anywhere by the
"rpm2cpio" package installer...
rpm2cpio.pl ConsoleKit-libs-0.2.10-3.fc9.i386.rpm | cpio -idmv
./lib/security/pam_ck_connector.so
./usr/lib/libck-connector.so.0
./usr/lib/libck-connector.so.0.0.0
./usr/share/man/man8/pam_ck_connector.8.gz
38 blocks
Note that the last five lines constitute output that was printed by the utility ... lines that contain information about the extracted files ...
There is an RPM manipulation package for FreeBSD that will accomplish the same extraction goals (bsdtar), but the aforementioned approach seems more generic and cross-platform. The Perl script cpio utility may be a wrapper on bsdtar - I havn't checked to determine.
Some binary packages (Those in the NetBSD pkgsrc repository, for example) are simply gzipped tarballs with a single ".tgz" extension. Slackware binary packages also fall into this category. While it would be rare or never that a FreeBSD OS user would have a need for a NetBSD package, there have been times when this author has made use of special packages for such things as Python module libraries.
While Python module packages are not technically in the realm of "binary" packages, such things are distributed in the manner of a binary package, wherein the installed code is "executed" via the Python interpreter, and so the package does not serve the traditional purpose of a "source code" package.
It's been a while, and it seems that I used the cpio trick on some Sun Solaris packages that I was installing, but my memory is not crystal clear on this .... one might be advised to check this for veracity before attempting any extractions. Any others who have ideas for package manipulations are encouraged to put suggestions on the comments page, or send me an email.
For the curious, my Debian-archive-extracted music player works like a champ, albeit two Linux compatibility packages were required -- both the linux_base-fc4 and the linux_base-f8 packages. I am not the Linux-on-FreeBSD guru, but I believe that linux_base-f8 is an incomplete package, and it requires the fc4 package for certain things. This seems to be true, regardless of the base vs. non-base configuration settings. I must further note that, on FreeBSD 7.2, the Linuxulator2 worked best when I installed the fc4 package during the OS installation process, and the linux_base-f8 package from current ports. (Maybe something changed in the linux_base-fc4 package since I burned my FreeBSD 7.2 CDs?) To make my particular Linux program work, a number of additional linux based graphics libraries were needed.
It was also necessary to configure a few other details ...
echo 'linux_enable="yes"' >> rc.conf
echo "compat.linux.osrelease=2.6.16" >> /etc/sysctl.conf
echo "OVERRIDE_LINUX_BASE_PORT=f8" >> /etc/make.conf
echo "OVERRIDE_LINUX_NON_BASE_PORTS=f8" >> /etc/make.conf
cp fstab /etc/fstab
mkdir -p /usr/compat/linux/proc
mount /usr/compat/linux/proc
/etc/rc.d/abi start
/etc/rc.d/sysctl start
Note that there may be security ramifications associated with the use of the Linuxator, and with the foregoing configuration settings ...
Attribution: This site and it's authors have absolutely no affiliation with, and are not endorsed by Redhat, Sun Microsystems,
RealNetworks, FreeBSD, NetBSD, Linux, or
any other entities mentioned on this opinion page.
1Realplayer is copyright RealNetworks, and is not affiliated with this site ... See: http://www.real.com
2The Linuxulator is not to be confused with the Linuxator of the Linux World.
Note: The use of any of the information on these pages is entirely at the user's risk. No guarantee of accuracy is suggested or implied, and this information has been collated primarily for the use of Datazygte staff. The information is what it is, it is "as is", and nothing more. No license is given for redistribution or commercial use, and no use beyond the satisfaction of intellectual curiosity is expected. Neither the company nor the individual contributors may be held liable for any direct, indirect, or consequential damages, however caused, and on any theory of liability, arising out of or as a result of contact with any information on this site ...