Debian-like Linux distributions use an APT-based package manager system. At this time, the APT package manager .deb
I'm using a file, but in this post .deb
Let's take a closer look at how the file is structured.
.deb
Internal components.deb
The file is generic UNIX AR
Archives It is a structure that follows a format. AR
An archive is a simple container format that groups multiple files together. .deb
In the case of, it must include the following three components:
Debian-binary
2.0
It contains only a string.control.tar
data.tar
Each component AR
Within the archive Debian-binary
→ control.tar
→ data.tar
They are arranged in order. This allows package tools such as dpkg .deb
Files can be interpreted and processed. Additionally, if the package includes a signature, there are additional steps, but since APT repositories are usually signed, I'll omit them in this article.
The control.tar archive contains the package's metadata and maintenance scripts.
control
md5sums
Conffiles
preinst
, Postinst
, Prerm
, Postrm
This includes the like. Dpkg/APT obtains the information needed to install packages through control.tar described above.
A package's maintenance script is a script that is automatically executed at a specific point in the installation and removal process to perform preparation or cleanup tasks required for the package's operation. Debian packages usually use 4 maintenance scripts.
preinst
(Pre-install)Postinst
(Post-install)Prerm
(Pre-Removal)Prerm
This will be called.Postrm
(Post-Removal)Postrm
Perform this cleanup procedure.Postrm
is called when an installation fails and is also used to clean up partial installation status. The above scripts can be applied selectively. Also, all scripts must have idempotency (idempotency) and be configured so that there are no problems even when executed multiple times.
Note: When upgrading a package, the scripts from the previous version and the new version are executed in combination. For example, during the upgrade process, the flow is called in the following order: previous version of prerm → new version of preinst → new version of unpacking files → new version of postinst → previous version of postrm. (It may vary depending on the specific situation, but broadly speaking, preinst runs before unpacking a new package, postinst runs after unpacking, and prerm runs before uninstalling, and postrm runs after uninstalling.)
Note: The following scripts are used in combination when upgrading packages.
old version of prerm → new version of preinst → new version of file unpacked → new version of postinst → old version of postrm
The data.tar archive is a data section containing all the files that are actually copied to the system when the package is installed. If you unpack this archive, it's like you've seen a lot . /usr/
, . /etc/
A directory structure such as is displayed, and the package's binaries, libraries, configuration files, and documents are included according to that structure.
For example, test
In a package called data.tar.gz
When I solved usr/bin/test
with an executable file usr/share/doc/test/...
Documents may appear. These paths are ultimately the system root (/
It will be installed based on). In other words, data.tar
inner . /usr/bin/test
The file is when the package is installed /usr/bin/test
It will be placed on the path.
data.tar
The permissions and owner information of the files included in are also stored, so dpkg interprets them and applies them to the system appropriately. For example, a binary file has permission to execute and the owner root
It is placed according to the metadata set by the package creator, such as being installed in the in-state.
usually data.tar
An archive is used to reduce capacity gzip
, xz
, zstd
It is compressed in the same way. (The Debian package standard allows compression of data archives.) In the old package data.tar.gz
There were many (gzip) formats, but most recent Debian/Ubuntu packages data.tar.xz
It uses the (xz) format, and some data.tar.zst
(zstd) is also used. Depending on the compression method, dpkg or APT can automatically release it.
Of Debian-based Linux distributions .deb
The file structure AR
It is organized based on an archive format. In detail Debian-binary
, control.tar
, data.tar
The three essential elements of are sequentially included, and by combining them, package metadata and actual deployment files can be organized and managed in one place. The above prerequisites help to automatically perform the tasks required during the installation, upgrade, and removal process.