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).