This error occurs when the /boot partition (or root filesystem) is full during apt updates or kernel installations. The fix involves freeing disk space by removing old kernels and packages that are no longer needed.
The "gzip: stdout: No space left on device" error appears when `apt-get`, `apt-get upgrade`, or `dpkg --configure` tries to compress and write files (typically kernel initramfs images) but there is no available space on the filesystem. On most Debian/Ubuntu systems, the /boot partition is small (often 100-500 MB) and is used exclusively for kernel images and bootloader files. When you install new kernel versions, the system creates new initramfs images using gzip compression. If the /boot partition is full, gzip cannot write its output and fails with this error. The most common scenario: You have several older kernel versions installed, each taking 20-50 MB of space in /boot. When a new kernel arrives via apt update/upgrade, there's no room for both the new kernel and the old ones.
First, determine how much space is available and what is consuming it:
df -hLook for the /boot line. If it shows 100% or close to it (e.g., "/dev/sda1 228M 218M 0 100% /boot"), you need to free space immediately.
df -h | grep bootAlso check inode usage:
df -i /bootIf the IUse% is 100%, you have an inode problem rather than disk space.
See which kernel versions are currently installed:
dpkg -l 'linux-image-*' | grep '^ii'This lists all installed kernel images. You'll see output like:
ii linux-image-5.15.0-76-generic 5.15.0-76.83~20.04.1 amd64
ii linux-image-5.15.0-78-generic 5.15.0-78.85~20.04.1 amd64
ii linux-image-5.15.0-84-generic 5.15.0-84.93~20.04.1 amd64Typically, you only need the currently running kernel and perhaps the previous one. All others are safe to remove.
Find your currently running kernel:
uname -rRemove all but the currently running kernel. Replace X.X.X-XX with an old kernel version:
sudo apt-get remove linux-image-5.15.0-76-genericOr remove multiple old kernels at once:
sudo apt-get remove linux-image-5.15.0-76-generic linux-image-5.15.0-78-genericAfter removing each kernel, you should see space freed. Verify with:
df -h | grep bootRemove kernels until /boot is below 80% capacity.
Once you've freed enough space, clean up dangling dependencies and old kernel-related packages:
sudo apt-get autoremoveThis removes:
- Unused kernel headers
- Unused linux-modules packages
- Other orphaned dependencies
Then clean the package cache:
sudo apt-get cleanVerify /boot space again:
df -h | grep bootIf apt-get upgrade was interrupted, complete the installation:
sudo apt-get -f installOr finish a stalled dpkg configuration:
sudo dpkg --configure -aThen retry the upgrade:
sudo apt-get upgradePrevent this issue in the future by automatically removing old kernels when new ones arrive.
Option 1: Using apt-get autoremove automatically
Enable Debian's automatic cleanup by editing /etc/apt/apt.conf.d/50unattended-upgrades:
sudo nano /etc/apt/apt.conf.d/50unattended-upgradesEnsure this line is uncommented:
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";Option 2: Using ubuntu-kernel-purge (Ubuntu only)
sudo apt install ubuntu-kernel-purgeThis tool automatically purges old kernel versions while keeping the current and at least one backup kernel.
Option 3: Manual cron job
Create a daily cleanup job:
sudo crontab -eAdd this line:
0 2 * * * apt-get autoremove -y >> /var/log/kernel-cleanup.log 2>&1This runs autoremove daily at 2 AM.
If you frequently run out of space despite removing kernels, your /boot partition is too small. This is a more advanced fix.
Check current /boot size:
lsblk
# or
fdisk -l | grep bootResize the partition (requires downtime and can be risky):
Option A: Merge /boot with root filesystem (recommended for new systems)
- This requires reinstalling or using complex partition tools
- Not recommended unless you're rebuilding the system
Option B: Expand the existing /boot partition
- Requires live USB/boot media
- Use tools like GParted or fdisk
- Extends the partition and filesystem
For new installations: Use a larger /boot partition (500 MB to 1 GB). Most modern installers default to only 100-200 MB.
# View recommended size (modern kernels)
ls -lah /boot/Sum of all kernel versions typically = 50 MB × (number of kernels). For 3-5 kernels, allocate 500 MB minimum.
### Understanding /boot Partition Design
The /boot partition exists because:
1. Bootloader (GRUB) needs a known location to find kernels
2. Some systems require /boot to be on the first disk sectors
3. Kernel images are large (30-50 MB each) and compress slowly
Modern kernels are much larger than kernels from 10 years ago. A partition sized for old kernels will quickly fill with new ones.
### Inode Exhaustion
If df -i /boot shows 100% IUse, you have too many small files, not too little space:
# Find what's consuming inodes
find /boot -type f | wc -l
# Check inode size
sudo tune2fs -l /dev/sda1 | grep "Inode size"Solutions:
- Remove old kernels (most reliable)
- Reformat /boot with larger inode size (destructive)
- Migrate /boot to root filesystem (advanced)
### Debian Bug History
Debian has a known issue (#929424) where update-initramfs stores temporary files in /boot instead of /tmp. This was fixed in later versions. If you're on an old Debian/Ubuntu release, upgrade to get the fix:
sudo apt-get update && sudo apt-get upgrade### SELinux on CentOS/RHEL
If you're using CentOS or RHEL with SELinux enabled, the issue may also involve security contexts:
# Check if SELinux is the issue
sudo setenforce 0
sudo apt-get -f install # or equivalent yum command
# If this works, the issue is SELinux, not disk space### Container/VM Considerations
If running in a container or VM:
- Disk space may be artificially limited
- Check host filesystem: docker exec container_name df -h
- Expand the VM disk if necessary
- In Docker, prune old images/layers: docker system prune
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