The "dpkg was interrupted" error occurs when unattended-upgrades detects that a previous package installation was not completed, leaving the system in an inconsistent state. This can happen after unexpected reboots, power failures, or system crashes during package operations. The fix involves running 'dpkg --configure -a' to complete any pending package configurations and restore system consistency.
This error indicates that unattended-upgrades has detected an incomplete package operation from a previous system state. The dpkg package manager maintains a database of package states, and when an installation, upgrade, or removal is interrupted before completion, dpkg is left in a state where some packages are unpacked but not fully configured. When unattended-upgrades runs and detects this condition, it stops and notifies you that the system cannot proceed with new upgrades until the interrupted operation is resolved. The 'dpkg --configure -a' command is the standard way to complete any pending package configurations and bring the system back to a consistent state. This error typically appears after: - Unexpected system reboot during package updates - Power failure or system shutdown during apt operations - Manual interruption of apt/dpkg processes - Disk space issues that caused operations to fail partway through
First, verify that dpkg is indeed in an interrupted state by running:
sudo dpkg --configure -a --dry-runThe --dry-run flag shows what would be configured without actually making changes. This lets you see which packages are waiting to be configured without taking action yet.
Once you've confirmed the pending configurations, run the command to actually complete them:
sudo dpkg --configure -aThis command goes through all packages that have been unpacked but not yet fully configured and completes their installation. This typically takes a few minutes depending on how many packages are waiting.
After dpkg completes, update your package lists and check for any remaining issues:
sudo apt update
sudo apt --fix-broken installThe --fix-broken install command will install any missing dependencies or fix any remaining broken package states. This ensures your system is fully consistent before resuming automatic updates.
In rare cases where dpkg lock files are stuck, you may need to remove them. Only do this if dpkg is completely hung and unresponsive:
sudo rm -f /var/lib/dpkg/lock
sudo rm -f /var/lib/dpkg/lock-frontend
sudo rm -f /var/cache/apt/archives/lockAfter removing lock files, run dpkg again:
sudo dpkg --configure -aLock file removal should only be a last resort when the system is truly deadlocked.
After resolving the dpkg state, verify that your package system is consistent:
sudo apt-get checkThis command checks for broken package dependencies without making any changes. If it completes without errors, your system is ready for normal operations.
To prevent this error from appearing in the future, configure unattended-upgrades to automatically repair interrupted dpkg state. Edit the configuration file:
sudo nano /etc/apt/apt.conf.d/50unattended-upgradesFind or add the following line (it may already be there):
Unattended-Upgrade::AutoFixInterruptedDpkg "true";If it's set to false or missing, change it to true. This setting makes unattended-upgrades automatically run dpkg --configure -a if it detects an interrupted state, preventing manual intervention from being required:
sudo systemctl restart unattended-upgradesRestart the service to apply the configuration change.
Review system logs to understand what caused the dpkg interruption originally:
sudo journalctl -xe | tail -50
sudo tail -100 /var/log/unattended-upgrades/unattended-upgrades.logLook for:
- Unexpected reboot messages
- Power failure indicators
- Disk space warnings (No space left on device)
- Kernel panic messages
Understanding the root cause helps prevent future interruptions. For example, if disk space was the issue, you may need to clean up or expand your filesystem.
AutoFixInterruptedDpkg Setting: Unattended-upgrades includes the AutoFixInterruptedDpkg setting which defaults to true on many systems. When enabled, this setting automatically runs dpkg --configure -a if the daemon detects an incomplete dpkg state before attempting any new package operations. This makes the manual error essentially transparent to the user.
Understanding dpkg States: The dpkg package manager tracks states for each package: unpacked (files extracted but not configured), configured (fully installed and ready), removed (deleted but config files remain), and purged (completely removed). When an operation is interrupted mid-process, packages can be left in the unpacked or half-configured state. Running dpkg --configure -a completes the move to the configured state.
Prevention Through Stability: Common causes of interruption include:
- Power issues: Use UPS (Uninterruptible Power Supply) for servers
- Disk space: Monitor available space and set up alerts
- Network: Ensure stable network for remote upgrades
- Reboot timing: Configure unattended-upgrades to reboot during maintenance windows when users are less likely to interrupt
Force-Confold vs Interactive: When multiple versions of a configuration file exist, dpkg can prompt for manual resolution. In automated environments, the --force-confold flag keeps the old configuration file automatically. Unattended-upgrades handles this through its own configuration settings.
Checking dpkg.log: For forensic analysis of what failed:
sudo tail -100 /var/log/dpkg.log | grep 'status'This shows the state changes dpkg recorded, helping identify at what point the interruption occurred.
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