【Debian管理员手册】第 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 包,因为它们包含一致的功能单元(应用程序、文档等),使得安装和维护更容易。所以了解它们是什么及如何使用它们是个好主意。 This chapter describes the structure and contents of “binary” and “source” packages. The former are files directly usable by
dpkg, while the latter contain the source code, as well as instructions for building binary packages.

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 or 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
工具
dpkg
APT
ar). 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.
In case of a misfortune you better also have a backup of your system (see 第 9.10 节 “备份”).

工具 dpkgAPTar

dpkg is the program that handles
.deb files (binary packages), notably extracting, analyzing, and unpacking them. APT (the abbreviation of “Advanced Packaging Tool”) is a group of programs that allows the execution of higher-level modifications to the system: installing or removing a package (while keeping dependencies satisfied), updating and upgrading the system, listing the available packages, etc. As for the
ar program, it allows handling files of the same name:
ar t archive displays the list of files contained in such an archive,
ar x archive extracts the files from the archive into the current working directory,
ar d archive file deletes a file from the archive, etc. Its man page (
ar(1)) documents all its other features.
ar is a very rudimentary tool that a Unix administrator would only use on rare occasions, but admins routinely use
tar, a more evolved archive and file management program. This is why it is easy to restore
dpkg in the event of an erroneous deletion. You would only have to download the Debian package and extract the content from the
data.tar.xz archive in the system’s root (
/):

# ar x dpkg_1.19.7_amd64.deb
# tar -C / -p -xJf data.tar.xz

基础知识 Man 手册注记

初学者可能会在看到“
ar(1)”这样的文字注记时感到疑惑。这通常是个简写,它表示指向 man 手册第一类中标题是
ar 的页面。 有时这种注记也用来避免歧义,比如要区分清楚是
printf 命令,可以用
printf(1) 来指明,如果是 C 语言里的
printf 函数,就可以用
printf(3) 来引用。 第 7 章
问题的解决与相关信息的检索 更详细地讨论手册页 (参见 第 7.1.1 节 “手册页面”)。 来看看
.deb 文件的内容:

$ ar t dpkg_1.19.7_amd64.deb
debian-binary
control.tar.gz
data.tar.xz
$ ar x dpkg_1.19.7_amd64.deb
$ ls
control.tar.gz  data.tar.xz  debian-binary  dpkg_1.19.7_amd64.deb
$ tar tJf data.tar.xz | head -n 16
./
./
./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/alternatives
./etc/logrotate.d/dpkg
./sbin/
./sbin/start-stop-daemon
./usr/
./usr/bin/
$ tar tJf control.tar.xz
./
./conffiles
./control
./md5sums
./postinst
./postrm
$ cat debian-binary
2.0

如你所见, Debian 包的
ar 存档格式由三个文件组成:

debian-binary
This is a text file which simply indicates the version of the
.deb file package format version. In Debian
Buster it is still version 2.0.
control.tar.xz
This archive file contains all of the available meta-information, like the name and version of the package as well as some scripts to run before, during or after (un-)installation of it. Some of the meta-information allows package management tools to determine if it is possible to install or uninstall it, for example according to the list of packages already on the machine, and if files shipped have been modified locally.
data.tar.xz,
data.tar.bz2,
data.tar.gz
This archive contains all of the files to be extracted from the package; this is where the executable files, libraries, documentation, etc., are all stored. Packages may use different compression formats, in which case the file will be named differently for
xz,
bzip2 or
gzip.

原创文章,作者:晴川运维,如若转载,请注明出处:https://baike.qcidc.com/4006.html

(0)
晴川运维晴川运维
上一篇 2025年6月4日
下一篇 2025年6月4日

相关推荐

  • 【Debian GNU/Linux 安装手册】4.2. 从 Debian 镜像服务器下载文件

    4.2. 从 Debian 镜像服务器下载文件 选择离您较近的(因此很可能也是最快的)镜像服务器,请参见 Debian 镜像列表。 4.2.1. 在哪里能找到安…

    Debian 2025年6月8日
  • Linux下使用SSHFS挂载远程文件系统

    SSHFS是一个通过SSH连接到服务器的网络文件系统客户端。SSHFS允许您使用SFTP挂载远程文件系统。大多数VPS SSH服务器默认情况下都支持并启用此SFTP访问,因此SSH…

    Debian 2025年6月8日
  • 【Debian GNU/Linux 安装手册】A.3. 安装

    A.3. 安装 一旦安装程序运行,会有一个初始画面迎接您。按 Enter 启动系统;或者先阅读一下其它的启动方式以及各种参数的说明(参阅第 5.3 节…

    Debian 2025年6月8日
  • Linux下安装并使用netstat命令

    Netstat命令用于显示协议统计数据和当前TCP/IP网络的连接相关信息。很多时候我们需要查看自己的电脑某些网络端口是否被正常打开或者是否已经成功与别的机器建立连接,或者想看一些…

    Debian 2025年6月8日
  • Linux中MAC 地址欺骗具体方法

    MAC地址欺骗(或MAC地址盗用)通常用于突破基于MAC地址的局域网访问控制,例如在交换机上限定只转发源MAC地址修改为某个存在于访问列表中的MAC地址即可突破该访问限制,而且这种…

    Debian 2025年6月17日
  • Linux查看内存版本具体方法

    Linux内核版本命名在不同时期有着不同的规范,在涉及到Linux版本问题时经常容易混淆,主线版本/稳定版/长期支持版本经常搞不清楚,下面大家详细讲解一下查看Linux内核版本具体…

    Debian 2025年6月8日
  • Ansible 剧本快速入门指南

    我们已经写了两篇关于 Ansible 的文章,这是第三篇。 如果你是 Ansible 新手,我建议你阅读下面这两篇文章,它会教你一些 Ansible 的基础以及它是什么。 第一篇:…

    Debian 2025年6月13日
  • Linux下修改hostname的三种方法

    Linux操作系统的hostname是一个kernel变量,可以通过hostname命令来查看本机的hostname。也可以直接cat /proc/sys/kernel/hostn…

    Debian 2025年6月10日
  • Linux下使用ACL备份及恢复文件权限

    ACL的全称是 Access Control List (访问控制列表) ,一个针对文件/目录的访问控制列表。它在UGO权限管理的基础上为文件系统提供一个额外的、更灵活的权限管理机…

    Debian 2025年6月9日
  • 如何在 Ubuntu 以及 Debian 中安装 DHCP 服务器

    动态主机配置协议(DHCP) 是一种用于使主机能够从服务器自动分配 IP 地址和相关的网络配置的网络协议。 DHCP 服务器分配给 DHCP 客户端的 IP 地址处于“租用”状态,…

    Debian 2025年6月4日

发表回复

登录后才能评论