This dpkg error occurs when your system runs out of disk space during package installation or updates. The /boot partition is often the culprit, filled with old kernel images. Free up space by removing outdated kernels and clearing cache files.
This error happens when the dpkg package manager tries to write extracted package files to disk but fails because there's no available space. On Debian-based systems like Ubuntu, the /boot partition is frequently the bottleneck—it accumulates old Linux kernel versions over time and can fill up completely. When dpkg attempts to write files (like new kernels), the operation fails, leaving the system in a broken state with incomplete package installations. The "No space left on device" condition is absolute: the filesystem must have free inodes and free blocks. dpkg operations are sensitive to this because they involve writing large files like kernel images (often 50-200 MB each) and updating system-critical files.
Run this command to see all partitions and their usage:
df -hLook for any partition at 100% usage. Pay special attention to /boot. If /boot shows 100%, you've found the culprit. Run this to see what's consuming space:
du -sh /boot/*This will show large files (usually old kernels) taking up space.
Before removing kernels, identify which one is currently running:
uname -rThis outputs something like 5.15.0-84-generic. Make a note of this—DO NOT remove this kernel. List all installed kernels:
dpkg -l 'linux-*' | grep '^ii'You'll see multiple kernel versions. Identify the older ones that differ from your current kernel.
Replace 5.15.0-83-generic with the actual old kernel version from the previous step (one that's NOT your current kernel):
sudo apt-get remove --purge linux-image-5.15.0-83-generic
sudo apt-get remove --purge linux-headers-5.15.0-83-genericOr use autoremove to remove all unused kernels at once (safe, only removes unused ones):
sudo apt-get autoremove --purgeIf you get "No space left on device" even with autoremove, try removing the oldest kernel manually first to create space, then use autoremove.
Once you've freed some space, clean up the apt cache:
sudo apt clean
sudo apt autocleanapt clean removes all cached .deb files. apt autoclean removes only old cached packages. This can free up several hundred MB.
After freeing space, fix any incomplete package operations:
sudo apt-get -f installThis repairs dependencies and completes any interrupted installations. Then try your original command again:
sudo apt update
sudo apt upgradeOn systems with separate /boot partitions: The /boot partition is critical for system boot and should have at least 100-200 MB free at all times. If you find yourself constantly removing kernels, consider expanding /boot during the next maintenance window using tools like LVM (Logical Volume Manager) or by repartitioning.
On cloud VMs and Docker containers: If you're running on a cloud instance (AWS, DigitalOcean, Linode, etc.), the root filesystem size was set during initial provisioning. After freeing space, monitor disk usage with tools like ncdu for long-term capacity planning.
Alternative approach using update-initramfs: Some users remove only the initramfs files instead of full kernel packages: sudo update-initramfs -d -k 5.15.0-83-generic (replace with old kernel version). This is more conservative but frees less space.
Distribution-specific notes: Ubuntu normally handles kernel cleanup automatically if you use the "linux-image-generic" meta-package (which depends on the latest kernel). However, if you manually installed specific kernel versions, you must manage cleanup yourself.
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