As a Debian system administrator, you will routinely handle .deb packages, since they contain consistent functional units (applications, documentation, etc.), whose installation and maintenance they facilitate. It is therefore a good idea to know what they are and how to use them.

This chapter describes the structure and contents of “binary” and “source” packages. The former are .deb files, directly usable by dpkg, while the latter contain the source code, as well as instructions for building binary packages.

5.1. Structure of a Binary Package

The Debian package format is designed so that its content may be extracted on any Unix system that has the classic commands ar, tar, and gzip (sometimes xz or bzip2). This seemingly trivial property is important for portability and disaster recovery.

Imagine, for example, that you mistakenly deleted the dpkg program, and that you could thus no longer install Debian packages. dpkg being a Debian package itself, it would seem your system would be done for... Fortunately, you know the format of a package and can therefore download the .deb file of the dpkg package and install it manually (see sidebar TOOLSdpkg, APT and ar). If by some misfortune one or more of the programs ar, tar or gzip/xz/bzip2 have disappeared, you will only need to copy the missing program from another system (since each of these operates in a completely autonomous manner, without dependencies, a simple copy will suffice). If your system suffered some even more outrageous fortune, and even these don't work (maybe the deepest system libraries are missing?), you should try the static version of busybox (provided in the busybox-static package), which is even more self-contained, and provides subcommands such as busybox ar, busybox tar and busybox gunzip.

TOOLSdpkg, APT and ar

dpkg is the program that handles .deb files, notably extracting, analyzing, and unpacking them.

APT is a group of programs that allows the execution of higher-level modifications to the system: installing or removing a package (while keeping dependencies satisfied), updating the system, listing the available packages, etc.

As for the ar program, it allows handling files of the same name: ar t archive displays the list of files contained in such an archive, ar x archive extracts the files from the archive into the current working directory, ar d archivefile deletes a file from the archive, etc. Its man page (ar(1)) documents all its other features. ar is a very rudimentary tool that a Unix administrator would only use on rare occasions, but admins routinely use tar, a more evolved archive and file management program. This is why it is easy to restore dpkg in the event of an erroneous deletion. You would only have to download the Debian package and extract the content from the data.tar.gz archive in the system's root (/):

# ar x dpkg_1.17.23_amd64.deb# tar -C / -p -xzf data.tar.gz

BACK TO BASICS Man page notation

It can be confusing for beginners to find references to “ar(1)” in the literature. This is generally a convenient means of referring to the man page entitled ar in section 1.

Sometimes this notation is also used to remove ambiguities, for example to distinguish between the printf command that can also be indicated by printf(1) and the printf function in the C programming language, which can also be referred to as printf(3).

As you can see, the ar archive of a Debian package is comprised of three files:

debian-binary. This is a text file which simply indicates the version of the .deb file used (in 2015: version 2.0).

control.tar.gz. This archive file contains all of the available meta-information, like the name and version of the package. Some of this meta-information allows package management tools to determine if it is possible to install or uninstall it, for example according to the list of packages already on the machine.

data.tar.gz. This archive contains all of the files to be extracted from the package; this is where the executable files, documentation, etc., are all stored. Some packages may use other compression formats, in which case the file will be named differently (data.tar.bz2 for bzip2, data.tar.xz for XZ).