13

On several Ubuntu machines I am constantly facing the problem of a full boot partition although I always do remove all old kernels. The problem seems to occur, as many initrd files are on the boot partition even though the related kernels are not actually installed. To give in example:

root@Jacobi:/boot# ls -lah
insgesamt 202M
drwxr-xr-x  3 root root 3,0K Jan 30 10:03 .
drwxr-xr-x 25 root root 4,0K Jan 30 10:03 ..
-rw-r--r--  1 root root 1,2M Dez 11 15:36 abi-4.4.0-104-generic
-rw-r--r--  1 root root 1,2M Jan  9 22:28 abi-4.4.0-109-generic
-rw-r--r--  1 root root 1,2M Jan 19 14:06 abi-4.4.0-112-generic
-rw-r--r--  1 root root 187K Dez 11 15:36 config-4.4.0-104-generic
-rw-r--r--  1 root root 187K Jan  9 22:28 config-4.4.0-109-generic
-rw-r--r--  1 root root 187K Jan 19 14:06 config-4.4.0-112-generic
drwxr-xr-x  5 root root 1,0K Jan 30 10:03 grub
-rw-r--r--  1 root root  10M Jan 30 10:03 initrd.img-3.13.0-39-generic
-rw-r--r--  1 root root  10M Jan 30 10:02 initrd.img-4.4.0-101-generic
-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
-rw-r--r--  1 root root  10M Jan 30 10:03 initrd.img-4.4.0-38-generic
-rw-r--r--  1 root root  10M Jan 30 10:03 initrd.img-4.4.0-45-generic
-rw-r--r--  1 root root  10M Jan 30 10:02 initrd.img-4.4.0-59-generic
-rw-r--r--  1 root root  10M Jan 30 10:02 initrd.img-4.4.0-77-generic
-rw-r--r--  1 root root  10M Jan 30 10:02 initrd.img-4.4.0-78-generic
-rw-r--r--  1 root root  10M Jan 30 10:02 initrd.img-4.4.0-81-generic
-rw-r--r--  1 root root 179K Jan 28  2016 memtest86+.bin
-rw-r--r--  1 root root 181K Jan 28  2016 memtest86+.elf
-rw-r--r--  1 root root 181K Jan 28  2016 memtest86+_multiboot.bin
-rw-------  1 root root 3,8M Dez 11 15:36 System.map-4.4.0-104-generic
-rw-------  1 root root 3,8M Jan  9 22:28 System.map-4.4.0-109-generic
-rw-------  1 root root 3,8M Jan 19 14:06 System.map-4.4.0-112-generic
-rw-------  1 root root 6,8M Dez 11 15:36 vmlinuz-4.4.0-104-generic
-rw-------  1 root root 6,8M Jan  9 22:28 vmlinuz-4.4.0-109-generic
-rw-------  1 root root 6,8M Jan 19 14:06 vmlinuz-4.4.0-112-generic

But only linux-image-4.4.0-104-generic and linux-image-4.4.0-109-generic are installed:

root@Jacobi:/boot# dpkg -l linux-image-\* | grep ^ii
ii  linux-image-4.4.0-104-generic       4.4.0-104.127 amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-109-generic       4.4.0-109.132 amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-extra-4.4.0-104-generic 4.4.0-104.127 amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-extra-4.4.0-109-generic 4.4.0-109.132 amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP

If I delete the unnecessary initrd files manually they will be generated again as soon as I try to do an upgrade.

What could be the cause of this issue and how can I get rid of those files permanently?

  • 1
    How did you remove the packages corresponding to these versions? – muru Jan 30 '18 at 9:40
  • 1
    @muru I can't remember having it done in any other way, than to purge them with apt-get autoremove. – user5950 Jan 30 '18 at 10:03
13

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}')
| improve this answer | |
  • 1
    This seems to work pretty well. To sum up: some how there were many only partially removed kernels. I spotted and removed them as described above. Then I had to remove the unnecessary initrd files form boot manually once again to free some space there, et voilà problem solved! Thanks! – user5950 Jan 30 '18 at 10:17
  • As I've read, it is bad form to use rm for anything releated to initrd or kernels or headers. There are some commands available that will handle the removal of partially removed kernels/headers/initrd.img files for you. See update-initramfs. See my answer below for more details. – Daniel Sep 5 '19 at 5:26
3

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.

| improve this answer | |
  • +1 - This is the correct method (and answer) for orphaned initrd's. – bshea Feb 25 at 15:35
  • Thank you. Removed excess initrd.img files. Hopefully won't come back – null Apr 8 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.