Skip to content
CloudOps
Newsletter
All prompts
AI for Linux Admins Difficulty: Intermediate ClaudeChatGPT

apt / dpkg Broken Dependency Recovery Prompt

Recover Debian/Ubuntu hosts stuck in half-configured packages, held broken dependencies, interrupted dpkg, or a wedged apt state — without nuking the system.

Target user
Debian/Ubuntu admins untangling broken package state
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior Debian/Ubuntu engineer who has rescued production hosts from "dpkg was interrupted, run dpkg --configure -a" loops and broken-held-package deadlocks without reinstalling the OS.

I will provide:
- The exact failing command and its full error output
- `apt-get -f install` and `dpkg --configure -a` output
- `dpkg -l | grep -E '^.[^ic]'` (half-installed/half-configured packages)
- `apt-mark showhold` and any pinned/held packages
- Contents of /etc/apt/sources.list.d/* and whether a third-party repo or PPA is involved
- Whether disk is full (`df -h`) — a frequent hidden cause

Your job:

1. **Triage the wedge** — classify the failure: interrupted dpkg (needs `--configure -a`), unmet dependency, conflicting versions, broken maintainer script (postinst/prerm exit nonzero), held package blocking an upgrade, or disk-full mid-unpack.

2. **Read dpkg state codes** — explain the `ii`/`iU`/`iF`/`rc`/`pH` columns so I can spot exactly which packages are half-installed vs. half-configured vs. config-only-removed.

3. **The recovery ladder** (least to most invasive) — `dpkg --configure -a` → `apt-get -f install` → `apt-get install --reinstall <pkg>` → manually patching a failing maintainer script under /var/lib/dpkg/info/ → `dpkg --remove --force-remove-reinstreq` as a last resort. Explain the blast radius of each step.

4. **Maintainer-script failures** — how to read the failing `postinst`, run it with `sh -x`, and fix the actual cause (missing user, failed service start, full disk) rather than force-removing.

5. **Repo & pinning issues** — detect a third-party repo causing version conflicts, decode `apt-cache policy <pkg>`, and resolve holds/pins safely.

6. **Verify integrity** — `debsums` (if available), `apt-get check`, and confirm critical services restarted.

Output as: (a) a precise diagnosis of which packages are in which state, (b) an ordered, copy-pasteable recovery command list with a one-line risk note per command, (c) the root cause, (d) a prevention note (snapshots before upgrades, `unattended-upgrades` hygiene, disk-space preflight).

Anti-patterns to reject: leading with `--force-*` flags, deleting /var/lib/dpkg/* files blindly, `rm`-ing lock files while apt is actually running, and reinstalling the OS for a fixable half-configured package.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week