deb 基本操作

apt deb 包缓存:

~$ ls /var/cache/apt/archives/
libradosstriper1_12.2.11-0ubuntu0.18.04.1_amd64.deb
lock
partial
python-rbd_12.2.11-0ubuntu0.18.04.1_amd64.deb

dpkg-deb

查看 deb 包信息(rpm 包的话需要几个不同的选项组合才能查到所有的这些信息):

~$ dpkg-deb -I libradosstriper1_12.2.11-0ubuntu0.18.04.1_amd64.deb
 new Debian package, version 2.0.
 size 334400 bytes: control archive=14872 bytes.
     635 bytes,    15 lines      control
     159 bytes,     2 lines      md5sums
      48 bytes,     1 lines      shlibs
  139265 bytes,  1686 lines      symbols
      74 bytes,     2 lines      triggers
 Package: libradosstriper1
 Source: ceph
 Version: 12.2.11-0ubuntu0.18.04.1
 Architecture: amd64
 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
 Installed-Size: 1190
 Depends: librados2 (= 12.2.11-0ubuntu0.18.04.1), libc6 (>= 2.14), libgcc1 (>= 1:3.0), libstdc++6 (>= 6)
 Section: libs
 Priority: optional
 Homepage: http://ceph.com/
 Description: RADOS striping interface
  Striping interface built on top of the rados library, allowing
  to stripe bigger objects onto several standard rados objects using
  an interface very similar to the rados one.
 Original-Maintainer: Ceph Maintainers <ceph-maintainers@lists.ceph.com>

列出 deb 包内容:

~$ dpkg-deb -c libradosstriper1_12.2.11-0ubuntu0.18.04.1_amd64.deb
drwxr-xr-x root/root         0 2019-02-15 18:08 ./
drwxr-xr-x root/root         0 2019-02-15 18:08 ./usr/
drwxr-xr-x root/root         0 2019-02-15 18:08 ./usr/lib/
drwxr-xr-x root/root         0 2019-02-15 18:08 ./usr/lib/x86_64-linux-gnu/
-rw-r--r-- root/root   1012088 2019-02-15 18:08 ./usr/lib/x86_64-linux-gnu/libradosstriper.so.1.0.0
drwxr-xr-x root/root         0 2019-02-15 18:08 ./usr/share/
drwxr-xr-x root/root         0 2019-02-15 18:08 ./usr/share/doc/
drwxr-xr-x root/root         0 2019-02-15 18:08 ./usr/share/doc/libradosstriper1/
-rw-r--r-- root/root     40016 2019-02-11 19:06 ./usr/share/doc/libradosstriper1/copyright
lrwxrwxrwx root/root         0 2019-02-15 18:08 ./usr/lib/x86_64-linux-gnu/libradosstriper.so.1 -> libradosstriper.so.1.0.0
lrwxrwxrwx root/root         0 2019-02-15 18:08 ./usr/share/doc/libradosstriper1/changelog.Debian.gz -> ../librados2/changelog.Debian.gz

解压 deb 包:

~$ dpkg-deb -x libradosstriper1_12.2.11-0ubuntu0.18.04.1_amd64.deb ~/working/test/deb
~$ tree  ~/working/test/deb/
/home/runsisi/working/test/deb/
└── usr
    ├── lib
    │   └── x86_64-linux-gnu
    │       ├── libradosstriper.so.1 -> libradosstriper.so.1.0.0
    │       └── libradosstriper.so.1.0.0
    └── share
        └── doc
            └── libradosstriper1
                ├── changelog.Debian.gz -> ../librados2/changelog.Debian.gz
                └── copyright

6 directories, 4 files

解压 deb 包元数据文件(即 control、preinst、prerm 之类的文件):

~$ dpkg-deb -e libradosstriper1_12.2.11-0ubuntu0.18.04.1_amd64.deb ~/working/test/deb
~$ tree  ~/working/test/deb/
/home/runsisi/working/test/deb/
├── control
├── md5sums
├── shlibs
├── symbols
└── triggers

0 directories, 5 files

同时解压 deb 包的元数据文件与用户文件:

~$ dpkg-deb -R libradosstriper1_12.2.11-0ubuntu0.18.04.1_amd64.deb ~/working/test/deb
~$ tree ~/working/test/deb
/home/runsisi/working/test/deb
├── DEBIAN
│   ├── control
│   ├── md5sums
│   ├── shlibs
│   ├── symbols
│   └── triggers
└── usr
    ├── lib
    │   └── x86_64-linux-gnu
    │       ├── libradosstriper.so.1 -> libradosstriper.so.1.0.0
    │       └── libradosstriper.so.1.0.0
    └── share
        └── doc
            └── libradosstriper1
                ├── changelog.Debian.gz -> ../librados2/changelog.Debian.gz
                └── copyright

7 directories, 9 files

注意:如上的 dpkg-deb 命令,除 -R 外都可以直接使用 dpkg 进行调用。

dpkg-query

列出所有已安装的 deb 包:

~$ dpkg-query -l | grep librados
ii  librados-dev                               12.2.11-0ubuntu0.18.04.1                     amd64        RADOS distributed object store client library (development files)
ii  librados2                                  12.2.11-0ubuntu0.18.04.1                     amd64        RADOS distributed object store client library
ii  libradosstriper1                           12.2.11-0ubuntu0.18.04.1                     amd64        RADOS striping interface

查看已安装的 deb 包的信息:

~$ dpkg-query -s libradosstriper1
Package: libradosstriper1
Status: install ok installed
Priority: optional
Section: libs
Installed-Size: 1190
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Source: ceph
Version: 12.2.11-0ubuntu0.18.04.1
Depends: librados2 (= 12.2.11-0ubuntu0.18.04.1), libc6 (>= 2.14), libgcc1 (>= 1:3.0), libstdc++6 (>= 6)
Description: RADOS striping interface
 Striping interface built on top of the rados library, allowing
 to stripe bigger objects onto several standard rados objects using
 an interface very similar to the rados one.
Homepage: http://ceph.com/
Original-Maintainer: Ceph Maintainers <ceph-maintainers@lists.ceph.com>

根据文件查找 deb 包:

~$ dpkg-query -S /usr/lib/x86_64-linux-gnu/libradosstriper.so.1
libradosstriper1: /usr/lib/x86_64-linux-gnu/libradosstriper.so.1

列出已安装的 deb 包的内容:

~$ dpkg-query -L libradosstriper1
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libradosstriper.so.1.0.0
/usr/share
/usr/share/doc
/usr/share/doc/libradosstriper1
/usr/share/doc/libradosstriper1/copyright
/usr/lib/x86_64-linux-gnu/libradosstriper.so.1
/usr/share/doc/libradosstriper1/changelog.Debian.gz

注意:如上 dpkg-query 命令都可以直接使用 dpkg 命令进行调用

修改 deb 包

~$ fakeroot
~# dpkg-deb -R ceph-mon_12.2.12-1xenial_amd64.deb ceph-mon
~# vi ceph-mon/
DEBIAN/ etc/    lib/    usr/    var/
~# vi ceph-mon/DEBIAN/control
Package: ceph-mon
Source: ceph
Version: 12.2.12-2xenial
~# dpkg-deb -b ceph-mon/ ceph-mon/
DEBIAN/ etc/    lib/    usr/    var/
~# dpkg-deb -b ceph-mon/ ceph-mon_12.2.12-3xenial_amd64.deb
dpkg-deb: building package 'ceph-mon' in 'ceph-mon_12.2.12-3xenial_amd64.deb'.
~# dpkg -I ceph-mon_12.2.12-3xenial_amd64.deb
 new Debian package, version 2.0.
 size 4563072 bytes: control archive=2368 bytes.
      88 bytes,     3 lines      conffiles
    1177 bytes,    22 lines      control
     674 bytes,    10 lines      md5sums
    1986 bytes,    66 lines   *  postinst
     590 bytes,    21 lines   *  postrm               #!/bin/sh
     439 bytes,    28 lines   *  prerm                #!/bin/sh
 Package: ceph-mon
 Source: ceph
 Version: 12.2.12-2xenial
 Architecture: amd64
 Maintainer: Ceph Maintainers <ceph-maintainers@lists.ceph.com>
 Installed-Size: 19045
 Depends: ceph-base (= 12.2.12-1xenial), python-flask, init-system-helpers (>= 1.18~), libc6 (>= 2.16), libgcc1 (>= 1:3.0), libgoogle-perftools4, libibverbs1 (>= 1.1.2), libleveldb1v5, libnspr4 (>= 2:4.9-2~) | libnspr4-0d (>= 1.8.0.10), libnss3 (>= 2:3.13.4-2~) | libnss3-1d (>= 3.12.9~beta2), librados2, libsnappy1v5, libstdc++6 (>= 5.2), zlib1g (>= 1:1.1.4)
 Recommends: ceph-common
 Breaks: ceph (<< 10), ceph-test (<< 12.2.2-14)
 Replaces: ceph (<< 10), ceph-test (<< 12.2.2-14)
 Section: admin
 Priority: optional
 Homepage: http://ceph.com/
 Description: monitor server for the ceph storage system
  Ceph is a massively scalable, open-source, distributed
  storage system that runs on commodity hardware and delivers object,
  block and file system storage.
  .
  This package contains the cluster monitor daemon for the Ceph storage
  system. One or more instances of ceph-mon form a Paxos part-time parliament
  cluster that provides extremely reliable and durable storage of cluster
  membership, configuration, and state.
~# exit
exit
~$ ll
total 8932
drwxr-xr-x  3 runsisi runsisi    4096 May 31 23:42 ./
drwxr-xr-x 17 runsisi runsisi    4096 May 31 22:57 ../
drwxr-xr-x  7 runsisi runsisi    4096 May 31 23:40 ceph-mon/
-rw-rw-r--  1 runsisi runsisi 4562182 May 31 23:35 ceph-mon_12.2.12-1xenial_amd64.deb
-rw-r--r--  1 runsisi runsisi 4563072 May 31 23:42 ceph-mon_12.2.12-3xenial_amd64.deb

注意:修改 control 文件中的 Version 信息才是真正的修改了版本号。

强制选项

~$ sudo dpkg -i --force-all ceph-mon_12.2.12-3xenial_amd64.deb
(Reading database ... 352370 files and directories currently installed.)
Preparing to unpack ceph-mon_12.2.12-3xenial_amd64.deb ...
Unpacking ceph-mon (12.2.12-2xenial) over (12.2.12-2xenial) ...
dpkg: ceph-mon: dependency problems, but configuring anyway as you requested:
 ceph-mon depends on ceph-base (= 12.2.12-1xenial); however:
  Package ceph-base is not installed.
 ceph-mon depends on python-flask; however:
  Package python-flask is not installed.

Setting up ceph-mon (12.2.12-2xenial) ...

其中的 --force-all 只是 --force-<things> 众多 things 的全集,特别注意其中的 confnew, confold, conflicts, depends 等选项。

强制删除

有时候,无论怎么折腾,都会出现已安装的 deb 包无法卸载的情况,如:

~$ sudo apt --fix-broken install --force
E: Command line option --force is not understood in combination with the other options
root@runsisi-hust:/home/runsisi# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
...
The following packages will be REMOVED:
  ceph-mon
0 upgraded, 0 newly installed, 1 to remove and 439 not upgraded.
After this operation, 19.5 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 352369 files and directories currently installed.)
Removing ceph-mon (12.2.12-2xenial) ...
Failed to stop ceph.service: Unit ceph.service not loaded.
invoke-rc.d: initscript ceph, action "stop" failed.
dpkg: error processing package ceph-mon (--remove):
 installed ceph-mon package pre-removal script subprocess returned error exit status 5
Errors were encountered while processing:
 ceph-mon
E: Sub-process /usr/bin/dpkg returned an error code (1)
~$ sudo dpkg -r ceph-mon
(Reading database ... 352353 files and directories currently installed.)
Removing ceph-mon (12.2.12-2xenial) ...
Failed to stop ceph.service: Unit ceph.service not loaded.
invoke-rc.d: initscript ceph, action "stop" failed.
dpkg: error processing package ceph-mon (--remove):
 installed ceph-mon package pre-removal script subprocess returned error exit status 5
Errors were encountered while processing:
 ceph-mon

这时就只能通过手动修改 deb 的内置脚本来解决了:

~$ cd /var/lib/dpkg/info
~$ sudo vi ceph-mon.prerm

比较版本号

https://runsisi.com/2019/02/02/deb-ver-compare

查询 deb 依赖

$ apt-cache depends python-rbd
python-rbd
  Depends: librbd1
  Depends: python
  Depends: python
  Depends: <python:any>
    python
  Depends: libc6
  Depends: libgcc1
  Depends: libpython2.7
  Depends: librados2
  Depends: libstdc++6
  Breaks: python-ceph
  Replaces: python-ceph

$ dpkg -I python-rbd_14.2.15-109-g040e46e0-1xenial_amd64.deb
 new debian package, version 2.0.
 size 355256 bytes: control archive=1240 bytes.
     830 bytes,    19 lines      control
    1134 bytes,    12 lines      md5sums
     158 bytes,     9 lines   *  postinst             #!/bin/sh
     255 bytes,    14 lines   *  prerm                #!/bin/sh
 Package: python-rbd
 Source: ceph
 Version: 14.2.15-109-g040e46e0-1xenial
 Architecture: amd64
 Maintainer: Ceph Maintainers <ceph-maintainers@lists.ceph.com>
 Installed-Size: 1447
 Depends: librbd1 (>= 14.2.15-109-g040e46e0-1xenial), python (<< 2.8), python (>= 2.7~), python:any (>= 2.7.5-5~), libc6 (>= 2.14), libgcc1 (>= 1:3.0), libpython2.7 (>= 2.7), librados2, libstdc++6 (>= 7)
 Breaks: python-ceph (<< 0.92-1223)
 Replaces: python-ceph (<< 0.92-1223)
 Section: python
 Priority: optional
 Homepage: http://ceph.com/
 Description: Python 2 libraries for the Ceph librbd library
  Ceph is a massively scalable, open-source, distributed
  storage system that runs on commodity hardware and delivers object,
  block and file system storage.
  .
  This package contains Python 2 libraries for interacting with Ceph's
  RBD block device library.

强制使用未签名的 apt repo

$ sudo apt -o Acquire::AllowInsecureRepositories=true -o Acquire::AllowDowngradeToInsecureRepositories=true update
$ sudo apt install python-rbd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libnspr4 libnss3 libpython-stdlib libpython2.7 libpython2.7-minimal libpython2.7-stdlib librados2 librbd1 libssl1.0.0 python python-minimal python2.7 python2.7-minimal
Suggested packages:
  python-doc python-tk python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
  libnspr4 libnss3 libpython-stdlib libpython2.7 libpython2.7-minimal libpython2.7-stdlib librados2 librbd1 libssl1.0.0 python python-minimal python-rbd python2.7 python2.7-minimal
0 upgraded, 14 newly installed, 0 to remove and 45 not upgraded.
Need to get 12.8 MB of archives.
After this operation, 49.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
WARNING: The following packages cannot be authenticated!
  librados2 librbd1 python-rbd
Install these packages without verification? [y/N] y

锁定版本

apt-mark的作用与 yum versionlock 类似:

$ sudo apt-mark hold libgegl-0.4-0
libgegl-0.4-0 set on hold.
$ apt-mark showhold
libgegl-0.4-0
$ sudo apt-mark unhold libgegl-0.4-0
Canceled hold on libgegl-0.4-0.

参考资料

Easily unpack DEB, edit postinst, and repack DEB

https://unix.stackexchange.com/questions/138188/easily-unpack-deb-edit-postinst-and-repack-deb

How to prevent updating of a specific package?

https://askubuntu.com/questions/18654/how-to-prevent-updating-of-a-specific-package


最后修改于 2019-05-31