Reviewing system logs or running routine maintenance on an Ubuntu server only to find email alerts or log entries reading “E: Sub-process /usr/bin/dpkg returned an error code (1)” generated by unattended-upgrades indicates that automated background security patching has failed. In Ubuntu 22.04 LTS and 24.04 LTS, the unattended-upgrades daemon runs headless; when a security package’s post-installation script crashes or encounters an unexpected interactive prompt, dpkg halts, locking the package manager from applying further updates.
Identify the Failing Package via Log Inspection
The unattended-upgrades service keeps meticulous chronological logs detailing which package script triggered the exit code 1 failure.
- Open a Terminal window (or connect via SSH).
- Inspect the recent unattended-upgrades log output:
sudo tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.log - Review the dpkg journal logs to pinpoint the exact failing package:
sudo tail -n 50 /var/log/dpkg.log - Look for lines marked
status half-configuredorerror processing package. Note the exact package name (for example,linux-image-generic,grub-efi-amd64, or a third-party daemon).
Manually Complete Pending DPKG Database Configuration
Forcing dpkg to run post-installation scripts interactively reveals missing configuration parameters or conflicting configuration files.
- Execute the manual configuration command:
sudo dpkg --configure -a - If prompted about configuration files (such as
keep the local version currently installed), select the appropriate option to resolve the file conflict. - If the configuration completes without errors, test the automated upgrade pipeline in dry-run mode:
sudo unattended-upgrade --dry-run --debug
Repair Damaged Package Installation Scripts in /var/lib/dpkg/info
If a specific package persistently throws error code 1 due to a faulty maintainer script (such as a postinst or prerm script failing on syntax), moving the script permits dpkg to finalise package registration.
- Navigate to the package info directory:
cd /var/lib/dpkg/info/ - Locate the post-installation script for the problematic package:
ls -la [package-name].* - Temporarily move the failing script out of the active path:
sudo mv [package-name].postinst ~/postinst.backup - Re-run the dpkg configuration:
sudo dpkg --configure -a - Reinstall the package cleanly using APT to restore genuine maintainer scripts:
sudo apt install --reinstall [package-name]
Purge Stale Linux Kernel Images to Free /boot Space
Unattended-upgrades frequently fails with error code 1 when attempting to install a new security kernel into a /boot partition that has run out of disk space.
- Check partition capacity:
df -h /boot - If
/bootis at 95% to 100% utilisation, purge retired kernel images:sudo apt autoremove --purge -y - Run the dependency fixer:
sudo apt --fix-broken install
Verify Unattended-Upgrades Service Health
Once package integrity is restored, ensure the background service is active and clear of error states.
- Check the systemd service status:
systemctl status unattended-upgrades.service - If inactive or failed, restart the service:
sudo systemctl restart unattended-upgrades.service