APT and dpkg status database interoperability during aborted distribution upgrades
0 reputation · 03 Apr 2023, 16:37 UTC
0 reputation · 03 Apr 2023, 16:37 UTC
During a Debian distribution upgrade, the system relies on the interaction between the APT dependency resolver and the dpkg status database located in /var/lib/dpkg/status. When an upgrade is interrupted mid-process, the system often enters a state where packages are unpacked but not yet configured.
While dpkg --configure -a and apt-get install -f are documented methods for resolving broken dependencies and completing configurations, uncertainty remains regarding the automated handling of obsolete packages from the previous release when the upgrade is aborted and the user attempts to stabilize the current state.
Specifically, it is unclear how the system prioritizes the cleanup of these legacy packages without risking the removal of critical system components required for the recovery process itself.
32775 reputation · 03 Apr 2023, 20:28 UTC
APT does not automatically identify and purge all obsolete packages during a recovery attempt. While apt-get install -f (fix-broken) resolves unmet dependencies to stabilize the system, it does not treat the presence of legacy packages from a previous release as a trigger for removal unless those packages directly conflict with a required dependency of a newer package.
Obsolete packages—those no longer present in the current configured repositories—typically remain in the dpkg status database as installed. They are not flagged for removal by default during recovery because APT prioritizes system stability over cleanup. To remove these, you must either use apt autoremove --purge (for packages marked as automatically installed that are no longer needed) or manually identify and purge them using tools like aptitude search '~o'.
When a recovery attempt encounters a dependency loop between a partially upgraded package and a legacy package, the expected behavior is as follows:
half-configured or unpacked) can block the removal of other packages until their own configuration is completed or they are forced out.To stabilize the system without risking the removal of essential recovery tools, follow this scoped sequence:
dpkg state transitions first.
sudo dpkg --configure -asudo apt-get install -fsudo apt-get -s autoremove --purgeThis behavior assumes a standard Debian-based environment (e.g., Debian or Ubuntu). Because resolver logic varies by version, you should verify your current state before executing removals:
dpkg --auditcat /etc/os-releasetail -n 100 /var/log/dpkg.logNote: If you are encountering a specific dependency loop that apt-get install -f cannot resolve, please provide the output of apt-get check, as this will determine if manual dpkg --purge intervention is required for a specific blocking package.
Use comments to ask for clarification. Post a solution as an answer.
5,190 reputation · 04 Apr 2023, 02:30 UTC
After dpkg --configure -a and apt --fix-broken install succeed, the system may still show obsolete packages from the old release. These packages remain marked as manually installed unless they were originally pulled in as dependencies. apt autoremove only removes packages that are automatically installed and not required by any other installed package, so it will not touch obsolete packages that are still marked manual. To make them eligible for autoremove, you can first change their install reason with apt-mark auto (or use aptitude to mark them auto) and then run apt autoremove --purge after verifying the list with a dry‑run. This step ensures that cleanup does not accidentally remove essential packages that are still needed for recovery.