This error occurs when dpkg cannot remove a Linux kernel package due to unmet dependencies or broken package states. Fix it by repairing dependencies with apt, configuring pending packages, or manually removing old kernels to free /boot space.
The dpkg package manager is refusing to uninstall a Linux kernel image package (like linux-image-5.4.0-42-generic) because other packages depend on it or the package management system is in a broken state. This typically happens during kernel upgrades when your /boot partition is full, or when DKMS modules (like wireguard) are incompatible with the kernel version you're trying to remove. The error indicates that dpkg has detected unmet dependencies that would be violated if it allowed the removal.
First, identify which kernel you are currently running so you do not accidentally remove it:
uname -rThis outputs something like 5.15.0-86-generic. Do NOT remove this kernel as it will make your system unbootable.
Try the most straightforward fix first - repair any broken dependencies and configure unconfigured packages:
sudo apt --fix-broken installIf that succeeds, your issue is resolved. If not, proceed to the next step.
If dpkg was interrupted during a previous operation, configure any unconfigured packages:
sudo dpkg --configure -aThen try the fix again:
sudo apt --fix-broken installIf the above steps do not work, check which kernel versions are installed on your system:
dpkg -l | grep linux-imageThis shows all installed kernel packages. Identify old versions that you can safely remove (anything except your current kernel from Step 1).
Once you identify an old kernel to remove, use dpkg to force-purge it:
sudo dpkg --purge --force-all linux-image-5.4.0-42-genericReplace 5.4.0-42-generic with the actual old kernel version. The --force-all flag overrides dependency checks. After removing one or two old kernels, proceed to the next step.
After manually removing old kernels, fix any remaining broken dependencies:
sudo apt-get -f installThen update your package cache and try to complete any pending operations:
sudo apt-get update
sudo apt-get upgradeFinally, clean up any leftover package configuration files and perform automatic removal of unused packages:
sudo dpkg -P $(dpkg -l | grep ^rc | awk '{print $2}')
sudo apt-get autoremoveThis removes packages marked for removal and cleans up the system.
For most systems, keep only 2 kernel versions installed: the currently running kernel and the immediately previous one. This provides a fallback if a kernel update breaks your system. The /boot partition is typically small (200-500MB) and runs out of space quickly with multiple kernel versions since each kernel includes compressed images, initramfs files, and DKMS modules. On systems with LVM, encrypted filesystems, or other storage constraints, managing kernel count is especially critical. If you prefer a more automated approach, use sudo apt autoremove which safely removes old kernels while keeping at least the current and previous versions. For DKMS-related failures, check if DKMS modules are compatible with your target kernel using dkms status before attempting removal.
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