TT Lab
Get started
Learn Learning paths Courses

Package Management

Looking One Layer Down With dpkg

Continue in TT Lab

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.

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.

Steps

  1. 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.
  2. Pick out only those files installed by the coreutils package that are under /usr/bin/, and save them to /root/dpkg/coreutils-bin.txt.
  3. Write only the package name that owns /usr/bin/ls on one line in /root/dpkg/owner.txt.
  4. 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.
  5. 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.
  6. 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.
  7. Install that package, and save the result of running the labhub-tool command to /root/dpkg/run.txt.
  8. Make /root/dpkg/report.txt with the following 4 lines. PACKAGE=labhub-tool / VERSION=<설치된 버전> / FILES=<이 패키지가 깐 실제 파일 개수(디렉터리 제외)> / OWNER_OF_LS=<3번에서 찾은 패키지 이름> (that is, the installed version, the actual number of files this package installed excluding directories, and the package name found in step 3)

Notes

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.

Package summary report

Make /root/dpkg/report.txt with the following 4 lines. PACKAGE=labhub-tool / VERSION=<설치된 버전> / FILES=<이 패키지가 깐 실제 파일 개수(디렉터리 제외)> / OWNER_OF_LS=<3번에서 찾은 패키지 이름> (that is, the installed version, the actual number of files this package installed excluding directories, and the package name found in step 3)

Reuse the files you made in earlier steps. For the file count, just count the real files in the dpkg -L result.