You run apt upgrade or dnf update on your VPS like you always do, and halfway through it falls over with something like No space left on device while writing an initramfs image. You check df -h and the main disk has 40 GB free. So what's full? Nine times out of ten it's /boot, a small separate partition that quietly fills up with old kernels until one day an update can't fit. Here's how to clear it safely without making your server unbootable.
Symptoms: How a Full /boot Shows Up
It rarely tells you "/boot is full" in plain words. You'll usually see one of these:
gzip: stdout: No space left on devicefollowed byE: mkinitramfs failureduring an apt upgradedpkg: error processing package linux-image-...and apt saying "You might want to run 'apt --fix-broken install'"- On AlmaLinux/Rocky:
installing package kernel-core-... needs 30MB more space on the /boot filesystem - Every later apt command complaining about half-configured packages, even ones that have nothing to do with the kernel
Confirm it in one command:
df -h /boot
If Use% is 95–100%, you've found the problem. If /boot isn't a separate mount (it just lives on /), this article isn't your issue. Look at general disk usage instead.
Cause: Old Kernels Pile Up
Every kernel update drops three or four files into /boot: the kernel itself (vmlinuz-*), an initramfs image, a System.map and a config file. A modern initramfs can easily be 60–100 MB. Many VPS images and older installers created /boot at just 250–500 MB, so four or five kernels is all it takes.
Normally the package manager removes old kernels for you. That breaks down when:
- Nobody's run
apt autoremovein months, so the oldlinux-image-*packages are still installed - Kernels were installed manually or via a
.deb/.rpm, so they aren't marked as auto-removable installonly_limitin/etc/dnf/dnf.confwas raised (or/bootis simply too small for the default of 3)- A previous upgrade already failed, leaving a half-written initramfs taking space
Step 1: Find Out Which Kernel You're Actually Running
This is the one rule you can't skip: never remove the running kernel. Check it first and write it down:
uname -r
Say it prints 6.8.0-45-generic. That package stays no matter what. Then see what's taking space:
ls -lh /boot
du -sh /boot/* | sort -h
Step 2 (Ubuntu/Debian): Remove Old Kernels the Clean Way
List installed kernel packages:
dpkg --list 'linux-image-*' | grep ^ii
First try the easy route. If apt still has a little room to work, this often fixes everything:
sudo apt autoremove --purge
If apt refuses because of the broken half-installed package, remove one or two old kernels directly with dpkg, which doesn't try to resolve the whole dependency tree first:
sudo dpkg --purge linux-image-6.8.0-31-generic linux-modules-6.8.0-31-generic
# repeat for other old versions — NOT the one from uname -r
Once there's breathing room, let apt finish what it started:
sudo apt --fix-broken install
sudo apt autoremove --purge
sudo update-grub
When even dpkg can't run
Sometimes /boot is so full that dpkg's removal scripts fail too. In that case, move (don't delete) the initramfs of one old kernel out of the way to free space temporarily:
sudo mv /boot/initrd.img-6.8.0-31-generic /root/
Then run the dpkg --purge for that same version. Once it's purged cleanly, delete the copy in /root. Only ever do this for a version that isn't your running kernel.
Step 2 (AlmaLinux/Rocky/CentOS): Use dnf
List installed kernels:
rpm -q kernel-core
Remove everything except the newest two (dnf keeps the running one automatically):
sudo dnf remove --oldinstallonly --setopt installonly_limit=2 kernel
On older CentOS 7 boxes, the equivalent is:
sudo yum install yum-utils
sudo package-cleanup --oldkernels --count=2
Then re-run the update that failed and check the bootloader entries:
sudo dnf update
sudo grubby --info=ALL | grep ^kernel
Step 3: Rebuild the Initramfs and Verify
If the original failure happened mid-write, the newest kernel's initramfs may be truncated. Rebuild it before you reboot:
| Distro | Rebuild command |
|---|---|
| Ubuntu / Debian | sudo update-initramfs -u -k all |
| AlmaLinux / Rocky | sudo dracut -f --regenerate-all |
Now check:
df -h /boot # aim for under 60–70%
ls -lh /boot # every vmlinuz should have a matching initrd/initramfs
A vmlinuz without a matching initramfs is a kernel that won't boot. If you see one, rebuild that version specifically before rebooting.
Before you reboot: take a VPS snapshot from your SkyServer panel. It takes a minute, and if the new kernel won't come up you can roll back instead of fighting with a rescue console.
Reboot, then confirm you're on the new kernel with uname -r.
Prevention: Stop It Happening Again
- Run autoremove as part of updates. On Debian/Ubuntu,
sudo apt update && sudo apt upgrade && sudo apt autoremove --purgeshould be a single habit, not three separate ones. - Let unattended-upgrades clean up. In
/etc/apt/apt.conf.d/50unattended-upgrades, setUnattended-Upgrade::Remove-Unused-Kernel-Packages "true"; - Cap kernels on RHEL-family systems. In
/etc/dnf/dnf.conf, setinstallonly_limit=2if/bootis under 500 MB. - Shrink the initramfs. On Ubuntu, setting
MODULES=depin/etc/initramfs-tools/initramfs.confbuilds only the drivers your VPS needs, which can cut each image dramatically. Test with a snapshot first. - Monitor it. Add
/bootto whatever disk alert you already use. A simple cron check works: alert whendf --output=pcent /bootpasses 80%.
If /boot is tiny (say 200 MB) and keeps filling even with two kernels, resizing it is possible but fiddly on a live system. Open a ticket with SkyServer support and we can talk you through the safest option for your plan.
Frequently Asked Questions
Can I just delete files in /boot with rm?
Avoid it. Deleting kernel files by hand leaves the package manager thinking they're still installed, and GRUB may still list them. Remove kernels through apt, dpkg or dnf so packages, modules and boot entries stay in sync. The temporary mv trick above is the only exception, and only for an old kernel.
How many kernels should I keep?
Two is the sweet spot: the one you're running and one previous version as a fallback. If a new kernel ever misbehaves, you can pick the older one from the GRUB menu via your VPS console.
Is it safe to reboot after the update failed?
Not until you've fixed it. A failed upgrade can leave a new kernel with a broken or missing initramfs set as the default. Free space, finish the update, rebuild the initramfs, verify /boot, take a snapshot, then reboot.
Why does df show free space but apt says the disk is full?
Because df -h with no argument shows every filesystem, and people usually glance at /. Apt is failing on /boot, a separate, much smaller partition. Running df -h /boot shows exactly where you are.
Does this affect cPanel/WHM servers?
Yes. cPanel runs on AlmaLinux/Rocky/CloudLinux, and a full /boot can block WHM's nightly OS updates. The dnf steps above apply. On CloudLinux, the kernel packages may be named differently, so check with rpm -qa | grep -i kernel before removing anything.
