Cleaning up orphaned initrd images

I seem to have some old images hanging around despite those kernel versions being removed:

sudo update-grub 
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.4-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-6.4-x86_64.img
Found initrd fallback image: /boot/initramfs-6.4-x86_64-fallback.img
Found linux image: /boot/vmlinuz-6.3-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-6.3-x86_64.img
Found initrd fallback image: /boot/initramfs-6.3-x86_64-fallback.img
Found linux image: /boot/vmlinuz-6.2-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-6.2-x86_64.img
Found initrd fallback image: /boot/initramfs-6.2-x86_64-fallback.img
Found linux image: /boot/vmlinuz-6.1-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-6.1-x86_64.img
Found initrd fallback image: /boot/initramfs-6.1-x86_64-fallback.img
Found linux image: /boot/vmlinuz-5.12-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-5.12-x86_64.img
Found initrd fallback image: /boot/initramfs-5.12-x86_64-fallback.img
Found linux image: /boot/vmlinuz-5.9-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-5.9-x86_64.img
Found initrd fallback image: /boot/initramfs-5.9-x86_64-fallback.img
pamac list -i | grep linux
archlinux-appstream-data           20230526-1                    extra     20.2 MB
archlinux-keyring                  20230704-1                    core      1.7 MB
lib32-util-linux                   2.39.1-1                      multilib  1.2 MB
linux-api-headers                  6.3-1                         core      5.6 MB
linux-firmware                     20230625.ee91452d-2           core      482.4 MB
linux-firmware-whence              20230625.ee91452d-2           core      218.7 kB
linux61                            6.1.38-1                      core      149.9 MB
linux61-headers                    6.1.38-1                      core      152.4 MB
linux63                            6.3.12-1                      core      160.7 MB
linux63-headers                    6.3.12-1                      core      161.7 MB
linux64                            6.4.2-3                       core      138.3 MB
linux64-headers                    6.4.2-3                       core      162.3 MB
util-linux                         2.39.1-1                      core      13.9 MB
util-linux-libs                    2.39.1-1                      core      1.3 MB

This seems to be related to: Old uninstalled kernel versions are still present in mkinitcpio.d

How do I clean up these old kernels? Do I just go into the relevant folders (which I still need to find) and remove any files with the old versions?

So 5.9, 5.12, and 6.2 ?

I thought they were removed when running the normal mkinitcpio (also triggered by hooks)

sudo mkinitcpio -P

Followed by

sudo update-grub

If they are there anyways … then they should be in /boot/ as already shown in the output, ex:

sudo rm /boot/vmlinux-6.2-x86_64
sudo rm /boot/initramfs-6.2-x86_64.img
sudo rm /boot/initramfs-6.1-x86_64-fallback.img
sudo rm /boot/vmlinux-5.12-x86_64
sudo rm /boot/initramfs-5.12-x86_64.img
sudo rm /boot/initramfs-5.12-x86_64-fallback.img
sudo rm /boot/vmlinux-5.9-x86_64
sudo rm /boot/initramfs-5.9-x86_64.img
sudo rm /boot/initramfs-5.9-x86_64-fallback.img

Then run the mkinitcpio and update-grub commands above.

If you want to try and find things in general, such as maybe old module directories, etc … you may try this script that will print a number of locations, possibly showing some other places you need/want to clean:

gcspt.sh
#!/usr/bin/env bash
gcspt=$(find /boot -type f -name '*.cfg' 2>/dev/null | sort);
gscpt=$(find /etc/grub.d -type f ! -name 'README' 2>/dev/null | sort);
initz=$(find /boot -type f -name 'initramfs*' 2>/dev/null | sort); 
imgz=$(find /boot -type f -name 'vmlinuz*' 2>/dev/null | sort); 
modz=$(find /lib/modules -maxdepth 1 -type d 2>/dev/null | sort);
mkinitz=$(find /etc -type f -name 'mkinitcpio*' 2>/dev/null | sort); 
mkinitzd=$(find /etc/mkinitcpio.d -type f 2>/dev/null | sort);
dracutz=$(find /etc -type f -name 'dracut*' 2>/dev/null | sort); 
dracutzd=$(find /etc/dracut.conf.d -type f 2>/dev/null | sort) 
printf '\n...Bite-Sized Boot-Info...\n'; 
printf "\nCurrently Running Kernel:\n$(hostnamectl | tail -n6 | head -n1 | awk '{ print $NF }')\n"; 
printf '\nGrub Configuration Files:\n';
echo "$gcspt" | while read in; do ls -l --time-style=+'%F %R' "$in" | cut --complement -d ' ' -f1,2,3,4,5; done | column -t;
echo "$gscpt" | while read in; do ls -l --time-style=+'%F %R' "$in" | cut --complement -d ' ' -f1,2,3,4,5; done | column -t;
printf '\nInstalled Kernels:\n';
echo "$imgz" | while read in; do ls -l --time-style=+'%F %R' "$in" | cut --complement -d ' ' -f1,2,3,4,5; done | column -t; 
printf '\nInitramfs Images:\n'; 
echo "$initz" | while read in; do ls -l --time-style=+'%F %R' "$in" | cut --complement -d ' ' -f1,2,3,4,5; done | column -t;
printf '\nmkinitcpio:\n';
echo "$mkinitz" | while read in; do ls -l --time-style=+'%F %R' "$in" | cut --complement -d ' ' -f1,2,3,4,5; done | column -t;
echo "$mkinitzd" | while read in; do ls -l --time-style=+'%F %R' "$in" | cut --complement -d ' ' -f1,2,3,4,5; done | column -t;
printf '\ndracut:\n';
echo "$dracutz" | while read in; do ls -l --time-style=+'%F %R' "$in" | cut --complement -d ' ' -f1,2,3,4,5; done | column -t;
echo "$dracutzd" | while read in; do ls -l --time-style=+'%F %R' "$in" | cut --complement -d ' ' -f1,2,3,4,5; done | column -t;
printf '\nModule Directories:\n'; 
for i in $modz; do du --time --time-style=+'%F %R' -sh $i; done | awk '{print $2,$3,$4,$1}' | column -t; 
printf '\nHibernation:\n'; grep -o 'resume=' /etc/default/grub || printf 'No "resume=" option found in /etc/default/grub\n\n'

(if you dont know how to use a script … save as a text file, named gcspt.sh, mark executable with chmod +x gcspt.sh, and run with ./gcspt.sh)

That first command ( sudo mkinitcpio -P ) has done the trick.

I don’t know what results in them not being cleaned up by default when the hooks call it. I would suggest it’s related to things hanging around because I build DKMS modules.

I think the order of processing is wrong. It might also be because there have been times I have run pamac update or pamac install linux<something> before realising there were old kernels I wanted to remove, so I have removed a kernel immediately after updating it, again indicating that the order of processing is wonky.

Thanks for the help. Can you suggest how I should proceed in addressing these edge cases where the hooks fall down?