Debian 软件包的配置管理

tl,dr

  • debconf是Debian的软件包配置管理工具。
  • 软件包安装过程是通过debconf获取用户的配置意愿,并进行配置。
  • 安装过后,也可以再通过dpkg-reconfigure命令重新对软件包进行配置,复原安装过程。
  • 通过debconf-show命令可以查看每个软件包的配置。

0. debconf

debconf是Debian系Linux系统软件包配置管理系统,下属多个命令工具。它与dpkg(Debian包管理系统)紧密集成,debconf负责包的配置管理,dpkg负责包的安装。

  • debconf举例来说有点类似于Windows下的注册表。

  • debconf本身只记录、保存配置信息,但不进行配置操作,真正的配置操作由各个软件包进行。

    • 并不是所有软件包都使用debconf,有少数软件包,或者为其他系统开发的源代码包是不经过debconf的,如ALSA声音管理系统、PulseAudio等。
  • 每个软件包的安装脚本 (一般包含.config, .postinst, 等)会在安装过程调用debconf(通过.config脚本,一般为安装过程的最后阶段),通过开发者预存的.templates问题模板,获取用户的配置意愿信息,进而使用.postinst脚本应用软件配置操作。

  • .templates问题模板一般包含多个问题,每个问题具有不同的优先级,根据软件包安装脚本的配置,并不是所有优先级的问题都需要用户回答。同样在使用dpkg-reconfigure命令重新配置软件包时,有可能没有任何问题出来,原因一般是优先级设置得比较高(高优先级问题一般较少),用户不需要回答,可以通过给dpkg-reconfigure命令传递参数,修改制定优先级问题的答案。

  • debconf通过其各种front-ends程序(不同的基于CLI或GUI的程序)交互、或非交互式的询问用户配置的意愿(如存放目录等信息),并将其缓存与debconf的数据库中。

    • font-ends程序可以通过sudo dpkg-reconfigure debconf命令进行修改:
      《Debian 软件包的配置管理》 dpkg-reconfigure debconf命令截图
  • debconf交互式过程一般只发生于软件包安装过程中,如果后期需要调整配置,可以使用dpkg-reconfigure命令或Synaptic命令再配置,两个命令将会重复安装阶段的交互式询问过程。

debconf下属命令集:

ray@ray-ThinkPad-X250:~$ debconf
debconf debconf-copydb debconf-set-selections
debconf-apt-progress debconf-escape debconf-show
debconf-communicate debconf-gettextize debconf-updatepo

参考自Wikipeadia:debconf (software package)

1. 重新配置软件包:dpkg-reconfigure

Reference:dpkg-reconfigure man page

功能介绍(来自于该命令的man page)

NAME
dpkg-reconfigure – reconfigure an already installed package
SYNOPSIS
dpkg-reconfigure [options] packages
DESCRIPTION
dpkg-reconfigure reconfigures packages after they have already been installed. Pass it the names of a package or packages to reconfigure. It will ask configuration questions, much like when the package was first installed. If you just want to see the current configuration of a package, see debconf-show(1) instead.

实例1:重新配置locales

$ sudo dpkg-reconfigure locales

实例2:重新配置Display Manager的选择(lightdm or gdm)

$ sudo dpkg-reconfigure lightdm
or
$ sudo dpkg-reconfigure gdm

实例3:重新配置整个系统(一般用户大故障恢复)

dpkg --configure -a will configure all unpacked but unconfigured packages.
dpkg-reconfigure -phigh -a will reconfigure all installed packages that use debconf with high priority.

2. 查看软件包的配置:debconf-show

Reference: debconf-show

功能介绍(来自于该命令的man page)

NAME
debconf-show – query the debconf database
SYNOPSIS
debconf-show packagename […] [–db=dbname] debconf-show –listowners [–db=dbname] debconf-show –listdbs
DESCRIPTION
debconf-show lets you query the debconf database in different ways. The most common use is “debconf-show packagename”, which displays all items in the debconf database owned by a given package, and their current values. Questions that have been asked already are prefixed with an ‘*’. This can be useful as a debugging aid, and especially handy in bug reports involving a package’s use of debconf.

一般建议在使用上一章节命令dpkg-reconfigure修改配置先,先通过这个命令查看、备份一下配置。

实例1:查看locales配置

ray@ray-ThinkPad-X250:~$ sudo debconf-show locales
locales/default_environment_locale: en_US.UTF-8
locales/locales_to_be_generated: , en_US.UTF-8 UTF-8, zh_CN.UTF-8 UTF-8
ray@ray-ThinkPad-X250:~$

实例2:查看Display Manager配置

ray@ray-ThinkPad-X250:~$ sudo debconf-show lightdm
lightdm/daemon_name: /usr/sbin/lightdm
* shared/default-x-display-manager: lightdm
ray@ray-ThinkPad-X250:~$

3. dpkg 包管理

dpkg 可以实现包的增删改调
dpkg -l 列出所有安装的包及其状态,可以使用grep过滤显示结果。常见的数据包状态有:

iU 表示软件包未安装成功
ii 表示安装成功
rc 表示软件包已经被卸载,但配置文件仍在

其中 rc 状态的包即卸载了包却保留了配置文件。如果想要完整删除所有 rc 状态的包一个一个删还是很麻烦的,所以可以使用以下命令进行清理:

dpkg -l | grep ^rc | cut -d’ ‘ -f3 | sudo xargs dpkg –purge

参考URL:
http://blog.csdn.net/chrisniu1984/article/details/6619755
http://www.th7.cn/system/lin/201604/160329.shtml

参考URL

重要文件 Updating packages with dpkg-reconfigure—Debian’s Secret Recovery Tool
Debian Wiki ChangeLanguage
What is dpkg-reconfigure and how is it different from dpkg –configure?

    原文作者:mst7
    原文地址: https://www.jianshu.com/p/4f1dbd4499e2
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞