Working with Debian binary packages

Posted by Steve on Sun 27 Mar 2005 at 18:11

The Debian distribution is one which is based upon binary packages, which are built from by developers from source, and then uploaded into the archive and mirrors. Obtaining the source code which is used to build packages is very simple - but sometimes you might want to work with the binary packages.

The Debian binary format is very simple, it is nothing more complex than an archive produced using the ar tool containing two files:

  • data.tar.gz
    • This archive is contains the binaries/manpages/whatever which the package is going to install.
  • control.tar.gz
    • This archive contains book-keeping information and information about the package. Along with scripts which run as part of the installation/removal process.

If you have the binary .deb file for a given package you can unpack it's contents in two ways, using ar or using the dpkg command.

The second method is simplest:

skx@mystery:~$ dpkg -x komi_1.03-1_i386.deb tmp
skx@mystery:~$ ls tmp/
usr  var

As you can see we've extracted the contents of the komi package into the directory tmp, which now contains the package.

If you were sufficiently motivated you could "install" binary packages beneath your home directory by unpacking them and setting up your PATH appropriately.

Using ar to unpack the contents is almost as easy, first of all you need to unpack the two .tar.gz files:

skx@mystery:~$ ar -x komi_1.03-1_i386.deb control.tar.gz
skx@mystery:~$ ar -x komi_1.03-1_i386.deb data.tar.gz

Once this has been done you can list the contents of the data file, by running:

skx@mystery:~$ tar -tzvf data.tar.gz
drwxr-xr-x root/root         0 2004-07-12 15:47:05 ./
drwxr-xr-x root/root         0 2004-07-12 15:47:04 ./usr/
drwxr-xr-x root/root         0 2004-07-12 15:47:05 ./usr/games/
-rwxr-xr-x root/root     69464 2004-07-12 15:47:05 ./usr/games/komi
drwxr-xr-x root/root         0 2004-07-12 15:47:04 ./usr/share/
drwxr-xr-x root/root         0 2004-07-12 15:47:03 ./usr/share/games/
.... snip ....

The contents of the control archive are interesting too:

skx@mystery:~$ tar -tzvf control.tar.gz
drwxr-xr-x root/root         0 2004-07-12 15:47:06 ./
-rwxr-xr-x root/root       173 2004-07-12 15:47:05 ./postinst
-rwxr-xr-x root/root       160 2004-07-12 15:47:05 ./postrm
-rw-r--r-- root/root      5472 2004-07-12 15:47:06 ./md5sums
-rw-r--r-- root/root       626 2004-07-12 15:47:06 ./control

Here you can see the some files, postinst is a script which runs post install. postrm is another script which runs post-remove. The control contains information about the package, dependencies etc, and the md5sums contains checksums of all the files in the data.tar.gz file.

If you wished you could make changes to the control file and repack the whole thing - this might be useful if you wish to force the installation of a package by removing a dependency, or performing similar magic.

ar is a pretty simple tool to work with, and is fully described in the fine manpage:

man ar

 

 


Posted by agi (80.58.xx.xx) on Mon 28 Mar 2005 at 07:52
If you just want to read/extract/whatever a file, or take a peek at the debian related files (control, md5sum, post*, pre*), you can also use 'mc' to navigate a Debian package.

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Mon 28 Mar 2005 at 17:21
[ View Steve's Scratchpad | View Weblogs ]

Good point, thanks.

I guess I should also have said that if you just want to see which files are inside a random package you can run:

dpkg --contents filename.deb

(Although that doesn't show you the control files, just the binaries/scripts/configuration files which are going to be installed).

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by ptecza (193.0.xx.xx) on Tue 29 Mar 2005 at 14:11
Hi Steve!

I think that single "dpkg -x" should be enough :)

My best regards!

P.

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Tue 29 Mar 2005 at 14:13
[ View Steve's Scratchpad | View Weblogs ]

Sure .. but it's fun to see how this stuff really works too!

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by ptecza (193.0.xx.xx) on Tue 29 Mar 2005 at 14:33
Do you mean `dpkg -x dpkg -x ...` command? What version
of dpkg does support it? It doesn't work on my Woody box:

$ mkdir tmp
$ LC_MESSAGES=en_US dpkg -x dpkg -x debian-updates_1.5-1_all.deb tmp/
dpkg-deb: --extract takes at most two arguments (.deb and directory)

Type dpkg-deb --help for help about manipulating *.deb files;
Type dpkg --help for help about installing and deinstalling packages.

P.

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Tue 29 Mar 2005 at 14:40
[ View Steve's Scratchpad | View Weblogs ]

D'oh I see what you mean.

You only need to run 'dpkg -x' not 'dpkg -x dpkg -x':

LC_MESSAGES=en_US dpkg -x debian-updates_1.5-1_all.deb tmp/ 

I've corrected the article now.

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by ptecza (83.24.xx.xx) on Tue 29 Mar 2005 at 19:08
I know it, but later I thought that is undocumented dpkg feature, not bug :)

P.

[ Parent | Reply to this comment ]

Posted by ptecza (83.24.xx.xx) on Wed 30 Mar 2005 at 20:06
Yo! :)

Today I've found unp by chance. This smart tool can also
unpack Debian package. See at [1] for more information.

1 - http://lists.debian.org/debian-sparc/2004/01/msg00151.html

Regards!

P.

[ Parent | Reply to this comment ]

Posted by ptecza (193.0.xx.xx) on Tue 10 May 2005 at 08:18
is available now at http://www.debianusers.pl/article.php?aid=76.

Thanks a lot for useful article, Steve!

My best regards!

P.

[ Parent | Reply to this comment ]

Posted by bdf (134.184.xx.xx) on Mon 19 Dec 2005 at 09:49
ar and tar can list and output their contents to stdout. By chaining them with the pipe operator (|), it becomes easier to work with the tar.gz-inside-ar file.

For example, the following sequence inspects the contents of a binary package, without leaving any files behind:
DEB=/var/cache/apt/archives/curl_7.13.2-2sarge4_i386.deb
ar t $DEB
ar p $DEB debian-binary
ar p $DEB data.tar.gz | tar -zt
ar p $DEB control.tar.gz | tar -zt
ar p $DEB control.tar.gz | tar -zxO ./control
ar p $DEB control.tar.gz | tar -zxO ./md5sums

[ Parent | Reply to this comment ]

Posted by Anonymous (189.135.xx.xx) on Sun 3 Sep 2006 at 19:27

Thanks for this article, it greatly helps me to understand the basics of binary packages. A sugestion:

If you wished you could make changes to the control file and repack the whole thing - this might be useful if you wish to force the installation of a package by removing a dependency, or performing similar magic.

That's exactly what I want to do... But I cant't find how. I guess there's a very simple way to do it. It would be great if this article could give this information.

Franck.

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 228 votes ~ 0 comments )