Debian包常见操作

平时在开发过程中或者处理debian包时经常会遇到下载源码包的操作并重新编译的问题,此处介绍一下的debian包的处理过程,遵循下载 -- 修改 -- 编译的过程,介绍一下debian系Linux系统中用到的一些操作命令。

查询软件包

如果不清楚软件包名称,可以使用apt-cache search <pkg>命令来查找源码包的具体名称,此命令支持模糊查询。以iproute2包为例,此处使用iprou作为关键字来查询,查询结果如下。

tencent@ubuntu:~/iproute2$ apt-cache search iprou
iproute - transitional dummy package for iproute2
iproute-doc - transitional dummy package for iproute2-doc
iproute2 - networking and traffic control tools
iproute2-doc - networking and traffic control tools - documentation
golang-github-vishvananda-netlink-dev - netlink library for go
libghc-iproute-dev - Haskell IP routing table
libghc-iproute-doc - Haskell IP routing table; documentation
libghc-iproute-prof - Haskell IP routing table; profiling libraries

上面的搜索结果中罗列出了所有匹配的软件包,使用iproute2软件包。如果向获取此软件包的详细信息,可以通过apt-cache show <pkg>命令来获得详细信息。

tencent@ubuntu:~/iproute$ apt-cache show iproute2
Package: iproute2
Architecture: amd64
Version: 4.3.0-1ubuntu3.16.04.5
Multi-Arch: foreign
Priority: important
Section: net
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian iproute2 Maintainers <ah-iproute@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 1487
Provides: arpd
Depends: libc6 (>= 2.14), libdb5.3, libmnl0 (>= 1.0.3-4~), libselinux1 (>= 2.0.15)
Recommends: libatm1 (>= 2.4.1-17~), libxtables11
Suggests: iproute2-doc
Conflicts: arpd, iproute (<< 20130000-1)
Replaces: iproute
Filename: pool/main/i/iproute2/iproute2_4.3.0-1ubuntu3.16.04.5_amd64.deb
Size: 522552
MD5sum: b228f6d27f1485a67beea2bbae166bad
SHA1: 2526af36c168345ae65590ca72a471796ca9a261
SHA256: 9792f856e3a051286149262767881007af43148e97f6cf8e02e681ad000b3367
SHA512: c252ab6f1bcec953b54c307baa7e5f57eaf14ec60b9d827c59a3b8c3363420234c3b5801e77eadacf9cd1d2c53cc0143d9a2bab8db2c2918b9af10cbbcb66562
Homepage: http://www.linux-foundation.org/en/Net:Iproute2
Description-en: networking and traffic control tools
 The iproute2 suite is a collection of utilities for networking and
 traffic control.
 .
 These tools communicate with the Linux kernel via the (rt)netlink
 interface, providing advanced features not available through the
 legacy net-tools commands 'ifconfig' and 'route'.
Description-md5: d10cc46ca4a9e5489b7d2c879fcfba17
Task: minimal, ubuntu-core, ubuntu-core, ubuntu-sdk-libs-tools, ubuntu-sdk
Supported: 5y

下载二进制包

通过apt-get download <pkg>命令可以直接下载二进制软件包,软件包的名称获取方式可以参考上一节中介绍的查询软件包方法。

tencent@ubuntu:~/iproute$ ls -l
total 0
tencent@ubuntu:~/iproute$
tencent@ubuntu:~/iproute$
tencent@ubuntu:~/iproute$ apt-get download iproute2
Get:1 https://mirrors.tencent.com/ubuntu xenial-updates/main amd64 iproute2 amd64 4.3.0-1ubuntu3.16.04.5 [523 kB]
Fetched 523 kB in 0s (523 kB/s)
tencent@ubuntu:~/iproute$
tencent@ubuntu:~/iproute$
tencent@ubuntu:~/iproute$
tencent@ubuntu:~/iproute$ ls -l
total 512
-rw-r--r-- 1 tencent tencent 522552 Apr 16  2019 iproute2_4.3.0-1ubuntu3.16.04.5_amd64.deb

此时其实可以通过apt-get install <pkg>命令从本地安装这个包,与平常安装稍微不同的是,需要给<pkg>加上本地路径,表明直接从本地安装,而不是从远程仓库上拉取这个包。

下载源码包

下载软件包源码

在Debian系linux操作系统中,可以通过apt-get source <pkg>命令来下载对应软件包的源码包。

tencent@ubuntu:~/iproute2$ apt-get source iproute2
Reading package lists... Done
NOTICE: 'iproute2' packaging is maintained in the 'Git' version control system at:
git://git.debian.org/git/collab-maint/pkg-iproute.git
Please use:
git clone git://git.debian.org/git/collab-maint/pkg-iproute.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 563 kB of source archives.
Get:1 https://mirrors.tencent.com/ubuntu xenial-updates/main iproute2 4.3.0-1ubuntu3.16.04.5 (dsc) [2,491 B]
Get:2 https://mirrors.tencent.com/ubuntu xenial-updates/main iproute2 4.3.0-1ubuntu3.16.04.5 (tar) [525 kB]
Get:3 https://mirrors.tencent.com/ubuntu xenial-updates/main iproute2 4.3.0-1ubuntu3.16.04.5 (diff) [35.2 kB]
Fetched 563 kB in 1s (457 kB/s)
tencent@ubuntu:~/iproute2$ ls -l
total 560
drwxrwxr-x 18 tencent tencent   4096 Nov 27 12:40 iproute2-4.3.0
-rw-r--r--  1 tencent tencent  35248 Apr 16  2019 iproute2_4.3.0-1ubuntu3.16.04.5.debian.tar.xz
-rw-r--r--  1 tencent tencent   2491 Apr 16  2019 iproute2_4.3.0-1ubuntu3.16.04.5.dsc
-rw-r--r--  1 tencent tencent 525364 Jan  4  2016 iproute2_4.3.0.orig.tar.xz

上述命令会完整下载iproute2的源码包,并且将源码包解压缩到当前目录中,即文件夹iproute2-4.3.0,如果不想让命令自动解压,可以加上--download-only参数。

tencent@ubuntu:~/iproute2$ apt-get source --download-only iproute2
Reading package lists... Done
NOTICE: 'iproute2' packaging is maintained in the 'Git' version control system at:
git://git.debian.org/git/collab-maint/pkg-iproute.git
Please use:
git clone git://git.debian.org/git/collab-maint/pkg-iproute.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 563 kB of source archives.
Get:1 https://mirrors.tencent.com/ubuntu xenial-updates/main iproute2 4.3.0-1ubuntu3.16.04.5 (dsc) [2,491 B]
Get:2 https://mirrors.tencent.com/ubuntu xenial-updates/main iproute2 4.3.0-1ubuntu3.16.04.5 (tar) [525 kB]
Get:3 https://mirrors.tencent.com/ubuntu xenial-updates/main iproute2 4.3.0-1ubuntu3.16.04.5 (diff) [35.2 kB]
Fetched 563 kB in 1s (513 kB/s)
Download complete and in download only mode
tencent@ubuntu:~/iproute2$ ls -l
total 556
-rw-r--r-- 1 tencent tencent  35248 Apr 16  2019 iproute2_4.3.0-1ubuntu3.16.04.5.debian.tar.xz
-rw-r--r-- 1 tencent tencent   2491 Apr 16  2019 iproute2_4.3.0-1ubuntu3.16.04.5.dsc
-rw-r--r-- 1 tencent tencent 525364 Jan  4  2016 iproute2_4.3.0.orig.tar.xz

如此一来,就只有源码包,简单阐述一下下载的三个文件。

  • *.dec文件:这个是源码包的描述文件,其中包含包名称、文件列表和校验和信息
  • *.debian.tar.xz: 这个是debian包的打包文件,里面包含编译此源码包并将其打包为debian包的控制文件
  • *.orig.tar.xz: 这个是真正的源代码,在不使用--download-only参数时,下载的文件夹就是这个压缩包解压后的内容
    如果--download-only参数,下载完毕后可以手动解压缩源码包,此处不使用tar -xf <pkg>命令,debian系统中提供有专用的加压缩命令dpkg-source
tencent@ubuntu:~/iproute2$ ls -l
total 556
-rw-r--r-- 1 tencent tencent  35248 Apr 16  2019 iproute2_4.3.0-1ubuntu3.16.04.5.debian.tar.xz
-rw-r--r-- 1 tencent tencent   2491 Apr 16  2019 iproute2_4.3.0-1ubuntu3.16.04.5.dsc
-rw-r--r-- 1 tencent tencent 525364 Jan  4  2016 iproute2_4.3.0.orig.tar.xz
tencent@ubuntu:~/iproute2$
tencent@ubuntu:~/iproute2$
tencent@ubuntu:~/iproute2$ dpkg-source -x iproute2_4.3.0-1ubuntu3.16.04.5.dsc
gpgv: Signature made Fri 12 Apr 2019 02:19:37 AM PDT using RSA key ID 8280B242
gpgv: Can't check signature: public key not found
dpkg-source: warning: failed to verify signature on ./iproute2_4.3.0-1ubuntu3.16.04.5.dsc
dpkg-source: info: extracting iproute2 in iproute2-4.3.0
dpkg-source: info: unpacking iproute2_4.3.0.orig.tar.xz
dpkg-source: info: unpacking iproute2_4.3.0-1ubuntu3.16.04.5.debian.tar.xz
dpkg-source: info: applying 0001-Add-moo-feature.patch
dpkg-source: info: applying 0002-txtdocs.patch
dpkg-source: info: applying 1000-ubuntu-poc-fan-driver.patch
dpkg-source: info: applying 1001-ubuntu-poc-fan-driver-v3.patch
dpkg-source: info: applying 1002-ubuntu-poc-fan-driver-vxlan.patch
dpkg-source: info: applying 1003-fix-variable-in-libnetlink.patch
dpkg-source: info: applying 1004-tc.8-Fix-reference-to-tc-tcindex.8.patch
dpkg-source: info: applying 99-increase-receive-buffer-size.patch
dpkg-source: info: applying 1005-ip-maddr-fix-igmp-parsing.patch
dpkg-source: info: applying 1006-ip-maddr-avoid-uninitialized-data.patch
dpkg-source: info: applying 1007-ip-maddr-fix-filtering-by-device.patch
dpkg-source: info: applying 1008-vf_trust_dddf1b44126e.patch
dpkg-source: info: applying 1009-vf_trust_b6d77d9ee312.patch
dpkg-source: info: applying 1010-vf_trust_fe9322781e63.patch
dpkg-source: info: applying 1011-tc-Add-support-for-the-matchall-traffic-classifier.patch
tencent@ubuntu:~/iproute2$
tencent@ubuntu:~/iproute2$
tencent@ubuntu:~/iproute2$
tencent@ubuntu:~/iproute2$ ls -l
total 560
drwxrwxr-x 18 tencent tencent   4096 Nov 27 13:09 iproute2-4.3.0
-rw-r--r--  1 tencent tencent  35248 Apr 16  2019 iproute2_4.3.0-1ubuntu3.16.04.5.debian.tar.xz
-rw-r--r--  1 tencent tencent   2491 Apr 16  2019 iproute2_4.3.0-1ubuntu3.16.04.5.dsc
-rw-r--r--  1 tencent tencent 525364 Jan  4  2016 iproute2_4.3.0.orig.tar.xz

值得注意的一点,此命令要比apt-get source <pkg>命令解压的更加完整,因此这条命令会将*.debian.tar.xz压缩包也解压到源码包中,如下所示。

tencent@ubuntu:~/iproute2$ cd iproute2-4.3.0/
tencent@ubuntu:~/iproute2/iproute2-4.3.0$ ls -l
total 120
drwxrwxr-x 2 tencent tencent  4096 Nov  3  2015 bridge
-rwxrwxr-x 1 tencent tencent  6959 Nov  3  2015 configure
-rw-rw-r-- 1 tencent tencent 18011 Nov  3  2015 COPYING
drwxrwxr-x 5 tencent tencent  4096 Apr  4  2019 debian
drwxrwxr-x 3 tencent tencent  4096 Nov 27 13:09 doc
drwxrwxr-x 3 tencent tencent  4096 Nov  3  2015 etc
drwxrwxr-x 4 tencent tencent  4096 Nov  3  2015 examples
drwxrwxr-x 2 tencent tencent  4096 Nov  3  2015 genl
drwxrwxr-x 5 tencent tencent  4096 Nov  3  2015 include
drwxrwxr-x 2 tencent tencent  4096 Nov 27 13:09 ip
drwxrwxr-x 2 tencent tencent  4096 Nov 27 13:09 lib
-rw-rw-r-- 1 tencent tencent  2188 Nov  3  2015 Makefile
drwxrwxr-x 5 tencent tencent  4096 Nov  3  2015 man
drwxrwxr-x 2 tencent tencent  4096 Nov  3  2015 misc
drwxrwxr-x 2 tencent tencent  4096 Nov  3  2015 netem
-rw-rw-r-- 1 tencent tencent  1364 Nov  3  2015 README
-rw-rw-r-- 1 tencent tencent  1266 Nov  3  2015 README.decnet
-rw-rw-r-- 1 tencent tencent   624 Nov  3  2015 README.devel
-rw-rw-r-- 1 tencent tencent  4403 Nov  3  2015 README.distribution
-rw-rw-r-- 1 tencent tencent  3735 Nov  3  2015 README.iproute2+tc
-rw-rw-r-- 1 tencent tencent  1990 Nov  3  2015 README.lnstat
drwxrwxr-x 2 tencent tencent  4096 Nov 27 13:09 tc
drwxrwxr-x 6 tencent tencent  4096 Nov  3  2015 testsuite
drwxrwxr-x 2 tencent tencent  4096 Nov  3  2015 tipc

修改源码包

此时,可以到源码包中修改源代码,修改主要分为三方面

  • 修改debian目录中的打包控制文件
  • 修改源代码
  • 修改Makefile(可能会使用automake工具)

具体的修改行为此处不多做阐述,可以根据自己的需要来修改。

重新编译源码包

完成自己的修改后,可以重新编译源码,并且将其打包为debian包,由于包一般会依赖于其他包,所以在编译之前需要提前安装好依赖包。

查询依赖关系

在Debian系统中,可以通过apt-cache depends/rdepends <pkg>命令查询软件包的依赖关系和反向依赖关系。

tencent@ubuntu:~/iproute2/iproute2-4.3.0$ apt-cache depends iproute2
iproute2
  Depends: libc6
  Depends: libdb5.3
  Depends: libmnl0
  Depends: libselinux1
  Conflicts: <arpd>
  Conflicts: iproute
  Recommends: libatm1
  Recommends: libxtables11
  Suggests: iproute2-doc
  Replaces: iproute
tencent@ubuntu:~/iproute2/iproute2-4.3.0$ apt-cache rdepends iproute2
iproute2
Reverse Depends:
  ubuntu-fan
    iproute2:i386
  virtualbox
    iproute2:i386
 |ltsp-server
    iproute2:i386
 |ltsp-client-core
    iproute2:i386
 |libguestfs0
    iproute2:i386
 |guestfsd
    iproute2:i386
 |criu
    iproute2:i386
  vlan
    iproute2:i386
... ...

此外,使用dpkg-info <pkg>命令或者使用命令apt-rdepends <pkg>也能查看包的依赖关系,命令apt-rdepends默认并未安装,可是通过sudo apt install apt-rdepends来安装此软件包,此处不再多做阐述。

安装依赖包

上节中介绍了如何查询依赖包,其实并不需要逐个去安装依赖包,在Debian系的Linux系统中,可以通过命令apt-get build-dep <pkg>安装在编译此包是需要的第三方包。

tencent@ubuntu:~/iproute2/iproute2-4.3.0$ sudo apt-get build-dep iproute2 -y
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  default-jdk-headless libasound2 libasound2-data libasyncns0 libflac8 libgif7 libgl1-mesa-glx libgtk2.0-0 libgtk2.0-common libogg0 libsndfile1 libvorbis0a libvorbisenc2 libxcb-glx0 libxxf86vm1
  openjdk-8-jdk-headless
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  bison cm-super-minimal flex iptables-dev libatm1-dev libbison-dev libcupsfilters1 libcupsimage2 libdb-dev libdb5.3-dev libfl-dev libgs9 libgs9-common libharfbuzz-icu0 libijs-0.35 libjbig2dec0
  libkpathsea6 libmnl-dev libosp5 libpaper-utils libpaper1 libpoppler58 libpotrace0 libptexenc1 libselinux1-dev libsepol1-dev libsynctex1 libtexlua52 libtexluajit2 libzzip-0-13 linuxdoc-tools
  lynx lynx-common opensp poppler-data t1utils tex-common texlive-base texlive-binaries texlive-fonts-recommended texlive-latex-base texlive-latex-recommended xdg-utils
0 upgraded, 43 newly installed, 0 to remove and 0 not upgraded.
Need to get 757 kB/66.7 MB of archives.
After this operation, 208 MB of additional disk space will be used.
... ...

编译debian包

解决完依赖包的问题后,可以正式开始编译了,可以通过dpkg-buildimage命令直接完成编译和打包工作。切换至源码包目录中

tencent@ubuntu:~/iproute2/iproute2-4.3.0$ dpkg-buildpackage -rfakeroot -b -us -uc
dpkg-buildpackage: source package iproute2
dpkg-buildpackage: source version 4.3.0-1ubuntu3.16.04.5
dpkg-buildpackage: source distribution xenial
dpkg-buildpackage: source changed by Stefan Bader <stefan.bader@canonical.com>
dpkg-buildpackage: host architecture amd64
 dpkg-source --before-build iproute2-4.3.0

执行完毕后会在上一级目录中找到编译的debian包。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,529评论 5 475
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,015评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,409评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,385评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,387评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,466评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,880评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,528评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,727评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,528评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,602评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,302评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,873评论 3 306
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,890评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,132评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,777评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,310评论 2 342

推荐阅读更多精彩内容