SSD Nodes Learn Hosting plans →
How to do am Matt ConnorBy Matt Connor · Updated 2026-10-31

How to Remove Old Kernels and Free /boot on Ubuntu

See why `No space left on device` breaks apt, identify your running kernel, then safely purge old linux-image packages without touching the one in use.

Why apt no dey work when /boot full with old kernels

For Ubuntu, every kernel update dey write new files go inside /boot and e leave the old ones there. Because of this, small /boot partition fit full, and apt no fit finish installation again. The repair get two steps. Find out which packages for the machine be kernels and which one you booted with, then remove the remaining ones with apt autoremove --purge.

The order matter. The kernel wey dey run na the package wey you must not remove. The machine fit already dey in a state where apt no fit run at all. Diagnose first.

Wetin the failure really dey look like

A kernel version dey install two big files inside /boot: the compressed kernel (vmlinuz-<version>) and the initramfs (initial RAM filesystem, initrd.img-<version>, the small archive wey kernel dey unpack before e mount the real root). The initramfs dey build for your machine during installation, na why the install need free space, no be only download bandwidth. If space finish, the build fail and e carry the package down with am.

update-initramfs: Generating /boot/initrd.img-6.8.0-64-generic
gzip: stdout: No space left on device
E: mkinitramfs failure gzip 1
update-initramfs: failed for /boot/initrd.img-6.8.0-64-generic with 1.
dpkg: error processing package linux-image-6.8.0-64-generic (--configure):
 installed linux-image-6.8.0-64-generic package post-installation script subprocess returned error exit status 1

The version string go be your own. The compressor name dey come from COMPRESS= inside /etc/initramfs-tools/initramfs.conf, so recent image fit name zstd where older one name gzip. The two lines wey identify this problem na No space left on device and the dpkg: error processing package line under am.

After that, the package remain half-configured. Every later apt run wey install, upgrade, or remove packages go try configure am again, fail the same way, and end with E: Sub-process /usr/bin/dpkg returned an error code (1). apt update only dey download package information, so e no go hit this error. Na this part dey matter beyond disk space: unattended-upgrades dey run according to im timer, hit the same error, and stop. The server go look healthy, but e go quietly stop applying security patches. E also mean say any unrelated install wey you try go fail with that same line, and blame go fall on wetin you dey add at that time. Na why a Tailscale install wey fail for Ubuntu worth reading first as an apt error. If apt update fail before you reach this point, na separate problem be that, often a duplicate entry after the deb822 sources migration.

Check whether /boot na separate partition

Before you delete anything, find out wetin you really dey free.

findmnt /boot
findmnt -T /boot
df -h /boot /

The first command go print line only if /boot na im own mount point. The second one go always print, and e go show the filesystem wey really hold /boot. If both name the same filesystem as /, then /boot na just directory inside the root filesystem, and e no fit fill by itself: your root filesystem don full, and old kernels na only one of many contributors. For this case, sudo apt clean, wey dey empty the downloaded .deb files under /var/cache/apt/archives, go create some space. For machine wey get real /boot partition, apt clean no go free any space for there at all, because the cache dey for another filesystem.

Now get the number wey you go use compare.

df -h /boot
ls -lh /boot/vmlinuz-$(uname -r) /boot/initrd.img-$(uname -r)

Compare the Avail column with the size of those two files. The initrd na the bigger one. The next kernel update need space for another pair wey go dey roughly that size, so if Avail small pass the current initrd, the next update go already fail.

Find di kernel wey you dey run

uname -r
cat /var/run/reboot-required.pkgs

uname -r dey print release string of di kernel wey dey memory now. Copy dat string put for somewhere. Na dat version you no suppose touch.

Di second file dey exist only when package request reboot. A linux-image line inside am mean say newer kernel don install for disk but e never dey use, because machine never reboot since e land. Reboot before you clean if you fit. apt always protect di kernel wey you dey run, so if you clean while old kernel dey run, dat old version go remain as your fallback, and di newest kernel no go get test until di next boot. If dat reboot hang for A stop job is running, no hard reset di machine, because na systemd dey wait for one service to stop, and how to fix di 'A stop job is running' wahala explain how di timeout dey work and how you fit shorten am.

List kernel packages and read their states

dpkg --list | grep -E 'linux-(image|modules|headers|tools)' | awk '{print $1, $2}'

The first field na dpkg state code. ii mean say dem install and configure. iF mean say dem install but configuration never complete. Na exactly this one the failed upgrade above leave behind. rc mean say dem remove, but configuration still dey disk. E no dey use space for /boot and e safe to purge.

The second field tell you the kind package wey e be. Name wey get version inside am, like linux-image-6.8.0-64-generic, na one specific kernel. Name wey no get version, like linux-image-generic, linux-headers-generic or linux-generic, na meta package. E no contain kernel. E whole work na to depend on the newest versioned kernel, so apt upgrade go bring new kernels inside. If you remove meta package, machine no go receive kernel updates again, and nothing go warn you afterwards.

The families divide like this. linux-image-* hold the compressed kernel for /boot. linux-modules-* and linux-modules-extra-* hold the drivers under /lib/modules. linux-headers-* hold build headers under /usr/src. This mean say purging headers free space for root filesystem, no be /boot space. If your problem na full /boot partition, na the image packages you dey find.

ls -1 /boot/vmlinuz-*
ls -1 /lib/modules/

These two listings suppose match each other and also match the dpkg --list output. If directory dey for /lib/modules but no matching installed package dey, na leftover from person wey delete files by hand.

How apt dey decide which kernels to keep

apt autoremove no go remove kernel wey e consider protected, and the protected set include the kernel wey you dey run now. The retention policy don change between Ubuntu releases, so read am from your own machine instead of trusting any number wey somebody write down anywhere.

apt-config dump | grep -i -e neverautoremove -e versionedkernel
ls -l /etc/apt/apt.conf.d/01autoremove /etc/apt/apt.conf.d/01autoremove-kernels

APT::NeverAutoRemove na the list of package name patterns wey apt autoremove no dey touch. APT::VersionedKernelPackages na the list of name prefixes wey apt first treat as versioned kernel packages. For releases wey dey generate /etc/apt/apt.conf.d/01autoremove-kernels, /etc/kernel/postinst.d/apt-auto-removal rewrite that file every time dem install kernel package, so editing am by hand no go achieve anything: the next kernel install go overwrite your edit. For releases wey no get the file, apt apply the same protection internally. Either way, apt-config dump go show the rules wey dey active for your box, and that output na the correct answer for your release.

Cleanup wey safe to run

sudo apt update
sudo apt autoremove --purge --dry-run

--dry-run no dey change anything for disk, and e go print exactly wetin the real run go remove. Read the list. Two things suppose make you stop. Meta package like linux-generic or linux-image-generic for the removal list mean say something mark am as automatic, and removing am go end your kernel updates. The string from uname -r for the removal list mean say the kernel wey dey run no dey protected. This no suppose happen, so investigate am before you continue.

If the list look correct, run am for real.

sudo apt autoremove --purge
df -h /boot

The --purge part go delete the leftover configuration together with the package. E go free small extra space, and e go keep dpkg --list free from plenty rc lines accumulating, so the next audit go easy to read.

Then confirm say the boot menu don rebuild. Removing a kernel package dey run update-grub for you, so the menu suppose reference only files wey still dey exist.

sudo grep -o 'vmlinuz-[^ ]*' /boot/grub/grub.cfg | sort -u
ls -1 /boot/vmlinuz-*

Every version for the first output must show for the second one. If menu entry point to file wey don disappear, na so working server fit become one wey stop for the GRUB prompt. This na one way to VPS wey no go boot after kernel update, and e dey much harder to fix from rescue console than to prevent am here.

Why apt autoremove sometimes no dey remove anything

apt autoremove only dey remove packages wey dem mark as automatic. That means packages wey dem install as dependency for another thing. If you install kernel by yourself with apt install linux-image-6.8.0-40-generic, dem go mark am as manual. autoremove no go ever touch am, no matter how old e be.

apt-mark showmanual | grep -E '^linux-'

Any versioned kernel for that output no dey visible to autoremove. Give am back with the version strings from your own listing:

sudo apt-mark auto linux-image-6.8.0-40-generic linux-modules-6.8.0-40-generic
sudo apt autoremove --purge --dry-run

Leave the meta packages marked as manual. Dem suppose be manual because na you ask for dem.

One named kernel remove on purpose

Sometimes you fit want make one specific version go now, instead of waiting until policy allow am. Name the image package and make apt work out the rest.

sudo apt purge linux-image-6.8.0-40-generic

apt go print the removal list before e do anything, because linux-modules-extra-* depend on the image package and dem must go for the same transaction. That list wey e print na your real safety check. Na there you go notice if meta package dey get removed together with the version wey you mean remove. Answer n if anything wey you no expect dey inside. Then run sudo apt autoremove --purge to collect the module and header packages wey don lose the reason why dem suppose remain.

Why you no dey remove the running kernel

The kernel wey dey memory still dey run after dem delete im files, so e fit look like say nothing spoil at first. Wetin go spoil na everything wey the kernel never load yet. Purging linux-modules-$(uname -r) dey delete /lib/modules/$(uname -r)/, so the next module load go fail:

modprobe: FATAL: Module nf_tables not found in directory /lib/modules/6.8.0-64-generic

Modules wey the kernel don already load go still work, but firewall reload wey need module wey never load go fail from that point. Mounting filesystem type wey this kernel never touch since boot go fail too. Meanwhile /boot/vmlinuz-$(uname -r) don disappear, so boot menu no longer offer the kernel wey you dey run, and the next reboot go land for another place. The machine still dey serve traffic, but e don already become unbootable. Check uname -r against the removal list every time.

When /boot full too much make apt no fit run at all

Na this state dey make people search for this page. apt autoremove need dpkg to finish configuring the kernel package wey only configure partly first. That step rebuilds an initramfs, and e need space inside /boot wey no get space. Break the loop by hand, once.

uname -r
ls -1 /boot/initrd.img-*

Pick one initrd wey version no be the string uname -r give you, then delete that one file.

sudo rm /boot/initrd.img-6.8.0-40-generic
sudo apt --fix-broken install
sudo apt autoremove --purge
sudo update-grub

Every line get reason. rm na deliberate exception wey make dpkg believe say file dey, even though e no dey. apt --fix-broken install go complete the configuration wey fail before, now wey space dey for the initramfs. autoremove --purge go then remove the package wey file you delete belong to, together with the other old versions. This go make dpkg match wetin dey for the disk again. update-grub go rebuild the menu from the files wey really dey. No reboot between rm and update-grub, because during that time the menu fit still point to the file wey you just delete. If dpkg complain say e dey interrupted, sudo dpkg --configure -a go do the same repair as apt --fix-broken install.

Di same work for dnf systems

If your VPS dey run Fedora or one of the RHEL rebuilds like Rocky Linux, the way e work different. Debian and Ubuntu dey protect kernels with apt autoremove rules, and leave the cleanup for you or unattended-upgrades to trigger. But dnf dey enforce one count wey dem call installonly_limit. E dey remove the oldest kernel automatically as soon as new installation go pass that count. /etc/dnf/dnf.conf dey show only settings wey person set directly. If installonly_limit no dey set, e go use default value of 3. So, if you grep that file, e no tell you the value wey dey active. Ask dnf instead: use dnf --dump-main-config | grep installonly_limit for DNF5, or dnf config-manager --dump | grep installonly_limit for DNF4 systems like RHEL 10 and its rebuilds. Use man 5 dnf.conf to see wetin the option mean. Use sudo dnf remove --oldinstallonly to clear existing backlog. The running kernel dey protected there too. For wider comparison between the two package managers, see dnf and apt command equivalents.

Make e no happen again

Cleanup wey depend on you to remember go fail one day, so put am inside the thing wey dey install the kernels. Open /etc/apt/apt.conf.d/50unattended-upgrades and find these keys. The shipped file already get dem as commented lines:

Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";

Remove the comment mark from dem instead of adding another copy for the end. For apt configuration, the last assignment of a key dey win. So duplicate fit make the file disagree with itself and hide which value dey active. Check wetin the parser finally set, and monitor one run wey no change anything:

apt-config dump | grep -i 'Unattended-Upgrade::Remove'
sudo unattended-upgrade --dry-run --debug
sudo tail -n 40 /var/log/unattended-upgrades/unattended-upgrades.log

The log na the proof. E record every run, so upgrade wey fail because space no dey go show there long before anybody notice say the machine dey behind on patches. The rest of that configuration dey covered for automatic security updates for Ubuntu.

Before the next kernel land, get one number to check. Na the same pair of commands from the beginning of this guide:

df -h /boot
ls -lh /boot/initrd.img-$(uname -r)

If Avail no plenty pass that file, the next kernel go fail exactly as we describe above. Fix am now instead of waiting until the upgrade. This check deserve one minute together with your other disk health checks for a VPS. E matter pass immediately before a release upgrade, because moving Ubuntu 24.04 to 26.04 dey install fresh kernel, and do-release-upgrade go abort when /boot no get enough space. That upgrade dey available now. Ubuntu hold LTS to LTS upgrades until the 26.04.1 point release, wey ship on 27 August 2026, and Canonical enable upgrades from 24.04 LTS on 29 September 2026. Server users fit run do-release-upgrade anytime, while desktop users dey receive am through Update Manager as progressive rollout. No waiting period remain to depend on, so arrange /boot before you start the upgrade. If 24.04 server still dey report say no new release dey available, the point release no longer explain am. Instead, work through the usual causes of a missing release upgrade.

FAQ

Why Ubuntu dey keep old kernels instead of deleting dem?

Because if one kernel no boot, you no go get another one to select. Keeping the previous version mean say bad update fit recover from GRUB menu instead of provider rescue console. apt therefore dey protect some kernel packages from automatic removal, and e always include the one wey you dey run. Run apt-config dump | grep -i neverautoremove to see the exact patterns wey your release dey protect, because the policy don change between releases.

apt autoremove --purge safe to run for production server?

Yes, as long as you read the dry run first. Run sudo apt autoremove --purge --dry-run, wey no dey write anything, and check the list wey e print. Stop if e contain meta package like linux-generic or linux-image-generic, because removing one of dem go stop future kernel updates. Stop too if e contain the version string wey uname -r print. If neither one appear, the packages wey e wan remove na old kernels and orphaned dependencies.

apt autoremove remove nothing and /boot still full. Wetin I fit do now?

The old kernels almost certainly get manual mark, and autoremove only dey touch packages wey get automatic mark. Run apt-mark showmanual | grep -E '^linux-'. Any versioned kernel wey e list, person install am by hand at some point. Mark am automatic with sudo apt-mark auto linux-image-<version> and run the dry run again, or purge that one version directly with sudo apt purge linux-image-<version>.

I fit delete files from /boot by hand?

Only as deliberate one-off, when /boot full reach the point say apt no fit configure the broken kernel package. Delete one initrd.img-<version> file wey version no be the output of uname -r, then immediately run sudo apt --fix-broken install, sudo apt autoremove --purge and sudo update-grub. If you delete files without those follow-up steps, dpkg go record packages whose files don disappear, and GRUB menu entries go still point to missing files. The machine go fail on the next reboot instead of failing immediately when you make the mistake.

Dis article help you?