1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!-- -*- DocBook -*- -->
3 <!DOCTYPE book PUBLIC
"-//OASIS//DTD DocBook XML V4.5//EN"
4 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
5 <!ENTITY % aptverbatiment SYSTEM
"apt-verbatim.ent"> %aptverbatiment;
10 <title>dpkg technical manual
</title>
16 <personname>Tom Lees
</personname><email>tom@lpsg.demon.co.uk
</email>
20 <releaseinfo>Version &apt-product-version;
</releaseinfo>
24 This document describes the minimum necessary workings for the APT dselect
25 replacement. It gives an overall specification of what its external interface
26 must look like for compatibility, and also gives details of some internal
31 <copyright><year>1997</year><holder>Tom Lees
</holder></copyright>
34 <title>License Notice
</title>
36 APT and this document are free software; you can redistribute them and/or
37 modify them under the terms of the GNU General Public License as published by
38 the Free Software Foundation; either version
2 of the License, or (at your
39 option) any later version.
42 For more details, on Debian systems, see the file
43 /usr/share/common-licenses/GPL for the full license.
49 <chapter id=
"ch1"><title>Quick summary of dpkg's external interface
</title>
51 <section id=
"control"><title>Control files
</title>
53 The basic dpkg package control file supports the following major features:-
58 5 types of dependencies:-
63 Pre-Depends, which must be satisfied before a package may be unpacked
68 Depends, which must be satisfied before a package may be configured
73 Recommends, to specify a package which if not installed may severely limit the
74 usefulness of the package
79 Suggests, to specify a package which may increase the productivity of the
85 Conflicts, to specify a package which must NOT be installed in order for the
86 package to be configured
91 Breaks, to specify a package which is broken by the package and which should
92 therefore not be configured while broken
97 Each of these dependencies can specify a version and a depedency on that
98 version, for example "
<=
0.5-
1", "==
2.7.2-
1", etc. The comparators
104 "
<<" - less than
109 "
<=" - less than or equal to
114 "
>>" - greater than
119 "
>=" - greater than or equal to
131 The concept of "virtual packages", which many other packages may provide,
132 using the Provides mechanism. An example of this is the "httpd" virtual
133 package, which all web servers should provide. Virtual package names may be
134 used in dependency headers. However, current policy is that virtual packages
135 do not support version numbers, so dependencies on virtual packages with
136 versions will always fail.
141 Several other control fields, such as Package, Version, Description, Section,
142 Priority, etc., which are mainly for classification purposes. The package
143 name must consist entirely of lowercase characters, plus the characters '+',
144 '-', and '.'. Fields can extend across multiple lines - on the second and
145 subsequent lines, there is a space at the beginning instead of a field name
146 and a ':'. Empty lines must consist of the text " .", which will be ignored,
147 as will the initial space for other continuation lines. This feature is
148 usually only used in the Description field.
154 <section id=
"s1.2"><title>The dpkg status area
</title>
156 The "dpkg status area" is the term used to refer to the directory where dpkg
157 keeps its various status files (GNU would have you call it the dpkg shared
158 state directory). This is always, on Debian systems, /var/lib/dpkg. However,
159 the default directory name should not be hard-coded, but #define'd, so that
160 alteration is possible (it is available via configure in dpkg
1.4.0.9 and
161 above). Of course, in a library, code should be allowed to override the
162 default directory, but the default should be part of the library (so that
163 the user may change the dpkg admin dir simply by replacing the library).
166 Dpkg keeps a variety of files in its status area. These are discussed later
167 on in this document, but a quick summary of the files is here:-
172 available - this file contains a concatenation of control information from all
173 the packages which dpkg knows about. This is updated using the dpkg commands
174 "--update-avail
<file
>", "--merge-avail
<file
>", and
180 status - this file contains information on the following things for every
186 Whether it is installed, not installed, unpacked, removed, failed
187 configuration, or half-installed (deconfigured in favour of another package).
192 Whether it is selected as install, hold, remove, or purge.
197 If it is "ok" (no installation problems), or "not-ok".
202 It usually also contains the section and priority (so that dselect may classify
203 packages not in available)
208 For packages which did not initially appear in the "available" file when they
209 were installed, the other control information for them.
214 The exact format for the "Status:" field is:
217 Status: Want Flag Status
220 Where
<replaceable>Want
</replaceable> may be one of
221 <emphasis>unknown
</emphasis>,
<emphasis>install
</emphasis>,
222 <emphasis>hold
</emphasis>,
<emphasis>deinstall
</emphasis>,
223 <emphasis>purge
</emphasis>.
<replaceable>Flag
</replaceable> may
224 be one of
<emphasis>ok
</emphasis>,
<emphasis>reinstreq
</emphasis>,
225 <emphasis>hold
</emphasis>,
226 <emphasis>hold-reinstreq
</emphasis>.
<replaceable>Status
</replaceable> may
227 be one of
<emphasis>not-installed
</emphasis>,
<emphasis>unpacked
</emphasis>,
228 <emphasis>half-configured
</emphasis>,
<emphasis>installed
</emphasis>,
229 <emphasis>half-installed
</emphasis> <emphasis>config-files
</emphasis>,
230 <emphasis>post-inst-failed
</emphasis>,
<emphasis>removal-failed
</emphasis>.
231 The states are as follows:-
235 <term>not-installed
</term>
238 No files are installed from the package, it has no config files left, it
239 uninstalled cleanly if it ever was installed.
244 <term>unpacked
</term>
247 The basic files have been unpacked (and are listed in
248 /var/lib/dpkg/info/[package].list. There are config files present, but the
249 postinst script has _NOT_ been run.
254 <term>half-configured
</term>
257 The package was installed and unpacked, but the postinst script failed in some
263 <term>installed
</term>
266 All files for the package are installed, and the configuration was also
272 <term>half-installed
</term>
275 An attempt was made to remove the packagem but there was a failure in the
281 <term>config-files
</term>
284 The package was "removed", not "purged". The config files are left, but
290 <term>post-inst-failed
</term>
293 Old name for half-configured. Do not use.
298 <term>removal-failed
</term>
301 Old name for half-installed. Do not use.
307 The two last items are only left in dpkg for compatibility - they are
308 understood by it, but never written out in this form.
311 Please see the dpkg source code,
<literal>lib/parshelp.c
</literal>,
312 <emphasis>statusinfos
</emphasis>,
<emphasis>eflaginfos
</emphasis> and
313 <emphasis>wantinfos
</emphasis> for more details.
318 info - this directory contains files from the control archive of every
319 package currently installed. They are installed with a prefix of
320 "
<packagename
>.". In addition to this, it also contains a file
321 called
<package
>.list for every package, which contains a list
322 of files. Note also that the control file is not copied into here; it
323 is instead found as part of status or available.
328 methods - this directory is reserved for "method"-specific files - each
329 "method" has a subdirectory underneath this directory (or at least,
330 it can have). In addition, there is another subdirectory "mnt", where
331 misc. filesystems (floppies, CD-ROMs, etc.) are mounted.
336 alternatives - directory used by the "update-alternatives" program. It
337 contains one file for each "alternatives" interface, which contains
338 information about all the needed symlinked files for each alternative.
343 diversions - file used by the "dpkg-divert" program. Each diversion takes
344 three lines. The first is the package name (or ":" for user diversion), the
345 second the original filename, and the third the diverted filename.
350 updates - directory used internally by dpkg. This is discussed later, in the
351 section
<xref linkend=
"updates"/>.
356 parts - temporary directory used by dpkg-split
362 <section id=
"s1.3"><title>The dpkg library files
</title>
364 These files are installed under /usr/lib/dpkg (usually), but
365 /usr/local/lib/dpkg is also a possibility (as Debian policy dictates). Under
366 this directory, there is a "methods" subdirectory. The methods subdirectory in
367 turn contains any number of subdirectories for each general method processor
368 (note that one set of method scripts can, and is, used for more than one of
369 the methods listed under dselect).
372 The following files may be found in each of these subdirectories:-
377 names - One line per method, two-digit priority to appear on menu at
378 beginning, followed by a space, the name, and then another space and
379 the short description.
384 desc.
<name
> - Contains the long description displayed by dselect
385 when the cursor is put over the
<name
> method.
390 setup - Script or program which sets up the initial values to be used
391 by this method. Called with first argument as the status area directory
392 (/var/lib/dpkg), second argument as the name of the method (as in the
393 directory name), and the third argument as the option (as in the names file).
398 install - Script/program called when the "install" option of dselect is run
399 with this method. Same arguments as for setup.
404 update - Script/program called when the "update" option of dselect is
405 run. Same arguments as for setup/install.
411 <section id=
"s1.4"><title>The "dpkg" command-line utility
</title>
413 <section id=
"s1.4.1"><title>"Documented" command-line interfaces
</title>
415 As yet unwritten. You can refer to the other manuals for now. See
416 <citerefentry><refentrytitle>dpkg
</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
420 <section id=
"s1.4.2"><title>Environment variables which dpkg responds to
</title>
424 DPKG_NO_TSTP - if set to a non-null value, this variable causes dpkg to run a
425 child shell process instead of sending itself a SIGTSTP, when the user selects
426 to background the dpkg process when it asks about conffiles.
431 SHELL - used to determine which shell to run in the case when DPKG_NO_TSTP
437 CC - used as the C compiler to call to determine the target architecture. The
443 PATH - dpkg checks that it can find at least the following files in the path
444 when it wants to run package installation scripts, and gives an error if it
445 cannot find all of them:-
473 <section id=
"s1.4.3"><title>Assertions
</title>
475 The dpkg utility itself is required for quite a number of packages, even if
476 they have been installed with a tool totally separate from dpkg. The reason
477 for this is that some packages, in their pre-installation scripts, check that
478 your version of dpkg supports certain features. This was broken from the
479 start, and it should have actually been a control file header "Dpkg-requires",
480 or similar. What happens is that the configuration scripts will abort or
481 continue according to the exit code of a call to dpkg, which will stop them
482 from being wrongly configured.
485 These special command-line options, which simply return as true or false are
486 all prefixed with "--assert-". Here is a list of them (without the prefix):-
491 support-predepends - Returns success or failure according to whether a version
492 of dpkg which supports predepends properly (
1.1.0 or above) is installed,
493 according to the database.
498 working-epoch - Return success or failure according to whether a version of
499 dpkg which supports epochs in version properly (
1.4.0.7 or above) is installed,
500 according to the database.
505 Both these options check the status database to see what version of the
506 "dpkg" package is installed, and check it against a known working version.
510 <section id=
"s1.4.4"><title>--predep-package
</title>
512 This strange option is described as follows in the source code:
515 /* Print a single package which:
516 * (a) is the target of one or more relevant predependencies.
517 * (b) has itself no unsatisfied pre-dependencies.
518 * If such a package is present output is the Packages file entry,
519 * which can be massaged as appropriate.
521 *
0 = a package printed, OK
522 *
1 = no suitable package available
527 On further inspection of the source code, it appears that what is does is
533 Looks at the packages in the database which are selected as "install",
539 It then looks at the Pre-Depends information for each of these packages
540 from the available file. When it find a package for which any of the
541 pre-dependencies are not satisfied, it breaks from the loop through the
547 It then looks through the unsatisfied pre-dependencies, and looks for
548 packages which would satisfy this pre-dependency, stopping on the first
549 it finds. If it finds none, it bombs out with an error.
554 It then continues this for every dependency of the initial package.
559 Eventually, it writes out the record of all the packages to satisfy the
560 pre-dependencies. This is used by the disk method to make sure that its
561 dependency ordering is correct. What happens is that all pre-depending
562 packages are first installed, then it runs dpkg -iGROEB on the directory,
563 which installs in the order package files are found. Since pre-dependencies
564 mean that a package may not even be unpacked unless they are satisfied, it
565 is necessary to do this (usually, since all the package files are unpacked
566 in one phase, the configured in another, this is not needed).
574 <chapter id=
"ch2"><title>dpkg-deb and .deb file internals
</title>
576 This chapter describes the internals to the "dpkg-deb" tool, which is used by
577 "dpkg" as a back-end. dpkg-deb has its own tar extraction functions, which is
578 the source of many problems, as it does not support long filenames, using
582 <section id=
"s2.1"><title>The .deb archive format
</title>
584 The main principal of the new-format Debian archive (I won't describe the old
585 format - for that have a look at deb-old
.5), is that the archive really is an
586 archive - as used by "ar" and friends. However, dpkg-deb uses this format
587 internally, rather than calling "ar". Inside this archive, there are usually
588 the following members:-
608 The debian-binary member consists simply of the string "
2.0", indicating
609 the format version. control.tar.gz contains the control files (and scripts),
610 and the data.tar.gz contains the actual files to populate the filesystem
611 with. Both tarfiles extract straight into the current directory. Information
612 on the tar formats can be found in the GNU tar info page. Since dpkg-deb
613 calls "tar -cf" to build packages, the Debian packages use the GNU extensions.
617 <section id=
"s2.2"><title>The dpkg-deb command-line
</title>
619 dpkg-deb documents itself thoroughly with its '--help' command-line
620 option. However, I am including a reference to these for
621 completeness. dpkg-deb supports the following options:-
626 --build (-b)
<dir
> - builds a .deb archive, takes a directory which
627 contains all the files as an argument. Note that the directory
628 <dir
>/DEBIAN will be packed separately into the control archive.
633 --contents (-c)
<debfile
> - Lists the contents of the "data.tar.gz"
639 --control (-e)
<debfile
> - Extracts the control archive into a directory
640 called DEBIAN. Alternatively, with another argument, it will extract it into a
646 --info (-I)
<debfile
> - Prints the contents of the "control" file in the
647 control archive to stdout. Alternatively, giving it other arguments will cause
648 it to print the contents of those files instead.
653 --field (-f)
<debfile
> <field
> ... - Prints any number of fields
654 from the "control" file. Giving it extra arguments limits the fields it prints
655 to only those specified. With no command-line arguments other than a filename,
656 it is equivalent to -I and just the .deb filename.
661 --extract (-x)
<debfile
> <dir
> - Extracts the data archive of a
662 debian package under the directory
<dir
>.
667 --vextract (-X)
<debfile
> <dir
> - Same as --extract, except it
668 is equivalent of giving tar the '-v' option - it prints the filenames as it
674 --fsys-tarfile
<debfile
> - This option outputs a gunzip'd version of
675 data.tar.gz to stdout.
680 --new - sets the archive format to be used to the new Debian format
685 --old - sets the archive format to be used to the old Debian format
690 --debug - Tells dpkg-deb to produce debugging output
695 --nocheck - Tells dpkg-deb not to check the sanity of the control file
700 --help (-h) - Gives a help message
705 --version - Shows the version number
710 --licence/--license (UK/US spellings) - Shows a brief outline of the GPL
715 <section id=
"s2.2.1"><title>Internal checks used by dpkg-deb when building packages
</title>
717 Here is a list of the internal checks used by dpkg-deb when building
718 packages. It is in the order they are done.
723 First, the output Debian archive argument, if it is given, is checked using
724 stat. If it is a directory, an internal flag is set. This check is only made
725 if the archive name is specified explicitly on the command-line. If the
726 argument was not given, the default is the directory name, with ".deb"
732 Next, the control file is checked, unless the --nocheck flag was specified on
733 the command-line. dpkg-deb will bomb out if the second argument to --build was
734 a directory, and --nocheck was specified. Note that dpkg-deb will not be able
735 to determine the name of the package in this case. In the control file, the
736 following things are checked:-
741 The package name is checked to see if it contains any invalid characters (see
742 <xref linkend=
"control"/> for this).
747 The priority field is checked to see if it uses standard values, and
748 user-defined values are warned against. However, note that this check is now
749 redundant, since the control file no longer contains the priority - the
750 changes file now does this.
755 The control file fields are then checked against the standard list of fields
756 which appear in control files, and any "user-defined" fields are reported as
762 dpkg-deb then checks that the control file contains a valid version number.
769 After this, in the case where a directory was specified to build the .deb file
770 in, the filename is created as "directory/pkg_ver.deb" or
771 "directory/pkg_ver_arch.deb", depending on whether the control file contains
772 an architecture field.
777 Next, dpkg-deb checks for the
<dir
>/DEBIAN directory. It complains if it
778 doesn't exist, or if it has permissions
< 0755, or
> 0775.
783 It then checks that all the files in this subdir are either symlinks or plain
784 files, and have permissions between
0555 and
0775.
789 The conffiles file is then checked to see if the filenames are too
790 long. Warnings are produced for each that is. After this, it checks
791 that the package provides initial copies of each of these conffiles,
792 and that they are all plain files.
802 <chapter id=
"ch3"><title>dpkg internals
</title>
804 This chapter describes the internals of dpkg itself. Although the low-level
805 formats are quite simple, what dpkg does in certain cases often does not make
809 <section id=
"updates"><title>Updates
</title>
811 This describes the /var/lib/dpkg/updates directory. The function of this
812 directory is somewhat strange, and seems only to be used internally. A
813 function called cleanupdates is called whenever the database is scanned. This
814 function in turn uses
815 <citerefentry><refentrytitle>scandir
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
816 to sort the files in this directory. Files who names do not consist entirely
817 of digits are discarded. dpkg also causes a fatal error if any of the
818 filenames are different lengths.
821 After having scanned the directory, dpkg in turn parses each file the same way
822 it parses the status file (they are sorted by the scandir to be in numerical
823 order). After having done this, it then writes the status information back to
824 the "status" file, and removes all the "updates" files.
827 These files are created internally by dpkg's "checkpoint" function, and are
828 cleaned up when dpkg exits cleanly.
831 Juding by the use of the updates directory I would call it a Journal. Inorder
832 to efficiently ensure the complete integrity of the status file dpkg will
833 "checkpoint" or journal all of it's activities in the updates directory. By
834 merging the contents of the updates directory (in order!!) against the original
835 status file it can get the precise current state of the system, even in the
836 event of a system failure while dpkg is running.
839 The other option would be to sync-rewrite the status file after each operation,
840 which would kill performance.
843 It is very important that any program that uses the status file abort if the
844 updates directory is not empty! The user should be informed to run dpkg
845 manually (what options though??) to correct the situation.
849 <section id=
"s3.2"><title>What happens when dpkg reads the database
</title>
851 First, the status file is read. This gives dpkg an initial idea of the
852 packages that are there. Next, the updates files are read in, overriding the
853 status file, and if necessary, the status file is re-written, and updates files
854 are removed. Finally, the available file is read. The available file is read
855 with flags which preclude dpkg from updating any status information from it,
856 though - installed version, etc., and is also told to record that the packages
857 it reads this time are available, not installed.
860 More information on updates is given above.
864 <section id=
"s3.3"><title>How dpkg compares version numbers
</title>
866 Version numbers consist of three parts: the epoch, the upstream version, and
867 the Debian revision. Dpkg compares these parts in that order. If the epochs
868 are different, it returns immediately, and so on.
871 However, the important part is how it compares the versions which are
872 essentially stored as just strings. These are compared in two distinct
873 parts: those consisting of numerical characters (which are evaluated, and
874 then compared), and those consisting of other characters. When comparing
875 non-numerical parts, they are compared as the character values (ASCII),
876 but non-alphabetical characters are considered "greater than" alphabetical
877 ones. Also note that longer strings (after excluding differences where
878 numerical values are equal) are considered "greater than" shorter ones.
881 Here are a few examples of how these rules apply:-