use*_*ser 24 debian dpkg package-management
我正在尝试在 VM 中设置一个临时环境,以便在将更新应用到我的主系统之前对其进行测试。
为此,我在 VM 中完成了 Debian Wheezy 的基本安装(与主系统相同),然后在 VM 中以 root 身份运行:
# dpkg --clear-selections
# dpkg --add-architecture i386
# apt-get update
# ssh me@main-system 'dpkg --get-selections | grep -v deinstall' | \
dpkg --set-selections
Run Code Online (Sandbox Code Playgroud)
不幸的是,在我的情况下需要 i386 架构;系统是 amd64 原生的。
问题在于dpkg --set-selections在 VM 中运行。我确实有一些需要特殊处理的包(这些实际上是我首先想要一个暂存环境的主要原因)但是当我运行上面的最后一个命令时,我得到了无数行输出,例如:
dpkg: warning: package not in database at line NNN: package-name
Run Code Online (Sandbox Code Playgroud)
对于真正应该在基本系统中可用的包。示例包括xterm、yelp和zip。
现在我的问题:
将软件包选择列表从一个 Debian 系统转移到另一个系统(假设 Debian 发行级别相同,在 Wheezy 中)然后随后应用这些更改的具体过程是什么?目标是两者都具有相同的已安装软件包列表,理想情况下,在diff两者的输出之间dpkg --get-selections或dpkg --list在两者上执行 a返回时不会显示任何差异。
该grep -v deinstall部分借用了在 Ask Ubuntu 上完成后防止软件包被删除dpkg --set-selections。
我已将 VM 中的源更改为与主系统上的源相同,还安装了apt-transport-https:
deb https://ftp-stud.hs-esslingen.de/debian/ wheezy main non-free
deb-src https://ftp-stud.hs-esslingen.de/debian/ wheezy main non-free
deb https://ftp-stud.hs-esslingen.de/debian/ wheezy-updates main non-free
deb-src https://ftp-stud.hs-esslingen.de/debian/ wheezy-updates main non-free
deb [arch=amd64] http://archive.zfsonlinux.org/debian wheezy main
Run Code Online (Sandbox Code Playgroud)
查看 --set-selections 输出,我看到:
dpkg: warning: package not in database at line 1: a2ps
dpkg: warning: package not in database at line 1: abiword
dpkg: warning: package not in database at line 1: abiword-common
dpkg: warning: package not in database at line 1: abiword-plugin-grammar
dpkg: warning: package not in database at line 1: abiword-plugin-mathview
dpkg: warning: package not in database at line 1: accountsservice
dpkg: warning: package not in database at line 1: acl
dpkg: warning: package not in database at line 4: aglfn
dpkg: warning: package not in database at line 4: aisleriot
dpkg: warning: package not in database at line 4: alacarte
dpkg: warning: package not in database at line 4: alien
...
Run Code Online (Sandbox Code Playgroud)
行号看起来很奇怪,--get-selections 输出的相应部分是:
a2ps install
abiword install
abiword-common install
abiword-plugin-grammar install
abiword-plugin-mathview install
accountsservice install
acl install
acpi-support-base install
acpid install
adduser install
aglfn install
aisleriot install
alacarte install
alien install
Run Code Online (Sandbox Code Playgroud)
请注意,在acl和aglfnare之间acpi-support-base,acpid并且adduser 没有报告错误。似乎报告错误的包要么un根据dpkg -l,要么dpkg -l根本不知道它们 ( dpkg-query: no packages found matching ...)。我知道有一些本地安装的软件包,但不是很多。i386不图,直到gcc-4.7-base:i386 install 多越往下列表(在--get-选择输出线342)。
Gil*_*il' 24
要克隆 Debian 安装,请使用该apt-clone实用程序。从 wheezy 开始,它在 Debian 中可用(作为一个单独的包,而不是默认安装的一部分),从 12.04 开始在 Ubuntu 中可用。在现有机器上,运行
apt-clone clone foo
Run Code Online (Sandbox Code Playgroud)
这将创建一个文件foo.apt-clone.tar.gz。将其复制到目标机器,然后运行
apt-get install apt-clone
apt-clone restore foo.apt-clone.tar.gz
Run Code Online (Sandbox Code Playgroud)
如果您正在使用不可用的旧系统apt-clone,或者如果您只想复制已安装软件包的列表而不是任何配置文件,这里是手动步骤。
在源机器上:
cat /etc/apt/sources.list /etc/apt/sources.list.d >sources.list
dpkg --get-selections >selections.list
apt-mark showauto >auto.list
Run Code Online (Sandbox Code Playgroud)在目标机器上:
cp sources.list /etc/apt/
apt-get update
/usr/lib/dpkg/methods/apt/update /var/lib/dpkg/
dpkg --set-selections <selections.list
apt-get dselect-upgrade
xargs apt-mark auto <auto.list
Run Code Online (Sandbox Code Playgroud)我相信您受到 dpkg 中不兼容更改的影响,该更改首先使其变得喘不过气来。有关背景,请参阅错误 #703092。
简而言之,dpkg --set-selections现在只接受文件/var/lib/dpkg/status或/var/lib/dpkg/available. 如果您像大多数人一样只使用 APT 来管理软件包,那么/var/lib/dpkg/available就不会保持最新。
运行后apt-get update和运行前dpkg --set-selections及apt-get -u dselect-upgrade运行以下命令:
apt-cache dumpavail >/tmp/apt.avail
dpkg --merge-avail /tmp/apt.avail
Run Code Online (Sandbox Code Playgroud)
从 jessie 开始,您可以将其简化为
apt-cache dumpavail | dpkg --merge-avail
Run Code Online (Sandbox Code Playgroud)
或者,运行
/usr/lib/dpkg/methods/apt/update /var/lib/dpkg/
Run Code Online (Sandbox Code Playgroud)
甚至更简单
apt-get install dctrl-tools
sync-available
Run Code Online (Sandbox Code Playgroud)
另一种不需要安装额外软件包但会再次下载软件包列表的简单方法是
dselect update
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅dpkg 常见问题解答。(在 dpkg 手册页中提到了这一点,但如果您已经意识到该问题,则会以更多方式提醒您,而不是以解释如何解决问题的方式!)
请注意,克隆包安装dpkg --set-selections并不会恢复 APT 中的自动/手动标记。有关更多详细信息,请参阅从 dpkg --set-selections '*' 恢复所有数据和依赖项。您可以使用以下命令将标记保存在源系统上
apt-mark showauto >auto.list
Run Code Online (Sandbox Code Playgroud)
并在目标系统上恢复它们
xargs apt-mark auto <auto.list
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20856 次 |
| 最近记录: |