This error occurs when dpkg's package database becomes corrupted or damaged. It prevents package installation, updates, and removal until resolved. Most fixes involve clearing locks, reconfiguring dpkg, or restoring backup database files.
The dpkg package manager maintains a database in /var/lib/dpkg/ that tracks all installed packages and their metadata. When this database becomes corrupted—due to interrupted installations, I/O errors, disk corruption, or incomplete transactions—dpkg cannot safely proceed with operations. The "unrecoverable fatal error" message means dpkg detected corruption severe enough that it cannot attempt recovery automatically. This typically happens when critical files like the status file, available file, or package info entries are malformed or incomplete. Common corruption sources include: interrupted apt operations (power loss or forced termination), disk I/O errors (failing storage media), filesystem issues, or hardware failures. On Raspberry Pi and similar systems, SD card corruption is a frequent culprit.
Lock files can prevent dpkg from operating if not cleaned up properly from a previous interrupted operation.
sudo rm -f /var/lib/dpkg/lock-frontend
sudo rm -f /var/lib/dpkg/lock
sudo rm -f /var/cache/apt/archives/lockAfter removing the locks, try running apt again:
sudo apt updateThis simple fix resolves the issue if the lock files were the cause. If it still fails, continue to the next step.
Force dpkg to reconfigure all packages, which can repair incomplete transactions.
sudo dpkg --configure -aThis command tells dpkg to complete any interrupted package configurations. Then attempt to fix broken dependencies:
sudo apt --fix-broken installThis step resolves corruption from incomplete installations or interrupted apt processes.
If the status file is corrupted, dpkg keeps a backup that can be restored.
First, check if the backup exists and is valid:
ls -la /var/lib/dpkg/status*If status-old exists, restore it:
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 -aThis rolls back to the last known good state. After restoration, verify the system is functional and attempt updates again.
If a specific package is identified as corrupted, remove its metadata files and force-remove the package.
First, identify the problematic package from the error message (e.g., "wireless-regdb"). Then:
sudo rm -fv /var/lib/dpkg/info/PACKAGE_NAME.*
sudo dpkg --remove --force-remove-reinstreq --force-depends PACKAGE_NAMEReplace PACKAGE_NAME with the actual package name. After removal, reconfigure dpkg:
sudo dpkg --configure -a
sudo apt updateThis approach removes corrupted package records without touching other system packages.
Disk errors or insufficient space can cause database corruption. Check both:
# Check available disk space
df -h /
# Look for I/O errors in system logs
sudo dmesg | tail -20
sudo journalctl -xe --no-pager | tail -30If you see I/O errors, warnings about bad sectors, or your root filesystem is near capacity (>90% used), the issue is hardware-related or space-related.
For low disk space:
# Clean apt cache
sudo apt clean
sudo apt autocleanFor I/O errors, the storage device may be failing and require replacement or repair.
Full dpkg database rebuild: If the above steps fail, you can attempt to rebuild the dpkg database from scratch:
sudo mv /var/lib/dpkg /var/lib/dpkg-backup
sudo mkdir -p /var/lib/dpkg/updates
sudo touch /var/lib/dpkg/status
sudo apt update
sudo apt install -fThis is a more aggressive approach and should only be attempted after other solutions fail.
Hardware failure considerations: On Raspberry Pi and ARM systems, SD card corruption is common. If multiple repair attempts fail and you see persistent I/O errors, the storage device itself may be failing. Consider changing the SD card, storage reader, or checking your storage controller.
SELinux and AppArmor: On systems using SELinux or AppArmor, permission restrictions can prevent dpkg from accessing its database files. Check:
sudo aa-status
getenforceIf SELinux is enforced and showing denials, temporarily switch to permissive mode to test, or adjust the policy.
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