Linux & Open SourceTechnology

Clean Old Kernels Manually When the Boot Partition Is Full

Admin
Clean Old Kernels Manually When the Boot Partition Is Full

You try to install a kernel update or rebuild the boot files, and Ubuntu answers with an error from update-initramfs saying there is no space left on the device. Your /boot partition is completely full, and the usual automatic cleanup commands either fail or claim there is nothing to remove. When the tidy tools cannot help, a careful manual cleanup is the way out.

Manual cleanup does not mean deleting files at random. It means checking exactly which kernels are installed, which one you are running, and which files belong to versions you no longer need, then removing them in the safest order possible. Done step by step, it is a reliable rescue method even for a very crowded boot partition.

Quick Answer

When update-initramfs says the boot partition is full, first note your running kernel with uname -r, then list the files in /boot and the installed kernel packages. Remove the oldest unused kernel packages with sudo apt purge, and only if package removal is impossible, move the initramfs file of the oldest unused kernel aside to free space so the package tools can run again. Finish with sudo apt autoremove --purge and sudo update-initramfs -u.

Understanding What update-initramfs Does

The initramfs is a small temporary file system that Ubuntu loads at the very start of boot, before the main system is available. It contains the drivers needed to find and unlock your real drive. The file for each kernel lives in /boot and is named like initrd.img-6.8.0-45-generic.

When a kernel or driver changes, update-initramfs rebuilds this file. Rebuilding needs temporary room: the new file is written before the old one is replaced. On a partition that is already 100 percent full, there is no room to write anything, so the tool fails and reports no space left on device. That failure can also block other package operations, because Ubuntu considers the kernel only half-configured until the initramfs is built successfully.

This is why a completely full /boot needs a slightly different approach from a merely crowded one. You often have to free a little space first, by hand, before the proper package tools can finish the real cleanup.

Step 1: Take Stock Before Touching Anything

Open a terminal and gather three pieces of information. Write them down or keep the terminal open where you can see them.

  1. Run uname -r to see the kernel you are running right now. This kernel must not be removed or moved under any circumstances during this session.
  2. Run df -h /boot to confirm how full the partition is and its total size.
  3. Run ls -lh /boot to list every file with its size. Look for repeated version numbers and note the oldest ones.
  4. Run dpkg --list | grep -E "linux-image|linux-headers" to see which kernels the package system knows about.

Compare the two lists. Usually they match: each installed kernel package has matching files in /boot. Sometimes you will find files in /boot with no matching package, leftovers from an interrupted removal. Those orphans are the safest first target because no package depends on them.

Step 2: Try the Proper Package Removal First

Even when update-initramfs is failing, removing a kernel package often still works if there is even a little free space, because removal mostly deletes files rather than writing new ones.

Pick the oldest kernel version that is not your running kernel and not the newest installed version. Remove it with a command like sudo apt purge linux-image-6.5.0-28-generic linux-headers-6.5.0-28-generic, using the exact version you found. If apt complains about broken dependencies, try sudo dpkg --purge linux-image-6.5.0-28-generic for the image package alone.

After each removal, run df -h /boot again. Removing one full kernel typically frees 100 to 300 megabytes, which is often enough breathing room for everything else to start working. Repeat for other old versions until only the running kernel and the newest one remain. If this step solves your space problem, skip ahead to the final cleanup steps and do not touch files directly at all.

Step 3: The Last-Resort Manual File Move

If the partition is so full that even package removal fails because update-initramfs runs as part of it and errors out, you need to free a chunk of space manually first. The trick is to move, not delete, the largest file belonging to the oldest unused kernel.

Which File to Move

The initramfs file is the biggest file for each kernel, often 60 to 150 megabytes or more. Choose the one with the oldest version number that is definitely not your running kernel. For example, if you are running 6.8.0-45 and the oldest leftover is 6.5.0-28, the target is /boot/initrd.img-6.5.0-28-generic.

How to Move It Safely

  1. Make sure your home folder has space: df -h /home should show plenty free.
  2. Move the file with sudo mv /boot/initrd.img-OLDVERSION-generic ~/initrd-backup.img, using your real old version.
  3. Check df -h /boot. You should now have a healthy amount of free space.
  4. Immediately remove that old kernel properly with sudo apt purge or sudo dpkg --purge as in Step 2, so the package records match the files again.

Moving instead of deleting matters. If you picked the wrong file by mistake, you can move it back with the reverse command. Once the old kernel package is purged properly, you can delete the backup file from your home folder. Never move or delete the initramfs, vmlinuz, or any other file belonging to your running kernel or the newest kernel. If you are running low on confidence at this point, the broader advice in our guide on freeing up disk space on Ubuntu safely covers general cleanup habits that help avoid getting here again.

Step 4: Repair and Rebuild

With space freed and old kernel packages removed, put the package system back into a clean state:

  1. Run sudo dpkg --configure -a to finish configuring any half-installed packages.
  2. Run sudo apt install -f to fix any remaining broken dependencies.
  3. Run sudo apt autoremove --purge to sweep out anything else that is no longer needed.
  4. Run sudo update-initramfs -u to rebuild the initramfs for your current kernel. It should now complete without a space error.
  5. Run sudo update-grub so the boot menu lists only the kernels that actually remain.

Restart the computer and confirm it boots normally. Keep the moved backup file until after this successful restart, just in case. Once you have booted cleanly and run sudo apt update and sudo apt upgrade without errors, the rescue is complete and the backup can go.

Checking for Other Space Hogs in /boot

Kernels are the usual culprits, but the ls -lh /boot listing shows sizes clearly, so anything unusually large that is not tied to your two kept kernels deserves a second look.

The official Ubuntu community guide on removing old kernels describes the standard tools and automatic options, and the update-initramfs manual page on Ubuntu Manpages documents every option of the rebuild tool if you want the technical reference.

Tips to Keep /boot Healthy

Check df -h /boot every couple of months if your partition is small, so you notice growth at 80 percent instead of at 100 percent.

Common Mistakes

The most serious mistake is deleting the files of the kernel you are currently running. The system may keep working until you restart, because the running kernel is already loaded in memory, and then fail to boot. Checking uname -r first and protecting that version prevents this completely.

A second mistake is deleting files for several kernels at once without purging their packages. The package database then disagrees with reality, and future kernel operations produce strange half-installed errors. Move one file if you must, purge that package straight away, and keep files and records in step.

A third mistake is forgetting update-grub after the cleanup. The boot menu can keep offering kernels that no longer exist, which is confusing and can cause a failed boot selection. One quick command refreshes the menu to match reality.

Finally, do not treat a full boot partition as a reason to reinstall Ubuntu. In almost every case the system underneath is perfectly healthy. Fifteen careful minutes of cleanup restores it fully.

Conclusion

When update-initramfs reports a full boot partition, stay methodical: identify your running kernel, list what is actually in /boot, remove old kernels through the package tools first, and only move a single old initramfs file by hand if you need space to let those tools work. Finish with the repair commands, a rebuild, and a grub update, then restart to prove everything is healthy. Your boot partition will have room to spare and your updates will run cleanly again.

Frequently Asked Questions

How many kernels should I keep?

Keep two: the one you are running now and the newest installed one as a fallback. That gives you a known-good option if a new kernel ever causes trouble, while using the least space on a small partition.

What does no space left on device mean if my main drive has room?

It refers to the specific partition being written to, which is /boot. That partition has its own size limit, separate from your main drive. Free space elsewhere on the system does not help until space is freed on /boot itself.

Is it safe to move an initrd file out of /boot?

It is safe only for an old kernel you are not running and are about to purge, and only as a temporary step to free space. Never move files for your running or newest kernel, and purge the matching package immediately afterwards.

update-initramfs still fails after cleanup. What next?

Check df -h /boot again to confirm space really is free, then run sudo dpkg --configure -a and sudo apt install -f to repair half-configured packages before retrying sudo update-initramfs -u. A stuck half-configured kernel is the usual remaining cause.

Why did so many old kernels build up?

Usually because kernels were marked as manually installed, automatic removal was disabled, or cleanups were interrupted. Returning to normal updates plus regular autoremove after restarts prevents the build-up from happening again.

Admin

Passionate about the intersection of style and storytelling. I simplify fashion trends and industry news into easy-to-follow advice, helping you stay stylish and informed in the fast-paced world of fashion.

One response to “Clean Old Kernels Manually When the Boot Partition Is Full”

Leave a Reply

Your email address will not be published. Required fields are marked *