In this post, we shall discuss about how to retain current and older Linux packages while updating the Linux OS with the ‘yum’ command. Note that /etc/yum.conf configuration file contains a [main] section. If required then we can add many additional options under the [main] section. Some of the key-value pairs in the [main] section affect how yum operates.
A sample /etc/yum.conf configuration file looks as below:
# cat /etc/yum.conf [main] cachedir=/var/cache/yum/$basearch/$releasever keepcache=0 debuglevel=2 logfile=/var/log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonlypkgs= kernel-2.6.32-279.2.1.el6.x86_64, kernel-2.6.32-100.24.1.el5 installonly_limit=3 ... # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d
Using the “installonlypkgs=space separated list of packages” directive under /etc/yum.conf file, provide a space-separated list of packages which yum can install, but will never update. Refer to the man page of yum.conf for the list of packages which are install-only by default.
# man yum.conf
If we add the installonlypkgs directive to /etc/yum.conf, we need to ensure that we provide the list of Packages that are for install-only, including any of those listed under the installonlypkgs section of man yum.conf.
In particular, kernel packages should always be listed in installonlypkgs (as they are by default), and installonly_limit should always be set to a value greater than 2 so that a backup kernel is always available in case the default one fails to boot.
# vi /etc/yum.conf installonlypkgs=space separated list of packages
Also please check the installonly_limit directive mentioned as below.
This option sets how many packages listed in the installonlypkgs directive can be installed at the same time. We can mark the value with an integer representing the maximum number of versions that can be installed simultaneously for any single package listed in installonlypkgs.
The defaults for the installonlypkgs directive include several different kernel packages, so be aware that changing the value of installonly_limit also affects the maximum number of installed versions of any single kernel package. The default value listed in /etc/yum.conf is installonly_limit=3, and it is not recommended to decrease this value, particularly below 2.
installonly_limit Number of packages listed in installonlypkgs to keep installed at the same time. Setting to 0 disables this feature.
# vi /etc/yum.conf installonly_limit=value
We can disable the functionality altogether by setting installonly_limit to 0:
# vi /etc/yum.conf installonly_limit=0
Using yumdb Command
Alternatively using yumdb command we can set a certain package to be kept from being removed on updates. To use the yumdb command we need to install “yum-utils” package:
# yum install yum-utils
Example of yumdb command:
# yumdb set installonly keep kernel-2.6.32-279.2.1.el6.x86_64
If you want to revert the previous change, you can use this command:
# yumdb del installonly kernel-2.6.32-279.2.1.el6.x86_64