This page follows deb(5) and deb-old(5) from dpkg. The
format has been used since Debian 0.93. Its media type is
application/vnd.debian.binary-package (formerly
application/x-debian-package or application/x-deb). What goes
inside the control archive is on the control
files page.
The ar container
A .deb is an ar archive in the common
format only, without the long file name extensions. The file starts with the 8 bytes
!<arch>\n (21 3C 61 72 63 68 3E 0A); each member is a
60-byte header followed by its data, padded with one \n to an even
length.
| Offset | Size | Field | Contents |
|---|---|---|---|
0 | 16 | name | Member name, padded with spaces; an optional trailing / is allowed, which limits names to 15 characters. |
16 | 12 | date | Modification time, decimal seconds since 1970. |
28 | 6 | owner | User ID, decimal. |
34 | 6 | group | Group ID, decimal. |
40 | 8 | mode | File mode, octal. |
48 | 10 | size | Data size, decimal; ten digits limit a member to 9,999,999,999 bytes (about 9536.74 MiB). |
58 | 2 | end | `\n (60 0A). |
Members
The members must come in this order. Programs should ignore any member after
data.tar, and should stop on an unexpected member anywhere else.
| Order | Name | Contents |
|---|---|---|
| 1 | debian-binary | The format version as newline-terminated lines; today one line, 2.0. Readers accept a higher minor number and extra lines, ignoring them; a different major number is an incompatible format, so the program stops. |
| — | _name | Optional extension members, which older programs ignore, go here, between debian-binary and control.tar, with names starting with an underscore. |
| 2 | control.tar, .tar.gz, .tar.xz, .tar.zst | The control archive: control and the other control files, as plain files at its root; it may also have an entry for .. |
| 3 | data.tar and the suffixes below | The files to install, as a tar archive of the filesystem, for the target system. |
A new member that older programs cannot safely ignore must not start with an
underscore and goes before data.tar; or the change raises the major
version.
Compression
| Suffix | Compression | control.tar since dpkg | data.tar since dpkg |
|---|---|---|---|
| none | Uncompressed | 1.17.6 | 1.10.24 |
.gz | gzip | Always | Always |
.xz | xz | 1.17.6 | 1.15.6 |
.zst | Zstandard | 1.21.18 | 1.21.18 |
.bz2 | bzip2 | — | 1.10.24 |
.lzma | LZMA (legacy) | — | 1.13.25 |
Each member’s compression is chosen separately and shown by its suffix.
Tar rules
Both archives are tar files in one of: the old v7 format, pre-POSIX ustar, a subset of the GNU format, or POSIX ustar. A type flag dpkg does not know is an error.
| Feature | Since dpkg |
|---|---|
GNU long path and link names (L and K entries) | 1.4.1.17 |
POSIX ustar long names (the prefix field) | 1.15.0 |
| GNU large-number (base-256) fields: sizes to 95 bits, negative times, 63-bit user, group and device numbers | 1.18.24 |
Without the base-256 extension, a member’s size is limited to 11 octal digits (8 GiB).
Worked example
The first 72 bytes of every new-format package:
| Offset | Bytes | Meaning |
|---|---|---|
0 | !<arch>\n | ar magic |
8 | debian-binary␣␣␣ | Name, 16 bytes |
24 | 1700000000␣␣ | Date (example), 12 bytes |
36 | 0␣␣␣␣␣ | Owner |
42 | 0␣␣␣␣␣ | Group |
48 | 100644␣␣ | Mode |
56 | 4␣␣␣␣␣␣␣␣␣ | Size: 4 bytes of data |
66 | `\n | Header end |
68 | 2.0\n | The data; even length, so no padding |
72 | control.tar.xz␣␣… | Next member header |
(␣ stands for a space. The date, owner, group and mode values are
examples; the field widths come from the common ar header, described on the
ar pages.)
The old format (before Debian 0.93)
Not an ar archive: two ASCII lines each ending in \n, then two gzipped tar
files back to back.
- The format version padded to 8 digits: always
0.939000. - The size in bytes of the first gzipped tar, in decimal without leading zeros.
- The control archive (gzipped tar), which must contain
control; in very old packages the files may be in aDEBIANfolder inside it, and there may be an entry for.. - The data archive (gzipped ustar), paths relative to the root without a leading slash.
Sources
dpkg manual pages deb(5) (container, members, compression and tar rules
with dpkg versions, extension members, media types) and deb-old(5) (old
format), dpkg 1.23. The ar header layout is the common ar format; see the site’s
ar pages and their sources.