0

As installonly_limit 3 in etc/yum/yum.conf and in etc/dnf/dnf.conf didn't seem to have any effect under Mageia even by running dnf autoremove, I tried to run dnf remove $(dnf repoquery --installonly --latest-limit=-2) but it failed by complaining about being unable to remove basesystem. Actually, dnf repoquery --installonly --latest-limit=-2 seems to return all kernels including the latest kernel whatever the value of --latest-limit. What am I missing? I found this command line in this documentation, it works under some other distributions supporting DNF but not under Mageia.

dnf repoquery --installonly gives me:

kernel-desktop-5.15.11-3.mga8-0:1-1.mga8.x86_64
kernel-desktop-5.15.15-1.mga8-0:1-1.mga8.x86_64
kernel-desktop-5.15.4-1.mga8-0:1-1.mga8.x86_64
kernel-desktop-5.15.6-2.mga8-0:1-1.mga8.x86_64

dnf remove --oldinstallonly --setopt installonly_limit=1 tells me that there is no old installonly package to remove.

gouessej
  • 111
  • 6

1 Answers1

0

As I use DNF after having used RPM for a while, solutions based on DNF don't work.

This is my solution using RPM, it keeps only the most recently installed kernel and the kernel currently in use:

#!/bin/bash
# script written by Julien Gouesse, under General Public License version 2
if [ ! -n "$BASH" ]
  then echo "Please run $0 with bash"
       exit 1
fi
if [ "$EUID" -ne 0 ]
  then echo "Please run $0 as root"
       exit 2
fi
kernelType=$(uname -r | cut -f 2 -d "-")
kernelReleaseNumber=$(uname -r | cut -f 1 -d "-")
kernelPatchLevelAndDistro=$(uname -r | cut -f 3 -d "-")
currentlyLoadedKernelPackagePrefix="kernel-$kernelType-$kernelReleaseNumber-$kernelPatchLevelAndDistro"
latestKernelPackagePrefix="kernel-$kernelType-latest-"
mostRecentlyInstalledKernelVirtualPackagePrefix=$(rpm -qa|grep $latestKernelPackagePrefix)
mostRecentlyInstalledKernelPackagePrefix=${mostRecentlyInstalledKernelVirtualPackagePrefix/-latest/}
packagesToDeinstall=""
for i in $(rpm -qa|grep kernel-desktop-)
do
   if [[ "$i" != *"$currentlyLoadedKernelPackagePrefix"* ]] && [[ "$i" != *"$mostRecentlyInstalledKernelVirtualPackagePrefix"* ]] && [[ "$i" != *"$mostRecentlyInstalledKernelPackagePrefix"* ]]
     then
       packagesToDeinstall+=" $i"
   fi
done
if [ "$packagesToDeinstall" == "" ] 
  then
    echo "No kernel to deinstall"
  else
    urpme $packagesToDeinstall
fi

Keep in mind that it's a very specific solution, it doesn't work under other distributions.

gouessej
  • 111
  • 6