dpkg aborts when its package database in /var/lib/dpkg/ is corrupted or incomplete, usually after an interrupted transaction or disk error. Fixes center on reconfiguring dpkg and repairing or restoring its status database.
The dpkg package manager keeps a database under /var/lib/dpkg/ that records every installed package and its metadata. The key files are the status file (the master record of installed packages and their state), the per-package info files under /var/lib/dpkg/info/, and the updates journal in /var/lib/dpkg/updates/. When dpkg reads these and finds them malformed, truncated, or inconsistent, it raises "unrecoverable fatal error, aborting" and refuses to continue rather than risk further damage. The word "unrecoverable" means dpkg could not safely auto-correct what it found, not that your system is beyond repair. The usual triggers are a transaction that was cut short (power loss, the process being killed, or the system crashing mid-install) or underlying storage problems (I/O errors, a full disk, or filesystem corruption). On Raspberry Pi and other SD-card systems, flash corruption is an especially common cause. Note that this is a database-corruption error, not a "package manager is locked" error. Stale lock files produce a different message ("Could not get lock /var/lib/dpkg/lock..."). Treat lock removal as a separate, last-resort action and only after confirming no apt or dpkg process is running.
First read the full error: dpkg usually names the exact file or package it choked on (for example a truncated status file, a specific info/<package>.* file, or an entry in updates/). Note it down — later steps target it.
Before touching anything, make sure no package operation is actually in progress. Removing files or locks while apt or dpkg is mid-transaction can corrupt the database further.
# Show any running apt/dpkg processes
ps aux | grep -E 'apt|dpkg' | grep -v grepIf you see an active apt, apt-get, dpkg, or unattended-upgrade process, let it finish or wait for it to exit. Do not kill it unless it is clearly hung.
The safest first repair is to ask dpkg to complete any transaction that was cut short. This is non-destructive and resolves the majority of cases caused by an interrupted install.
sudo dpkg --configure -aThen repair any broken dependency state:
sudo apt-get install -fIf both commands complete without the fatal error, run sudo apt update to confirm the system is healthy again.
dpkg stages in-progress changes in /var/lib/dpkg/updates/. A corrupt file here is a frequent cause of this exact error and is safe to clear — dpkg rebuilds it from status.
Inspect the directory first:
ls -la /var/lib/dpkg/updates/If the error referenced a file in this directory, move the contents aside (do not delete blindly) and reconfigure:
sudo mkdir -p /var/lib/dpkg/updates.bak
sudo mv /var/lib/dpkg/updates/* /var/lib/dpkg/updates.bak/ 2>/dev/null
sudo dpkg --configure -aIf this resolves things, you can remove the backup directory later.
If the error points at a corrupt or truncated status file, dpkg keeps a recent backup at /var/lib/dpkg/status-old. Restoring it rolls back to the last known-good state.
Check what is available and confirm the backup is non-empty:
ls -la /var/lib/dpkg/status*If status-old exists and has a sensible size, preserve the bad file first, then restore:
sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.bad
sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status
sudo dpkg --configure -aKeeping status.bad lets you recover if the backup turns out to be older than expected. After this, run sudo apt update to verify.
If the error names one specific package (for example wireless-regdb), its info files under /var/lib/dpkg/info/ may be damaged. Move that package's info files aside rather than deleting them outright, so you can restore if needed.
# Replace PACKAGE with the name from the error
sudo mkdir -p /root/dpkg-info-bak
sudo mv /var/lib/dpkg/info/PACKAGE.* /root/dpkg-info-bak/ 2>/dev/null
sudo dpkg --configure -aThen reinstall the package cleanly so its metadata is regenerated:
sudo apt-get install --reinstall PACKAGEUse dpkg --remove --force-remove-reinstreq only as a last resort if reinstall is impossible, since it discards the package's recorded state. Prefer --reinstall first.
Database corruption is often a symptom of a full or failing disk. Rule these out, especially on SD-card systems.
# Is the root filesystem full?
df -h /
# Look for I/O errors or bad-sector warnings
sudo dmesg | grep -iE 'error|i/o|sector' | tail -20
sudo journalctl -p err -b --no-pager | tail -30If the root filesystem is near capacity, free space and retry:
sudo apt-get clean
sudo apt-get autocleanIf you see persistent I/O errors or bad sectors, the storage device is failing. Back up your data and plan to replace the disk or SD card — software repairs will not hold on bad media.
This is unrelated to the corruption error and should only be done if you have confirmed (Step 1) that no apt or dpkg process is active and you separately see a lock-related message. Removing locks while a real transaction is running can corrupt the database further, which is the opposite of what you want here.
# Re-verify nothing is running first
ps aux | grep -E 'apt|dpkg' | grep -v grep
# Only if the output above is empty:
sudo rm -f /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock /var/cache/apt/archives/lock
sudo dpkg --configure -aFull dpkg database rebuild (last resort only): If every step above fails and the database is genuinely unrecoverable, you can rebuild it. This discards dpkg's record of what is installed, so attempt it only after the other steps and only with a backup. Never run it while the disk shows I/O errors — fix the hardware first.
# Back up the existing database (do NOT delete it)
sudo cp -a /var/lib/dpkg /var/lib/dpkg.backup-$(date +%F)
# Recreate the minimal structure
sudo mkdir -p /var/lib/dpkg/updates
sudo touch /var/lib/dpkg/status
sudo apt-get update
sudo apt-get install -fAfter this, the system will under-report installed packages; use dpkg --get-selections from a similar healthy machine to help rebuild state if needed. Because this is destructive to package state, prefer reinstalling the OS over a database rebuild on an important system.
Recovering status from /var/backups: Many Debian/Ubuntu systems keep compressed snapshots at /var/backups/dpkg.status.*.gz. If both status and status-old are bad, these are a safer source:
ls -la /var/backups/dpkg.status*
sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.bad
sudo zcat /var/backups/dpkg.status.0.gz | sudo tee /var/lib/dpkg/status > /dev/null
sudo dpkg --configure -aSD card and ARM systems: On Raspberry Pi, repeated corruption almost always means a worn or failing SD card. If repairs do not stick, reflash to a fresh, good-quality card. Note that AppArmor (Debian/Ubuntu's default MAC system) does not normally confine dpkg, so it is rarely the cause here; SELinux is not used by default on Debian/Ubuntu, so do not disable security modules chasing this error.
dpkg: serious warning: files list file for package 'package-name' contains empty filename
How to fix "files list file contains empty filename" in APT
E: Sub-process /usr/bin/dpkg returned an error code (2)
How to fix "Sub-process /usr/bin/dpkg returned an error code (2)" in APT
dpkg-divert: error: rename involves overwriting 'path' with different file
How to fix dpkg-divert rename conflicts in APT
E: Sub-process /usr/bin/dpkg returned an error code (1) during kernel installation
How to fix "dpkg returned an error code (1)" in APT kernel installation
dpkg: dependency problems prevent configuration of triggers
dpkg: dependency problems prevent configuration of triggers in apt