Product SiteDocumentation Site

第 5 章 包管理系统:工具和基本原则

5.1. 二进制包的结构
5.2. 软件包元信息
5.2.1. 描述:control 文件
5.2.2. 配置脚本
5.2.3. 校验,配置文件列表
5.3. 源软件包的结构
5.3.1. 格式
5.3.2. Debian 中的使用
5.4. 通过dpkg来操作软件包
5.4.1. 安装软件包
5.4.2. 软件包移除
5.4.3. 查询 dpkg 的数据库,并检查 .deb 文件
5.4.4. dpkg的日志文件
5.4.5. 多架构支持
5.5. 与其它软件包共存
作为 Debian 系统管理员,你经常地要处理 .deb 包,因为它们包含一致的功能单元(应用程序、文档等),使得安装和维护更容易。所以了解它们是什么及如何使用它们是个好主意。
本章介绍了“二进制”和“源码”包的结构和内容。前者是 .deb 文件,可以用 dpkg 命令直接处理;而后者则包含程序的源代码,以及创建二进制包的说明。

5.1. 二进制包的结构

The Debian package format is designed so that its content may be extracted on any Unix system that has the classic commands ar, tar, and xz (sometimes gzip or bzip2). This seemingly trivial property is important for portability and disaster recovery.
Imagine, for example, that you mistakenly deleted the dpkg program, and that you could thus no longer install Debian packages. dpkg being a Debian package itself, it would seem your system would be done for... Fortunately, you know the format of a package and can therefore download the .deb file of the dpkg package and install it manually (see sidebar 工具 dpkgAPTar). If by some misfortune one or more of the programs ar, tar or gzip/xz/bzip2 have disappeared, you will only need to copy the missing program from another system (since each of these operates in a completely autonomous manner, without dependencies, a simple copy will suffice). If your system suffered some even more outrageous fortune, and even these don't work (maybe the deepest system libraries are missing?), you should try the static version of busybox (provided in the busybox-static package), which is even more self-contained, and provides subcommands such as busybox ar, busybox tar and busybox xz.
来看看 .deb 文件的内容:
$ ar t dpkg_1.18.24_amd64.deb
debian-binary
control.tar.gz
data.tar.xz
$ ar x dpkg_1.18.24_amd64.deb
$ ls
control.tar.gz  data.tar.xz  debian-binary  dpkg_1.18.24_amd64.deb
$ tar tJf data.tar.xz | head -n 15
./
./etc/
./etc/alternatives/
./etc/alternatives/README
./etc/cron.daily/
./etc/cron.daily/dpkg
./etc/dpkg/
./etc/dpkg/dpkg.cfg
./etc/dpkg/dpkg.cfg.d/
./etc/logrotate.d/
./etc/logrotate.d/dpkg
./sbin/
./sbin/start-stop-daemon
./usr/
./usr/bin/
$ tar tzf control.tar.gz
./
./conffiles
./postinst
./md5sums
./prerm
./control
./postrm
$ cat debian-binary
2.0
如你所见, Debian 包的 ar 存档格式由三个文件组成:
  • debian-binary. This is a text file which simply indicates the version of the .deb file used (in 2017: version 2.0).
  • control.tar.gz。这个归档文件包含所有可用的元信息,如软件包的名称和版本。有些包的元信息允许软件包管理工具来决定能否安装或卸载它。例如,软件包管理工具会根据机器上已有的软件包列表和软件包元信息来进行相关安装或卸载的操作。
  • data.tar.xz. This archive contains all of the files to be extracted from the package; this is where the executable files, documentation, etc., are all stored. Some packages may use other compression formats, in which case the file will be named differently (data.tar.bz2 for bzip2, data.tar.gz for gzip).