Why are old initrd files of uninstalled kernels filling up /boot partition?
You should check partially removed kernels with
dpkg -l linux-image-\* | grep ^rc
and remove them with for example sudo apt-get purge linux-image-4.4.0-101-generic
.
Purging will remove initramfs generation rules from /var/lib/initramfs-tools/
.
If it does not help, you can remove them manually from initramfs list:
sudo rm /var/lib/initramfs-tools/3.13.0-39-generic
sudo rm /var/lib/initramfs-tools/4.4.0-101-generic
sudo rm /var/lib/initramfs-tools/4.4.0-103-generic
sudo rm /var/lib/initramfs-tools/4.4.0-38-generic
sudo rm /var/lib/initramfs-tools/4.4.0-45-generic
sudo rm /var/lib/initramfs-tools/4.4.0-59-generic
sudo rm /var/lib/initramfs-tools/4.4.0-77-generic
sudo rm /var/lib/initramfs-tools/4.4.0-78-generic
sudo rm /var/lib/initramfs-tools/4.4.0-81-generic
Usually I run purge-old-kernels
followed by sudo apt-get autoremove
to have only 2 recent kernels.
You can reinstall installed kernels with their initramfses:
sudo apt-get install --reinstall \
$(dpkg -l linux-image-\* | grep ^ii | awk '{print $2}')
If you have already used dpkg
to purge the kernels / headers and if you have already checked dpkg -l
and still don't see the kernels / headers installed there, but you still see references to these old kernels in /boot
in the form of initrd-img
files, then the proper way to purge these references and files is with the update-initramfs
command.
For example, if you only have 4.4.0-109
installed, but you still see the following in /boot
:
-rw-r--r-- 1 root root 10M Jan 30 10:02 initrd.img-4.4.0-103-generic
-rw-r--r-- 1 root root 38M Jan 30 10:02 initrd.img-4.4.0-104-generic
-rw-r--r-- 1 root root 38M Jan 30 10:02 initrd.img-4.4.0-109-generic
You can safely remove 4.4.0-104
and 4.4.0-103
from /boot
with the following commands:
$ sudo update-initramfs -d -k 4.4.0-103-generic
$ sudo update-initramfs -d -k 4.4.0-104-generic
$ sudo update-initramfs -c -k all
The first two commands delete the references to those kernels in initramfs
generation rules as well as the files in /boot
. The last command tells initramfs to regenerate the initrd.img
files based on the updated rules.
Theoretically you could also use
$ sudo update-initramfs -d -k 4.4.0-{103,104}-generic
to delete multiple kernels at once, but for some reason this didn't work for me.