This error occurs when your disk or partition is full, preventing apt from writing packages or metadata. It can also occur when inodes are exhausted, even with free disk space remaining. Fix it by cleaning up disk space, removing old kernels, purging cache files, or extending storage.
The "E: Write error - write (28: No space left on device)" error indicates that apt cannot write files to disk because your filesystem is full. This can happen for two reasons: actual disk space exhaustion (no free blocks) or inode exhaustion (no free file metadata slots). Even if `df -h` shows 50% free space, running out of inodes will still trigger this error. The write operation fails at the system level (errno 28), preventing apt from completing package installations or updates.
First, determine which partition is full:
df -hThis shows you which mountpoint (/, /var, /boot, etc.) is at 100%. Also check inode usage:
df -iIf IUse% is 100% for any partition even though block usage is low, you have inode exhaustion. Note which partition needs space freed.
The apt cache often contains old downloaded .deb files. Clean them:
sudo apt cleanThis removes all cached package files. For aggressive cleaning (removes partial packages too):
sudo apt autocleanAutoclean keeps only packages for currently installed versions, removing older version packages you may never use again.
Autoremove deletes packages that were dependencies for other packages but are no longer needed:
sudo apt autoremove --purgeThe --purge flag also removes configuration files. This often frees significant space if you have upgraded your system multiple times.
If df -h shows /boot is full, you have multiple kernel versions installed. List installed kernels:
dpkg -l | grep linux-imageKeep the current kernel and one previous kernel as backup. Remove old ones:
sudo apt remove linux-image-<old-version>Replace <old-version> with versions shown in the previous command (not the current running one). You can find your current kernel with:
uname -rLog files in /var/log can grow extremely large. Safely clean them:
sudo du -h /var/log | sort -h | tail -20This shows the largest log files. Remove old compressed logs:
sudo rm /var/log/*.gz /var/log/*.old /var/log/*.[0-9].gzFor active logs, truncate them (don't delete, just empty):
sudo truncate -s 0 /var/log/syslog
sudo truncate -s 0 /var/log/auth.logUse du to find the largest directories:
sudo du -h --max-depth=1 / | sort -hFor deeper investigation of the largest culprits:
sudo du -h --max-depth=2 /var | sort -h | tail -10
sudo du -h --max-depth=2 /home | sort -h | tail -10Common space hogs: /var/cache, /var/log, /home (user files), and /tmp. Once identified, remove unnecessary files manually or with apt clean commands.
After cleanup, verify space is available:
df -hIf /var or the partition containing /var/cache/apt is now below 90%, retry your apt command:
sudo apt update
sudo apt upgradeIf you still get the write error, check which specific partition is still full and target cleanup there.
If df -i shows 100% IUse% but df -h shows free space, you have inode exhaustion. Find directories with excessive small files:
find /var/log -type f | wc -l
find /var/cache -type f | wc -l
find /tmp -type f | wc -lRemove small cached files:
sudo rm -rf /var/cache/apt/archives/*
sudo rm -rf /tmp/*
sudo find /var/log -type f -deleteThen verify:
df -iIf space is still insufficient after cleanup, you may need to extend your partition. This requires:1. Unused space on your disk (check with fdisk -l), or
2. Another partition you can shrink
Extending a partition is advanced; ensure you have backups first. Tools like GParted (GUI) or fdisk/parted (CLI) can resize partitions. Alternatively, add a new disk and mount it at /var to distribute storage load.
In cloud environments (AWS EC2, Azure, DigitalOcean), be aware that root volume sizes are fixed at launch; expanding requires detaching and resizing the volume, then rebooting. Docker containers inherit host filesystem limits; if running apt in a container, you're constrained by the container's host disk. WSL2 allocates a virtual disk; use wsl --manage <distro> --set-sparse true to reclaim space. For servers running unattended-upgrades, check /var/log/unattended-upgrades/ for large logs from repeated failed upgrades. Use logrotate to automate log rotation: edit /etc/logrotate.conf to compress and archive logs, freeing space automatically. For production systems, set up monitoring (Nagios, Zabbix, or cloud provider alerts) to trigger at 80% disk usage, preventing this error in the future.
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