Dealing with Broken Maintainer Scripts Sometimes the upgrade gets interrupted because one
of the package maintainer scripts fails (usually, it is the
postinst
). In those cases, you can try to
diagnose the problem, and possibly work around it, by editing the problematic script.
Here we rely on the fact that maintainer scripts are stored in
/var/lib/dpkg/info/
and that we
can review and modify them.
Since maintainer scripts are usually simple shell scripts, it is possible to add a set -x line just after
the shebang line and arrange them to be rerun (with
dpkg --configure -a
for
postinst
) to see
precisely what is happening and where it is failing. This output can also nicely complement any
bug report that you might file.
With this newly gained knowledge, you can either fix the underlying problem or transform the
failing command into a working one (for example by adding
|| true
at the end of the line).
Note that this tip does not work for a failing
preinst
since that script is executed even before
the package gets installed so it is not yet in its final location. It does work for
postrm
and
prerm
although you will need to execute a package removal (respectively upgrade) to trigger them.
The dpkg Log File The
dpkg
tool keeps a log of all of its actions in
/var/log/dpkg.log
. This log is extremely verbose,
since it details all the stages of each package. In addition to offering a way to track dpkg’s behav-
ior, it helps to keep a history of the development of the system: you can find the exact moment
when each package has been installed or updated, and this information can be extremely useful
in understanding a recent change in behavior. Additionally, with all versions being recorded, it is
easy to cross-check the information with the
changelog.Debian.gz
for packages in question, or
even with online bug reports.
# tail /var/log/dpkg.log 2021-01-06 23:16:37 status installed kali-tools-gpu:amd64 2021.1.0
2021-01-06 23:16:37 remove kali-tools-gpu:amd64 2021.1.0 2021-01-06 23:16:37 status half-configured kali-tools-gpu:amd64 2021.1.0
2021-01-06 23:16:37 status half-installed kali-tools-gpu:amd64 2021.1.0
2021-01-06 23:16:37 status config-files kali-tools-gpu:amd64 2021.1.0
2021-01-06 23:16:37 status not-installed kali-tools-gpu:amd64 Reinstalling Packages with apt --reinstall and aptitude reinstall When you mistakenly damage your system by removing or modifying certain files, the easiest way
to restore them is to reinstall the affected package. Unfortunately, the packaging system finds that
the package is already installed and politely refuses to reinstall it. To avoid this, use the --reinstall
option of the
apt
and
apt-get
commands. The following command reinstalls postfix even if it is
already present:
194
Kali Linux Revealed
# apt --reinstall install postfix The
aptitude
command line is slightly different but achieves the same result with
aptitude
reinstall postfix
. The
dpkg
command does not prevent re-installation, but it is rarely called
directly.