7

Looks like I have a unnecessary initrd.img in my /boot directory:

$ ls -1s /boot
total 82835
 1439 abi-4.11.0-10-generic
  204 config-4.11.0-10-generic
    1 extlinux
    1 grub
48186 initrd.img-4.11.0-10-generic
10626 initrd.img-4.8.0-34-generic
10626 initrd.img-4.8.0-39-generic
   12 lost+found
  180 memtest86+.bin
  182 memtest86+.elf
  182 memtest86+_multiboot.bin
 3695 System.map-4.11.0-10-generic
 7501 vmlinuz-4.11.0-10-generic

These are initrd.img-4.8.0-34-generic and initrd.img-4.8.0-39-generic because I cannot find any traces of them

$ sudo update-grub2
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.11.0-10-generic
Found initrd image: /boot/initrd.img-4.11.0-10-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done

$ dpkg -l *4.8.0*
dpkg-query: no packages found matching *4.8.0*

$ dpkg -l linux-*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                        Version            Architecture       Description
+++-===========================-==================-==================-===========================================================
ii  linux-base                  4.5ubuntu1         all                Linux image base package
un  linux-doc-4.11.0            <none>             <none>             (no description available)
ii  linux-firmware              1.167              all                Firmware for Linux kernel drivers
ii  linux-generic               4.11.0.10.10       amd64              Complete Generic Linux kernel and headers
un  linux-headers               <none>             <none>             (no description available)
un  linux-headers-3.0           <none>             <none>             (no description available)
ii  linux-headers-4.11.0-10     4.11.0-10.15       all                Header files related to Linux kernel version 4.11.0
ii  linux-headers-4.11.0-10-gen 4.11.0-10.15       amd64              Linux kernel headers for version 4.11.0 on 64 bit x86 SMP
ii  linux-headers-generic       4.11.0.10.10       amd64              Generic Linux kernel headers
un  linux-image                 <none>             <none>             (no description available)
ii  linux-image-4.11.0-10-gener 4.11.0-10.15       amd64              Linux kernel image for version 4.11.0 on 64 bit x86 SMP
ii  linux-image-extra-4.11.0-10 4.11.0-10.15       amd64              Linux kernel extra modules for version 4.11.0 on 64 bit x86
ii  linux-image-generic         4.11.0.10.10       amd64              Generic Linux kernel image
un  linux-initramfs-tool        <none>             <none>             (no description available)
un  linux-kernel-headers        <none>             <none>             (no description available)
un  linux-kernel-log-daemon     <none>             <none>             (no description available)
ii  linux-libc-dev:amd64        4.11.0-10.15       amd64              Linux Kernel Headers for development
ii  linux-libc-dev:i386         4.11.0-10.15       i386               Linux Kernel Headers for development
un  linux-restricted-common     <none>             <none>             (no description available)
ii  linux-sound-base            1.0.25+dfsg-0ubunt all                base package for ALSA and OSS sound systems
un  linux-source-4.11.0         <none>             <none>             (no description available)
un  linux-tools                 <none>             <none>             (no description available)

Are these both really useless? If they are useless, what is the correct way to remove them (I read, that rm strictly unrecommended for /boot folder)?

EDIT1: sudo apt autoremove cannot help either.

Ravexina
  • 55,668
  • 25
  • 164
  • 183
Loom
  • 576

2 Answers2

18

"initrd" images will be created each time a package triggers update-initramfs, so it's unlikely that you can find a corresponding package to them.

Use:

dpkg -S /boot/initrd.img*

to see the image has been placed by which package, you should get:

dpkg-query: no path found matching pattern /boot/initrd.img-4...

which means "I can't find any related package to this file", just as I said.


So here is my suggestion,

Remove all "initrd" images:

sudo rm /boot/initrd.img*

Generate new "intird" images for all of your currently installed kernels:

sudo update-initramfs -c -k all

You're done.

Ravexina
  • 55,668
  • 25
  • 164
  • 183
  • I removed all initrd images an generated the one for the current kernel, but dpkg -S still says no path found .. for the newly installed image. – sinclair May 10 '18 at 02:13
  • Sadly, this doesn't work (I am on Ubuntu 14.04 running kernel 3.13.0-149-generic). Each time I run the last command, the update-initramfs generates the unwanted initrd.img file again. – Sonny May 29 '18 at 20:40
  • 4
    The thing that did work is from the link https://help.ubuntu.com/community/RemoveOldKernels and does this: $ sudo update-initramfs -d -k 4.8.0-34-generic. Then, run update-initramfs -c -k all. It works then. – Sonny May 29 '18 at 20:49
  • @sinclair This answer has explained that. It says that dpkg won't know the initrd images because they are not in the downloaded package. The initrd images are generated locally after installing the package. – Franklin Yu Oct 02 '18 at 18:57
  • See https://askubuntu.com/a/761305/132098 for learning which kernels are considered for update-initramfs – Abdull Feb 09 '22 at 12:39
7

In your case, I think it is ok to remove the initrd.img manually since you clearly do not have a linux-image-4.8.0-34-generic.

For anyone else who comes across this thread and needs to get rid of an "extra" initrd.img, you might have an "extra" linux-image installed which is what update-initramfs is using to generate this "unwanted" initrd.img

So before running sudo rm /boot/initrd.img*, consider running:

sudo apt-get remove linux-image-4.8.0-34-generic

Now run:

sudo update-initramfs -c -k all

I know you already solved your problem, but I thought another person might need quick instructions and might not understand the uniqueness of your problem.

Unless you are VERY sure of what you are doing, do not manually remove system files.

You might need to run sudo update-grub manually afterwards.