Chapter 2. dpkg-deb and .deb file internals
Prev |  | Next

# Chapter 2. dpkg-deb and .deb file internals

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.

## 2.1. The .deb archive format

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.

## 2.2. The dpkg-deb command-line

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

### 2.2.1. Internal checks used by dpkg-deb when building packages

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

- First, the output Debian archive argument, if it is given, is checked using stat. If it is a directory, an internal flag is set. This check is only made if the archive name is specified explicitly on the command-line. If the argument was not given, the default is the directory name, with ".deb" appended.

- Next, the control file is checked, unless the --nocheck flag was specified on the command-line. dpkg-deb will bomb out if the second argument to --build was a directory, and --nocheck was specified. Note that dpkg-deb will not be able to determine the name of the package in this case. In the control file, the following things are checked:-

  - The package name is checked to see if it contains any invalid characters (see Section 1.1, “Control files” for this).

  - The priority field is checked to see if it uses standard values, and user-defined values are warned against. However, note that this check is now redundant, since the control file no longer contains the priority - the changes file now does this.

  - The control file fields are then checked against the standard list of fields which appear in control files, and any "user-defined" fields are reported as warnings.

  - dpkg-deb then checks that the control file contains a valid version number.

- After this, in the case where a directory was specified to build the .deb file in, the filename is created as "directory/pkg_ver.deb" or "directory/pkg_ver_arch.deb", depending on whether the control file contains an architecture field.

- Next, dpkg-deb checks for the <dir>/DEBIAN directory. It complains if it doesn't exist, or if it has permissions < 0755, or > 0775.

- It then checks that all the files in this subdir are either symlinks or plain files, and have permissions between 0555 and 0775.

- The conffiles file is then checked to see if the filenames are too long. Warnings are produced for each that is. After this, it checks that the package provides initial copies of each of these conffiles, and that they are all plain files.

Prev |  | Next
Chapter 1. Quick summary of dpkg's external interface | Home | Chapter 3. dpkg internals