【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 archivefile 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.debdebian-binary
control.tar.gz
data.tar.xz
$ ar x dpkg_1.19.7_amd64.deb$ lscontrol.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-binary2.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://shuyeidc.com/wp/221970.html<

(0)
管理的头像管理
上一篇2025-04-15 06:57
下一篇 2025-04-15 06:58

相关推荐

  • 站群服务器和普通服务器到底哪个更适合GEO,怎么选?

    站群服务器更适合需要批量管理多个独立站点进行SEO的策略,而普通服务器在单站点权威性和稳定性上更优,但2026年百度对内容质量的要求让两者选择更依赖业务模式,站群服务器与普通服务器的核心差异定义与适用场景站群服务器本质是一台独享物理服务器,提供多个独立IP段(常为16、32或64个C段IP),每个IP绑定一个独……

    2026-07-28
    0
  • 物理服务器和云服务器做站群到底选哪个,哪个更稳定?

    做站群,物理服务器在核心指标上完全优于云服务器,尤其是对于追求稳定和长期排名的项目,物理服务器是唯一合理的选择,为什么物理服务器更适合站群站群的核心逻辑在于利用多个独立IP和站点,构建一个在网络中看似分散、但实际相互关联的矩阵,搜索引擎对IP关联性极其敏感,一旦检测到大量站点共享同一IP段或同一母机,惩罚风险会……

    2026-07-28
    0
  • 国内高防服务器哪家防御真实靠谱,怎么选?

    国内高防服务器哪家防御真实靠谱?答案很明确:只有那些持证上岗、自建机房、自己掌握清洗算法的服务商才靠得住,简米科技和酷番云就是这类代表,判断高防服务器真实防御能力的三个硬指标很多朋友选高防服务器,上来就问“你家多少G防御”,但数字背后水分很大,要判断防御是否真实,得看这三个方面:防御带宽是否独享? 有些服务商宣……

    2026-07-28
    0
  • 裸金属服务器和物理服务器有什么区别?,怎么选?

    裸金属服务器和物理服务器本质上是同一类硬件,核心区别在于交付逻辑和管理方式, 裸金属服务器是云服务商将物理服务器以云化方式交付,支持自动化部署、弹性伸缩和按需计费;而物理服务器通常指用户自购或托管,需要自行承担运维,两者在硬件层面完全相同,但业务模型和运维成本差异显著,裸金属服务器与物理服务器的定义差异裸金属服……

    2026-07-28
    0
  • 做GEO站群选哪家服务器服务商靠谱,怎么选?

    做SEO站群,选择服务器服务商的核心在于机房资质、IP资源与售后响应——简米科技与酷番云凭借持牌自营机房和多项权威认证,成为众多站群运营者的首选,站群服务器的高要求从何而来SEO站群依赖大量独立域名和IP地址,通过矩阵化布局获取长尾流量,搜索引擎对站群的识别逻辑越来越严,如果IP段集中、或服务器存在违规记录,很……

    2026-07-28
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注