Configuring yum to keep more than three kernels

When you run ‘yum update’ on your Fedora system, the default yum configuration will keep the last 3 kernels. This allows you to fail back to a previous working kernel if you encounter an error or a bug. The number of kernels to keep is controlled by the installonly_limit option, which is thoroughly described in the yum.conf(8) manual page:

installonly_limit Number of packages listed in installonlypkgs to keep installed at the same time. Setting to 0 disables this feature. Default is ‘0’. Note that this functionality used to be in the “installonlyn” plugin, where this option was altered via. tokeep. Note that as of version 3.2.24, yum will now look in the yumdb for a installonly attribute on installed packages. If that attribute is “keep”, then they will never be removed.

If you need to keep more than 3 kernels, you can increase the value of installonly_limit in /etc/yum.conf.

Purging the yum header and package cache

Most of the Linux distributions that utilize the yum package manager cache headers and packages by default. These files are cached in the directory identified by the cachedir option, which defaults to /var/cache/yum on all of the hosts I checked. On my Fedora 16 desktop this directory has grown to 167MB in size:

$ du -sh /var/cache/yum
167M /var/cache/yum

You can clean out the cached directory with the yum “clean” option:

$ yum clean all

If disk space is an issue on your systems, you can also set the “keepcache” option to 0. This will remove cached files after they are installed, as noted in yum.conf(8)the manual page:

keepcache Either `1' or `0'. Determines whether or not yum keeps
          the cache of headers and packages after successful installation.
          Default is '1' (keep files)

This is a useful option for hosts that have limited disk space. Nice!

Adding a new CentOS or Fedora CD or DVD image to a kickstart server

I’ve talked in the past about Yum repositories, and how you can create them. If you are using kickstart and want to import the contents of a CD for use by the installer, there are numerous ways you can tackle this issue. One of the easiest methods is to loopback mount the CDs or DVDs and copy them to your kickstart directory hierarchy:

$ mount -o loop CentOS-6.0-x86_64-bin-DVD1.iso /cd1

$ mount -o loop CentOS-6.0-x86_64-bin-DVD2.iso /cd2

$ cd /cd1 && cp -rp repodata /kickstart/centos/6/x86_64/os &

$ cd /cd1 && cp -rp images /kickstart/centos/6/x86_64/os &

$ cd /cd1 && cp -rp Packages /kickstart/centos/6/x86_64/os &

$ cd /cd2 && cp -rp Packages /kickstart/centos/6/x86_64/os &

You will need to make sure to copy the Packages, repodata and images directories. After the copy completes you can point your kickstart.cfg file at the top level directory of the release you want to install:

url –url=http://kickstart.prefetch.net/kickstart/centos/6.0/x86_64/os/

Posting here so I have this procedure for future reference.

Finding orphaned RPMs on Linux hosts

If you use an RPM-based Linux distribution, you may have run into one or more cases were your system contains orphaned packages. An orphaned package is a package that doesn’t have any packages that depend on it, and in a number of cases the package is no longer required for the system to function correctly. To view the list of orphaned packages on your Linux host, you can use the incredibly useful rpmorphan tool. To install it, you can fire up yum:

$ yum install rpmorphan

Once installed, you can run it to view the list of orphaned packages on your system:

$ rpmorphan
libdwarf
libertas-usb8388-firmware
libsane-hpaio

To get additional information on what rpmorphan is doing, you can run it with the “-verbose” option. This is a super useful utility, and one that will make its way into my SA utility belt!

Viewing the scripts that run when you install a Linux RPM

RPM packages contain the ability to run scripts after a package is added or removed. These scripts can perform actions like adding or removing users, cleaning up temporary files, or checking to make sure a software component that is contained within a package isn’t running. To view the contents of the scripts that will be run, you can use the rpm “–scripts” option:

$ rpm -q –scripts -p VirtualBox-3.1-3.1.4_57640_fedora11-1.x86_64.rpm |more

preinstall scriptlet (using /bin/sh):
# defaults
[ -r /etc/default/virtualbox ] && . /etc/default/virtualbox

# check for active VMs
if pidof VBoxSVC > /dev/null 2>&1; then
  echo "A copy of VirtualBox is currently running.  Please close it and try again. Please not
e"
  echo "that it can take up to ten seconds for VirtualBox (in particular the VBoxSVC daemon) 
to"
  echo "finish running."
  exit 1
fi

RPM provides four types of pre and post installation scripts that can be run:

preinstall scriptlet — this will run before a package is installed
postinstall scriptlet — this will run after a package is installed
preuninstall scriptlet — this will run before a package is uninstalled
postuninstall scriptlet — this will run after a package is uninstalled

There are some awesome RPM options buried in the documentation, and you will definitely want to read through the various RPM resources prior to creating RPMs.

Configuring yum to use an HTTP or FTP proxy

I have been experimenting with squid at home, and recently configured yum to use the squid proxy server I set up. There are two ways you can get yum to use an HTTP or FTP proxy. First, you can make yum use a proxy for a single session by setting the http_proxy and ftp_proxy environment variables:

$ export http_proxy=http://proxy:3128

$ export ftp_proxy=http://proxy:3128

$ yum update

If you want to make the proxy settings permanent, you can add a proxy directive to /etc/yum.conf:

$ grep proxy /etc/yum.conf
proxy=http://proxy:3128

If your proxy requires you to authenticate, you can add the credentials to the configuration file as well.