How to fix E: Write error - write (28: No space left on device) in APT
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.
Quick fix
Fixes E: Write error - write (28: No space left on device)
df -h- Check disk usage and identify the full partition
- Clean apt package cache
- Remove old and unused packages
- Handle /boot partition full (kernel-related)
df -hE: Write error - write (28: No space left on device)
What this error means
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.
Typical symptoms
- apt update, apt upgrade, or apt install commands fail with write error
- Error occurs even though you believe you have disk space available
- Running `df -h` shows most partitions have free space, but /var or /boot may be full
- Software updates cannot be downloaded or installed
- System stops responding during apt operations
- Previous apt operations may have been interrupted, leaving incomplete files
Common causes
- Root partition (/) or /var partition is full from large files or logs
- /boot partition is full from multiple kernel versions (common issue)
- Apt cache contains old .deb packages that were never cleaned
- Log files in /var/log have grown excessively without rotation
- Inode exhaustion from countless small files, even with free disk blocks
- Temporary files or cache files from other applications consuming space
- Previous interrupted apt operations left partial or orphaned files
How to fix "E: Write error - write (28: No space left on device)"
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.
Advanced notes
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.
Frequently asked questions
- What does "E: Write error - write (28: No space left on device)" mean?
- 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.
- How do I fix "E: Write error - write (28: No space left on device)"?
- 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.
- What causes "E: Write error - write (28: No space left on device)"?
- Root partition (/) or /var partition is full from large files or logs /boot partition is full from multiple kernel versions (common issue) Apt cache contains old .deb packages that were never cleaned
- Is the "E: Write error - write (28: No space left on device)" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐APT Official Documentation
- ๐Linux man pages - df command(Official Docs)
- ๐Linux man pages - du command(Official Docs)