The KAGAMI mark КАГАМИ
kagami.bg/academy · lesson · machine-readable viewUPDATED 2026-10-03
IDENTITY
module
KW I30 · Unwanted package from a factory image: prove it, remove it
series
KAGAMI Way · Track I — Infrastructure
level
Intermediate
duration
~15 min
trust_label
UPDATED 2026-10-03 (apt-get, apt-mark, apt-cache, dpkg commands checked against the Debian manual pages; not run on live hardware in this revision)
language
human view: en · bulgarian edition: /academy/moduli/KW_I30_Parasite_Package.html
previous
KW_I29_Five_Untested_Trials.html
next
index.html · all KAGAMI Way modules (end of track)
PURPOSE

Teach a method for a Debian-family machine whose factory image ships a package nobody chose: gather evidence of where it came from, find what depends on it, measure any claimed harm, remove it with a dry run first, and record the decision. Evidence before verdict; unmeasured claims are labelled as observations.

KEY CONCEPTS
COMMANDS / PATHS
CHECKLIST
NEXT MODULE

index.html · all KAGAMI Way modules · offer: Quick experiment (kagami.bg/stalbata/)

SOURCES
TAGS
aptdpkgmetapackagedry-runreverse-dependenciesfactory-imagechange-record
UPDATED · 03.10.2026

Unwanted factory-image package: prove it, remove it

A new machine arrives with programs nobody asked for. Some only take up space, some spin the processor, some are tied to something else so that removing them drags it along. This lesson is the method: first a trail and evidence, then a dry run, and only then the real removal — and a written record of the decision.

⏱ ~15 min Intermediate Infrastructure apt · dpkg · dependencies · dry run
The machine's command line (apt, dpkg)🔒 local
🔄
UPDATED · 03.10.2026 — what changed
The lesson was generalised from an earlier case of ours into a general method for Debian-family systems. Specific program names, machine names, figures and internal paths were removed. The apt-get, apt-mark, apt-cache commands and the dpkg log path were checked against the Debian manual pages (apt 3.0.3). Added: a look at reverse dependencies with --installed and the "measured or not" rule for every harm claim.
⚠️ Unverified: we did not run the commands on live hardware in this revision — so the label is UPDATED, not TESTED or VERIFIED. Behaviour on distributions outside the Debian family was not checked.

01What you will learn

02Before you start

⚠️
What is NOT proven here
The commands were checked against the official manuals but were not run by us in this revision. The examples are generic: <package>, <metapackage>, <program> are placeholders — run nothing until you have replaced them and read the dry-run result.

03Steps

  1. The trail: when and with what it arrived

    The dpkg log keeps when each package was installed (default path: /var/log/dpkg.log; older ones are in dpkg.log.1 and so on). Find the package's line and see what else was installed in the same hour. If hundreds of packages arrived in one minute, it was most likely the image or a bulk install, not a command of ours.

    bash · when the package was installed
    # the lines for the package; replace <package>
    grep " install <package>" /var/log/dpkg.log*
    # packages installed manually (explicitly requested)
    apt-mark showmanual
    ⚠️
    A trail, not a verdict
    "It came with the image" is an inference from a date and neighbouring installs. Record it as an inference. The log may have been rotated and old lines may be gone.
  2. Who holds it: reverse dependencies

    Before removing anything, see who requires it. If another installed package depends on it, removing it drags that package along. Be especially careful with metapackages — packages that are only a list of other packages (for example "the whole desktop").

    bash · who requires it and what the metapackage carries
    # only installed packages that depend on it
    apt-cache rdepends --installed <package>
    # what the metapackage itself requires
    apt-cache depends <metapackage>
    ✅
    Rule
    If the reverse dependencies are only metapackages, do not remove "blind". Read the metapackage's list first — step 5 explains why.
  3. What it actually does: measured or not

    The most common mistake is to write "it does harm" without numbers. So for every claim of harm, mark it: measured (there is a number, a log or a before-and-after copy) or observation (it seemed so to us). Typical things you can measure: space used, processes that hang and eat CPU, errors in the logs.

    One classic cause of a hanging process: a program that on start launches another, helper process. When the caller's time runs out and it kills only the first, the helper is left an orphan and keeps running. So with "a core at 100%", look at the parent too, not only the program's name.

    bash · which processes use the most CPU (not run)
    ps aux --sort=-%cpu | head -n 10
    ℹ️
    The honest record
    Write "measured: …; not measured: …". That way the next person knows what is fact and what is assumption.
  4. Check your own code

    A package that is unwanted by you may be needed by a script of yours that nobody recorded as a dependency. Search for the program's name in all your scripts before you remove the package. If you find a call, first prepare a replacement and test it, then remove.

    bash · where the program is called
    grep -rI "<program>" <scripts-folder>
  5. Dry run, and marking the rest

    apt-get -s (--simulate) works out what would happen and changes nothing. The Remv lines are what would be removed. Read them one by one — if you see a program you want, stop.

    If the package is part of a metapackage, removing it also removes the metapackage, and everything the metapackage brought becomes "unneeded", so a later autoremove may clear it. The cure is to mark the rest as manually installed before you remove.

    bash · dry run, then marking
    # 1. dry run: what would go
    apt-get -s purge <package>
    # 2. review what the metapackage carries and choose what stays
    apt-cache depends <metapackage>
    # 3. mark the chosen ones as manual (the list is yours)
    apt-mark manual <package-1> <package-2>
    ⚠️
    Trap: a blind autoremove
    After removal, apt-get autoremove removes packages that were installed automatically and are no longer needed. If you have not marked the rest, it can take more programs with it. Run it as a dry run first: apt-get -s autoremove.
  6. The real removal, the check and the record

    When the dry-run result satisfies you, remove the package. purge also removes configuration files; remove leaves them. Choose deliberately: if you may need to go back, remove is gentler.

    bash · removal and check
    apt-get purge <package>
    # check: the program is gone
    command -v <program> || echo "gone"
    # autoremove — dry run only
    apt-get -s autoremove

    Finally, write the decision down: what was removed, when, why, what replaces it and how to go back. Without a record, the next update or the next person may bring the package back and start over.

    ✅
    Rule
    Dry run first, real run second, and never an automatic clean-up done blind. Every step leaves a trace.

04Check

1. What does the package's line in the dpkg log tell you?

2. Why do you not run autoremove right after purge?

3. What is right before purge?

4. How do you write about the package's harm?

05What's next

06Sources

  1. apt-get(8) — -s/--simulate, purge, remove, autoremove (apt 3.0.3; checked 03.10.2026).
  2. apt-mark(8) — manual, auto, showmanual.
  3. apt-cache(8) — depends, rdepends, --installed.
  4. dpkg(1) — the /var/log/dpkg.log log.
  5. KAGAMI's own earlier case with an unwanted package on an AI machine — generalised into a method; the specific data is not published and was not repeated for this revision.