Not easy, if it was removed from the repo. I modified my mhwd-kernel
script, but here is a standalone script:
#!/bin/bash
kver_list=( $(pacman -Ssq "^linux[0-9][0-9]?([0-9])($|-rt$)" | \
sed -r "s/linux([4,5])([0-9]+)(|-rt)/\\1.\\2\\3/g") )
kver_inst=( $(pacman -Qqs "^linux[0-9][0-9]?([0-9])($|-rt$)" | \
sed -r "s/linux([4,5])([0-9]+)(|-rt)/\\1.\\2\\3/g") )
# Remove installed kernels from the list
for target in ${kver_inst[@]}; do
for i in "${!kver_list[@]}"; do
if [[ ${kver_list[i]} == $target ]]; then
unset 'kver_list[i]'
fi
done
done
# List kernels versions, which are not installed
echo -e "The following kernels are \033[1mNOT INSTALLED\033[0m in your system:"
echo
for x in ${kver_list[@]}; do
echo " * linux${x/./}"
done
echo
# List kernels versions, which are installed
echo -e "The following kernels are \033[1mINSTALLED\033[0m in your system:"
echo
for x in ${kver_inst[@]}; do
echo " * linux${x/./}"
done
echo
# List possible garbage files
echo "Search for garbage files..."
garbage=()
# Search for possible garbage files
garbage+=(
$(find /boot -maxdepth 1 -type f \
\( \
-name "*vmlinuz*$(uname -m)" -o \
-name "*initramfs*$(uname -m).img" -o \
-name "*initramfs*$(uname -m)-fallback.img" -o \
-name "linux*-$(uname -m).kver" \
\) \
| grep -v "$(echo -n ${kver_inst[@]} | sed -e 's, ,\\|,g')" \
| grep -v "$(echo -n ${kver_inst[@]/.} | sed -e 's, ,\\|,g')")
)
garbage+=(
$(find /etc/mkinitcpio.d -maxdepth 1 -type f \
\( \
-name "linux*.preset" -o \
-name "linux*.preset.pacsave" \
\) \
| grep -v "$(echo -n ${kver_inst[@]} | sed -e 's, ,\\|,g')" \
| grep -v "$(echo -n ${kver_inst[@]/.} | sed -e 's, ,\\|,g')")
)
# List of possible garbage files
echo
for x in ${garbage[@]}; do echo " * ${x}"; done
echo
# Ask to remove garbage files and for safeness,
# run mkinitcpio and grub-mkconfig
if [[ -n $garbage ]]; then
echo "If the files don't have a known version number, then they are most likely garbage."
echo "Same goes for not installed kernel versions."
echo
read -p "Would you like to delete these files? [ENTER/CTRL+C]"
sudo rm -fv ${garbage[@]}
read -p "Would you like to recreate the initcpio? [ENTER/CTRL+C]"
sudo mkinitcpio -P
read -p "Would you like to recreate the grub config? [ENTER/CTRL+C]"
sudo grub-mkconfig -o /boot/grub/grub.cfg
else
echo "No garbage found."
fi
Save it into a text file and run it in chroot or on the local installation:
bash script
like this:
cd /tmp
nano script
Copy the text and insert it with CTRL+SHIFT+V and save and exit it with CTRL+S and CTRL+X,
Then run it.
It looks like this then:
$ bash script
The following kernels are NOT INSTALLED in your system:
* linux419
* linux517
* linux518
* linux54
* linux515-rt
* linux518-rt
The following kernels are INSTALLED in your system:
* linux510
* linux515
Search for garbage files...
No garbage found.