How to Fix ‘dpkg Returned an Error Code (1)’ During unattended-upgrades in Ubuntu

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.

  1. Open a Terminal window (or connect via SSH).
  2. Inspect the recent unattended-upgrades log output:
    sudo tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.log
  3. Review the dpkg journal logs to pinpoint the exact failing package:
    sudo tail -n 50 /var/log/dpkg.log
  4. Look for lines marked status half-configured or error 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.

  1. Execute the manual configuration command:
    sudo dpkg --configure -a
  2. If prompted about configuration files (such as keep the local version currently installed), select the appropriate option to resolve the file conflict.
  3. 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.

  1. Navigate to the package info directory:
    cd /var/lib/dpkg/info/
  2. Locate the post-installation script for the problematic package:
    ls -la [package-name].*
  3. Temporarily move the failing script out of the active path:
    sudo mv [package-name].postinst ~/postinst.backup
  4. Re-run the dpkg configuration:
    sudo dpkg --configure -a
  5. 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.

  1. Check partition capacity:
    df -h /boot
  2. If /boot is at 95% to 100% utilisation, purge retired kernel images:
    sudo apt autoremove --purge -y
  3. 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.

  1. Check the systemd service status:
    systemctl status unattended-upgrades.service
  2. If inactive or failed, restart the service:
    sudo systemctl restart unattended-upgrades.service

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.