Chapter 2. dpkg-deb and .deb file internals

Table of Contents

2.1. The .deb archive format
2.2. The dpkg-deb command-line

This chapter describes the internals to the "dpkg-deb" tool, which is used by "dpkg" as a back-end. dpkg-deb has its own tar extraction functions, which is the source of many problems, as it does not support long filenames, using extension blocks.

The main principal of the new-format Debian archive (I won't describe the old format - for that have a look at deb-old.5), is that the archive really is an archive - as used by "ar" and friends. However, dpkg-deb uses this format internally, rather than calling "ar". Inside this archive, there are usually the following members:-

  • debian-binary

  • control.tar.gz

  • data.tar.gz

The debian-binary member consists simply of the string "2.0", indicating the format version. control.tar.gz contains the control files (and scripts), and the data.tar.gz contains the actual files to populate the filesystem with. Both tarfiles extract straight into the current directory. Information on the tar formats can be found in the GNU tar info page. Since dpkg-deb calls "tar -cf" to build packages, the Debian packages use the GNU extensions.

dpkg-deb documents itself thoroughly with its '--help' command-line option. However, I am including a reference to these for completeness. dpkg-deb supports the following options:-

  • --build (-b) <dir> - builds a .deb archive, takes a directory which contains all the files as an argument. Note that the directory <dir>/DEBIAN will be packed separately into the control archive.

  • --contents (-c) <debfile> - Lists the contents of the "data.tar.gz" member.

  • --control (-e) <debfile> - Extracts the control archive into a directory called DEBIAN. Alternatively, with another argument, it will extract it into a different directory.

  • --info (-I) <debfile> - Prints the contents of the "control" file in the control archive to stdout. Alternatively, giving it other arguments will cause it to print the contents of those files instead.

  • --field (-f) <debfile> <field> ... - Prints any number of fields from the "control" file. Giving it extra arguments limits the fields it prints to only those specified. With no command-line arguments other than a filename, it is equivalent to -I and just the .deb filename.

  • --extract (-x) <debfile> <dir> - Extracts the data archive of a debian package under the directory <dir>.

  • --vextract (-X) <debfile> <dir> - Same as --extract, except it is equivalent of giving tar the '-v' option - it prints the filenames as it extracts them.

  • --fsys-tarfile <debfile> - This option outputs a gunzip'd version of data.tar.gz to stdout.

  • --new - sets the archive format to be used to the new Debian format

  • --old - sets the archive format to be used to the old Debian format

  • --debug - Tells dpkg-deb to produce debugging output

  • --nocheck - Tells dpkg-deb not to check the sanity of the control file

  • --help (-h) - Gives a help message

  • --version - Shows the version number

  • --licence/--license (UK/US spellings) - Shows a brief outline of the GPL

Here is a list of the internal checks used by dpkg-deb when building packages. It is in the order they are done.