Looking One Layer Down With dpkg
Goal
You query the system with dpkg, and build a .deb yourself and even install it. If you handle packages without apt, it becomes clear what apt had been doing for you. At the end, starting from the two status letters, you finish off one by one the packages that dpkg -i left half done.
Why it matters
dpkg does not know the repository. It unpacks the file it is given, and finishes (configure) only if the dependencies are satisfied. That is why dpkg -i does not pull in dependencies automatically and stops in the iU state. Once you know this division of labor, everything is explained: why "install order" matters on an air-gapped network, and what apt-get -f install fixes. And the habit of checking a file's origin with dpkg -S is the first weapon you reach for on an unfamiliar server.
The last step is an incident. When putting a vendor's .deb in with dpkg -i fails, all of apt stops, but the place it stopped differs per package: iF, where the post-install script failed; iU, where a missing dependency kept it from entering configuration; and the case where it tried to overwrite someone else's file and could not even unpack. If you casually accept the "fix by removing" that apt-get -f install proposes, packages you need disappear. This is where reading the two status letters and dpkg's error lines comes in.
Steps
- Create the
/root/dpkgdirectory and write only the number of packages currently in the installed (ii) state as a single numeric line in/root/dpkg/count.txt. - Pick out only those files installed by the
coreutilspackage that are under/usr/bin/, and save them to/root/dpkg/coreutils-bin.txt. - Write only the package name that owns
/usr/bin/lson one line in/root/dpkg/owner.txt. - With
dpkg-query, make a single line for thebashpackage with이름 버전 아키텍처(name, version, architecture) separated by spaces, and save it to/root/dpkg/bash-fields.txt. - Build the
/opt/fixtures/pkg/labhub-tooldirectory into a.deband save it as/root/dpkg/labhub-tool_1.2.0-labhub1_all.deb. - Save the control information of the package you built to
/root/dpkg/deb-info.txtand its file list to/root/dpkg/deb-contents.txt. - Install that package, and save the result of running the
labhub-toolcommand to/root/dpkg/run.txt. - Incident: run
incident pk-half-installedand read the ticket. Three vendor packages are all in an "install not finished" state and apt is stuck. Bring all three to the fully configured state (ii), and in/root/incident/pk-half-installed/report.txtwrite a cause code for each package (dep-missing,file-conflict,interrupted,postinst-fail,wrong-arch) and oneevidence:line.
Notes
- The first two letters of
dpkg -lare "desired state + actual state". The three header lines explain what each letter means. - Common mistake 1: if you count the whole
dpkg -loutput in step 1, it counts the header too and adds 5 lines. - Common mistake 2: if you go into the directory to be built and build with relative paths in step 5, the output file easily ends up in the wrong place. Specify absolute paths.
- Common mistake 3: in the incident, accepting apt's "fix" as it is. First read what it says it will remove.
- Incident tools:
incident listshows the list, andincident show <이름>(name) shows the ticket (a colleague's report) again. Raising the same incident again returns it to its original broken state. - Write the report to
/root/incident/<이름>/report.txt(name is the incident name): one line<이름>: <원인 코드>(name: cause code) per target, plusevidence: <관찰한 출력 한 줄>(one line of output you observed). The evidence line is checked against the output actually seen in the incident. - Grading does not look only at the report. The actual state, such as the dpkg status DB, apt's candidate, and signature verification, must be right, and workarounds that only erase the symptom (forced installs, removals, turning off signatures) fail.
Working directory and installed list
Create the /root/dpkg directory and write only the number of packages currently in the installed (ii) state as a single numeric line in /root/dpkg/count.txt.
In the output of dpkg -l, the real package lines start with a state mark (ii and so on). The five header lines are not packages.
The list of files a package installed
Pick out only those files installed by the coreutils package that are under /usr/bin/, and save them to /root/dpkg/coreutils-bin.txt.
dpkg -L prints directories too. If you need only the executables, you have to filter by path.
Who installed this file
Write only the package name that owns /usr/bin/ls on one line in /root/dpkg/owner.txt.
dpkg -S answers in the format 'package: path'. What you need is the part before the colon.
Pulling out only the fields you want
With dpkg-query, make a single line for the bash package with 이름 버전 아키텍처 (name, version, architecture) separated by spaces, and save it to /root/dpkg/bash-fields.txt.
In the format string of dpkg-query -W -f, wrap a field in a dollar sign and braces. A line break is a backslash and n.
Building a .deb from a fixture
Build the /opt/fixtures/pkg/labhub-tool directory into a .deb and save it as /root/dpkg/labhub-tool_1.2.0-labhub1_all.deb.
dpkg-deb --build turns an entire directory that contains DEBIAN/control into a package. You can give the output file name as the second argument.
Taking the built package apart
Save the control information of the package you built to /root/dpkg/deb-info.txt and its file list to /root/dpkg/deb-contents.txt.
dpkg-deb has the options -I (information) and -c (contents list). The two outputs are completely different in nature.
Install and check the state
Install that package, and save the result of running the labhub-tool command to /root/dpkg/run.txt.
After installing with dpkg -i, check the Status line of dpkg -s. If the dependencies cannot be resolved, it stays in the iU state.
Incident: after dpkg -i, apt stops whatever it does
Running incident pk-half-installed gives you a server where putting in a vendor delivery (/srv/vendor) with dpkg -i failed (read the ticket first). Symptom: since then apt refuses with dependency errors whatever it installs, and all three of vend-agent, vend-report, and vend-cli look like "the install did not finish". Bring all three to the fully configured state (ii) and get apt working again. The collection server for vend-agent is in the ticket. Modifying the vendor .deb files or the scripts inside them, removing packages to make errors go away, or forcing overwrites is a failure. In /root/incident/pk-half-installed/report.txt, write three lines <패키지>: <코드> (package: code) and evidence: <관찰한 출력 한 줄> (one line of output you observed). The code is one of dep-missing (stopped before configuration because a dependency package is missing), file-conflict (stopped while trying to overwrite another package's file), interrupted (dpkg was cut off midway), postinst-fail (the post-install script failed), or wrong-arch (the architecture differs).
Direction: a dpkg install has two stages, "unpack → configure", and the cause is at which stage, and where in it, each package stopped. Also read what apt's proposed fix intends to remove; the request is to use all three. Tools: dpkg -l (the first two letters), dpkg --audit, the operator's screen log (/var/log/vend-install.log), dpkg -S, dpkg-deb -I and -c, and dpkg's rerun of the configuration stage. Concretely: read in the dpkg -l header what iF, iU, and in each mean, and find the last error line for each package in the log. For the one that failed in the configuration stage, look at what that script requires (the error message and the examples in /usr/share); for the one that stopped while unpacking, look at the current owner of that file and the vendor notice.