THEDEBIANWAY: Dpkg of Debian Maintenance Tool

Source: Internet
Author: User
THEDEBIANWAY: Debian maintenance tool Dpkg-Linux Release Technology-Debian information, the following is a detailed description. This article describes the Debian GNU/Linux Dpkg tool in detail, and hopes that Linux users will have a deep understanding of Debian.
1. Statement

* Version information:

The latest version of this document will be posted in: LinuxSir. Org Forum Debian release forum;

You can also get from http://debian.linuxsir.org.
* Feedback:

All comments, error reports, other information and criticism, Please mail to etony@tom.com;

Or post it in the Debian release forum of LinuxSir. Org.
* Copyright information:

Copyright (c) 2006-2007 belongs to etony C. F..

Reprint please indicate from http://debian.linuxsir.org /.

2. Overview of dpkg

In its manpage, the description is as follows:

Dpkg-a medium-level package manager for Debian.

Dpkg-Debian intermediate Software Package Manager.

Dpkg is the mainstay of the Debian software package management system. It is responsible for installing, uninstalling, configuring, and maintaining installed software packages. it is also the backend of many software package management tools in the Debian system. for more information about dpkg, see: http://www.dpkg.org

Dpkg maintains the software in the system through the database, including the file list, dependency, software status, and other details, usually in the/var/lib/dpkg directory. make sure that the system and database are consistent. therefore, dpkg is very robust and excellent in processing programs.

When processing a software package, dpkg should first determine whether it will cause system chaos. When it is found that it may occur, dpkg will refuse to install the software, rather than manually loading the software into the system, then, we threw the mess to the user.

Dpkg is a huge family that not only provides a large number of Parameter options, but also provides many sub-commands such:

Dpkg-deb

Dpkg-divert

Dpkg-query

Dpkg-split

Dpkg-statoverride

Start-stop-daemon

...

This document is not a dpkg manpage and will not introduce all parameters and sub-commands. It is also quite painful to remember all parameters, here, we only provide an example of common parameters and commands.

Dpkg covers most of the features of the dpkg family, so dpkg can be used as an ALL-IN-ONE software to better use ALL the features of the dpkg family.
3. deb Software Package naming rules:

The Debian Software Package naming conventions are as follows: <软件包名称> _ <版本> - <修订号> _ <平台> . Deb

* Package Name ):
* Version Number ):
* Build Number ):
* Platform (Architecture ):
O i386
O all: platform independent. Applicable to all platforms, such as text, webpages, images, media, and pdf.

For example

* Nano_1.3.10-2_i386.deb
O package name: nano
O version: 1.3.10
O Revision No.: 2
O platform: i386

4. Software Package Processing

(Note: The operation in this article takes nano as an example)

Dpkg-deb: used to process local Debian software packages. You can extract the software package information and data from the. deb file. For more information, see the online manual of dpkg-deb.

* List the content of a software package:

Tony @ tony :~ /Doc/dpkg $ dpkg-deb-c nano_1.3.10-2_i386.deb | more
Drwxr-xr-x root/root 0 00:29:18 ./
Drwxr-xr-x root/root 0 00:29:07./etc/
-Rw-r -- root/root 11887 00:29:07./etc/nanorc
Drwxr-xr-x root/root 0 00:29:14./usr/
Drwxr-xr-x root/root 0 00:29:12./usr/share/
Drwxr-xr-x root/root 0 00:29:01./usr/share/doc/
Drwxr-xr-x root/root 0 00:29:15./usr/share/doc/nano/
-Rw-r -- root/root 1847 02:29:02./usr/share/doc/nano/AUTHORS
-Rw-r -- root/root 2338 05:33:13./usr/share/doc/nano/README
-Rw-r -- root/root 3175 17:36:11./usr/share/doc/nano/THANKS
-Rw-r -- root/root 2206 10:28:06./usr/share/doc/nano/TODO
-Rw-r -- root/root 1066 21:09:26./usr/share/doc/nano/UPGRADE
-Rw-r -- root/root 35996 05:45:07./usr/share/doc/nano/faq.html
......

* View the software package information

Tony @ tony :~ /Doc/dpkg $ dpkg-deb-I nano_1.3.10-2_i386.deb
New debian package, version 2.0.
Size 477372 bytes: control archive = 2656 bytes.
12 bytes, 1 lines conffiles
714 bytes, 18 lines control
3529 bytes, 51 lines md5sums
613 bytes, 21 lines * postinst #! /Bin/sh
160 bytes, 5 lines * postrm #! /Bin/sh
379 bytes, 20 lines * preinst #! /Bin/sh
288 bytes, 14 lines * prerm #! /Bin/sh
Package: nano
Version: 1.3.10-2
Section: editors
Priority: important
Architecture: i386
Depends: libc6 (>=2.3.5-1), libncursesw5 (>=5.4-5)
Suggests: spell
Conflicts: nano-tiny (<= 1.0.0-1), pico
Replaces: pico
Provides: editor
Installed-Size: 1108
Maintainer: Jordi Mallach
Description: free Pico clone with some new features
GNU nano is a free replacement for Pico, the default Pine editor. Pine is
Copyrighted under a restrictive licence, that makes it unsuitable
Debian's main section. GNU nano is an effort to provide a Pico-like
Editor, but also includes some features that were missing in the original,
Such as 'search and replace ', 'Goto line' or internationalization support.

* Re-build the Software Package

For example, nano (1.3.10) must meet the following dependencies:

$ Dpkg-deb-f nano_1.3.10-2_i386.deb depends // depends for the corresponding query segment

Libc6 (> = 2.3.5-1), libncursesw5 (> = 5.4-5)

If the system does not meet the dependency, for example, the current version cannot be met, you can use the following method to handle the problem. Of course, in this case, the installed nano may not run normally, this method can be applied to flexible installation of some software.

$ Mkdir nano // create the nano directory

$ Dpkg-deb-e./nano_1.3.10-2_i386.deb./nano/DEBIAN // extract Control Files

$ Dpkg-deb-x./nano_1.3.10-2_i386.deb./nano // extract the program file

$ Vi./nano/DEBIAN/control // modify control information

$ Dpkg-deb-B nano nano_1.3.10-2_ill.deb // repackage

5. Database Query

The current version of dpkg uses text files as databases. the general name is in the/var/lib/dpkg directory. the general name stores the software status and control information in the status file. back up the control file in the info/directory and. the list file records the list of installation files, under which. mdasums stores the MD5 code of the file.

It's time to experience using the database:

$ Dpkg-l
Desired = Unknown/Install/Remove/Purge/Hold
| Status = Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/Err? = (None)/Hold/Reinst-required/X = both-problems (Status, Err: uppercase = bad)
|/Name Version Description
++-============================================= ======================================
Ii aalib1 1.4p5-28 ascii art library-transitional package
Ii adduser 3.85 Add and remove users and groups
Ii alien. 63 install non-native packages with dpkg
......

Each record corresponds to a software package. Note the first, second, and third characters of each record. This is the status identification of the software package, followed by the software package name, version number, and simple description.

* The first character is the expected value, which includes:
The o u status is unknown, which means that the software package is not installed and the user has not sent an installation request.
O I user requests to install the software package.
O r user requests to uninstall the software package.
O p user request to clear the software package.
O h user requests to keep the software package version locked.
* The second column is the current state of the software package. This column includes six States of the software package.
O n software package is not installed.
O I software package installation and configuration.
O c software package has been installed before and is now deleted, but its configuration file remains in the system.
The o u software package is unwrapped, but not yet configured.
O f tried to configure the software package but failed.
O h software package installation, but not successful.
* The third column identifies the error status, which can be summarized as four states. The first one is null, and the other three symbols identify the problem.
O h software packages are forcibly maintained because they cannot be upgraded due to dependency requirements of other software packages.
O r software package is damaged and may need to be re-installed for normal use (including deletion ).
O x soft package is damaged and forcibly maintained.

You can also perform fuzzy search in the unified character mode. For example, I want to find all the software packages starting with nano:

$ Dpkg-l nano *
Desired = Unknown/Install/Remove/Purge/Hold
| Status = Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/Err? = (None)/Hold/Reinst-required/X = both-problems (Status, Err: uppercase = bad)
|/Name Version Description
++-============================================= ==============================================
Ii nano 1.3.10-2 free Pico clone with some new features
Pn nano-tiny (No description available)
Un nanoblogger (No description available)

The above status description: nano version 1.3.10-2 is installed in the system, nano-tiny is installed, and then deleted. nanoblogger is never installed.

If you think that too many dpkg parameters are difficult to remember, you can use dpkg-query to query the dpkg database.

Example:

* Nano files in the query system:

$ Dpkg -- listfiles nano

Or

$ Dpkg-query-L nano

* View the software nano details:

$ Dpkg-s nano

Or

$ Dpkg-query-s nano

* Check the status of software packages in the system. Fuzzy search is supported:

$ Dpkg-l

Or

$ Dpkg-query-l

* View the owner package of a file:

$ Dpkg-query-S nano

Or

$ Dpkg-S nano

6. install the software package

Run the following command:

$ Dpkg-l nano
Un nano (No description available)

The current nano status indicates that the nano package has never been installed in the system. You can run the following command to install the local nano package:

$ Dpkg-deb-e./nano_1.3.10-2_i386.deb

When you use dpkg to install the software package, it mainly involves two phases: first unpackage, and then run the postinst control script (if any), which is the so-called configuration phase. after the package is decompressed, The -- intall option of dpkg automatically calls the configuration phase. note: You must specify the parameter during the operation. the actual path of the deb file. Only the file name cannot be found.

In this way, the software installation can be split into two opposing processes:

* Dpkg -- unpack
* Dpkg -- configure

Unpack

Run

# Dpkg -- unpack nano_1.3.10-2_i386.deb


Then

$ Dpkg-l nano
IU nano 1.3.10-2 free Pico clone with some new features

The nano package is installed in the system but is not configured.

Unpacking may include the following steps:

* Decompress the control file to a temporary directory.
* Run preinst (if any). The service is usually stopped.
* Decompress the configuration file to the/etc directory and add the. dpkg-new suffix to prevent conflict.
* Decompress data.tar.gz to the system root directory (-- root = dir ).
* Extract the control file to the/var/lib/dpkg/info directory and add the software name prefix. update the database.
* Set the status of the software package to "unpacked" in the database ".

Only unpacking does not ensure that the software runs properly.

Configuration

# Dpkg -- configure nano

$ Dpkg-l nano
Ii nano 1.3.10-2 free Pico clone with some new features

As shown in the output, nano is installed properly.

After the software is unwrapped, you also need to adjust it, such as modifying the configuration file according to the actual situation. this step is usually performed automatically during the installation process. Of course, you can call it manually. This time, the software name is used instead of the deb file name.

The command dpkg-L nano can be used for verification.

This process may include the following steps:

* Ask whether to handle the configuration file by overwriting the current version or not (this problem occurs when the software is upgraded)
* Run the postinst script
* Mark the software package as "installed"

To modify the configuration option again, run:

# Dpkg-reconfigure nano

7. uninstall software

Package uninstallation and cleanup are two different concepts In Debian. the difference is that after a software package is deleted (uninstalled), its configuration files will remain in the system and will be deleted only when it is cleared. by default, Debian only deletes the configuration file. if you want to clear the software package, the delete operation is performed implicitly before it is cleared.

To delete a software package, dpkg needs to use the -- remove option to uninstall the software package. Unlike installation, to delete a software package, only the software package name is required, not the actual deb file name.

Delete

# Dpkg-r nano

* First run the prerm script (if any ).
* The configuration file is retained, and all other files are deleted.
* Delete all configuration files of the software package under the/var/lib/dpkg/info directory, and retain the postrm and list files.
* Finally, dpkg changes the software status to delete in the database.

Run

$ Dpkg-l nano

Rc nano 1.3.10-2 free Pico clone with some new features

Clear

# Dpkg-P nano

* Delete all files. All files are removed (deleted from the system ).
* Run the postrm script. if it still exists, run the postrm script.
* Delete postrm and list files. The two files are retained, and remove postfix. postrm and postfix. files from the system.
* Mark the software package as not installed in the dpkg Database

$ Dpkg-l nano
Pn nano (No description available)

Note the output status: pn, which means the software package is actually cleared, but there are records of this software package in the database. therefore, pn clearly indicates that nano has been installed before and has been completely cleared in the software package database.
8. Exception Handling

Sometimes, because the dependency cannot be met, or there is a conflict, the file will be overwritten, or the control script has an error and the installation fails. this type of problem never exists in the stable release (this is considered a major error ). however, it is inevitable to run the unstable release system.

Handle file conflicts

Dpkg does not allow a software package to overwrite files of other software packages. you can force dpkg to overwrite software that belongs to other software packages (using -- force-overwrite), but this is very dangerous. if this is only a temporary conflict (which is common in unstable), there is no major problem in overwriting. please note that in this case, relevant error reports should be submitted to the software package maintainer.

If you are using an unofficial package, or a software package Built on your own through alien or checkinstall, you should change the name of the file in the package, or discard the use of such software packages.

An error occurred while controlling the script during installation. the problematic script is another cause of the problem. if an error occurs in the postinst control file of the software package, you cannot use dpkg to complete the configuration of the software package.

This error must be reported to the Error Tracking System as a serious problem. you can debug the script to identify the problem. For example, you can insert set-x after the first line of the script, tracks its running status. unless necessary, you should also refuse to use such software packages.

Process corrupted control files during uninstallation

When there is a problem with the uninstall script of the software package. even if you can forcibly delete files that are not cleared by the control script, it may prevent dpkg from correctly maintaining your system and possibly leaving junk files in the system. there are no good solutions for such problems (You are strongly advised to submit an error report), only waiting for software updates (or fixing the software package ). then, the related files are detached using the update package.
9. dpkg vs rpm

* List software packages installed in the system
O rpm-qa
O dpkg -- list
* List software package information
O rpm-qi pkgname
O dpkg -- status pkgname
* List the files installed in a package
O rpm-ql pkgname
O dpkg -- listfiles pkgname
* List information about local package files
O rpm-qpi file. rpm
O dpkg -- info file. deb
* List files contained in local package files
O rpm-qpl file. rpm
O dpkg -- contents file. deb
* Install a local package
O rpm-I file. rpm
O dpkg -- install file. deb
* Clear the package from the system
O rpm-E pkgname
O dpkg -- purge pkgname
* Query File Ownership
O rpm-qf file
O dpkg -- search file

10. References

* Debian Reference Manual
* Debian FAQs
* APT and Dpkg quick reference table; can also be obtained from the apt-dpkg-ref_5_all.deb package.
* Dpkg vs rpm
* Debian GNU/Linux Anwenderhandbuch
* Pkg software maintenance tools
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.