Lab #5: RPM Lab
Date: February 6, 2008
Due Date: February 8, 2008
Points: 10

In this lab, we'll learn how to use Red Hat's packaging system. Both the format and the primary command used to install and query packages are called rpm. There are several dozen RPM-based Linux distributions, including CentOS, Fedora Core, Red Hat Enterprise Linux, and SUSE.

First, we'll use the rpm command to install packages manually, then we'll look at the higher level RPM commands. While Red Hat Enterprise Linux uses the up2date command to access the commercial repositories on the Red Hat Network, CentOS uses the yum command. These commands will install packages and all of their dependencies from the network.

  1. Installing Software with RPM
    1. Install zsh, an alternative to bash, from the CentOS repository by saving the zsh-4.2.6-1.i386.rpm file to disk, then using rpm to install it.
      rpm -ivh zsh-4.2.6-1.i386.rpm
      
    2. Install emacs, an alternative to vim, from the CentOS repository using the same technique you applied above. This install will fail. What went wrong?
  2. Querying the RPM database
    1. List information about the package installed above.
      rpm -qi zsh
      
    2. List the files in the package installed above.
      rpm -ql zsh
      
    3. How many packages are installed?
      rpm -qa | wc -l
      
  3. Getting Information with yum
    1. List available packages using yum.
      yum list all | less
      
    2. List information about your zsh package.
      yum info zsh
      
    3. Since yum has complete databases of information about packages that are in its repositories, it can also provide information about packages that have not been installed, like emacs.
      yum info emacs
      
    4. yum can also determine what files a package needs to work and what packages provide those files.
      yum deplist emacs | less
      
      yum can search for packages containing a specified string, so we can identify all packages that contain emacs in their name or description.
      yum search emacs | less
      
  4. Updating and Installing Software with yum
    1. Update all installed packages.
      yum update
      
    2. While up2date stores sources in /etc/sysconfig/rhn/sources, yum uses /etc/yum.conf and the repository files in /etc/yum.repos.d:
      less /etc/yum.conf
      for f in /etc/yum.repos.d/*
      do
          less $f
      done
      
    3. Install a package using yum. Which packages does yum automatically find and install to satisfy this package's dependencies? Include the dependencies in your lab.txt file. Note that if you want to avoid the confirmation prompt, you can use the -y option.
      yum install ruby
      
  5. Testing Packages with rpm
    1. Verify the telnet package. The rpm -V command should return nothing, as the package should be intact. Delete a file. Verify the package again. Now you should receive a message indicating that the file you removed is missing.
      rpm -V zsh
      rm -f /bin/zsh
      rpm -V zsh
      
    2. Fix the broken zsh package. We can't re-install the package directly with yum, as it's already installed and forcing re-installing will cause the pre- and post-install scripts to be run again. For some packages, that may not cause problems, but for others, such as a running web server, it might. The simplest solution is to download the RPM and extract the file we want from it; fortunately, we already downloaded zsh. To extract the file we want, we construct a pipeline that converts the RPM to a CPIO archive with rpm2cpio then extracts the man page we need with cpio. Note that rpm might complain about the timestamps of the restored file when you do the check to verify that the file has been restored.
      cd /
      rpm2cpio /home/student/zsh*rpm | cpio -vi ./bin/zsh
      ls -l /bin/zsh
      rpm -V zsh
      
  6. Building Software with RPM
    1. Install the RPM build tools that you'll need to create an RPM.
      yum install rpm-build
      
    2. Download the source RPM for nmap-4.20 from DAG RPMs and install it (use a search engine to find the site if you don't know the URL.) Note that installing a source RPM is not like installing a binary RPM. If you get some errors about nonexistent file owners being replaced by root, that's not a problem. It just means that a user on the system where the source RPM was created doesn't exist on your system.
      rpm -ivh nmap-*.src.rpm
      
    3. RPM always installs the source code and the SPEC file that describes how to build the source code under /usr/src/redhat, where you can later build binary RPMs from it using rpmbuild.
      cd /usr/src/redhat
      # You should find a SPEC file and a tarball containing the source code.
      ls -lR | less
      # Read the SPEC file and find what packages nmap depends upon.
      # List the dependencies in your lab.txt file.
      less SPECS/nmap.spec
      
    4. Build the nmap source RPM. If you encounter dependency problems, use yum to resolve them. If you encounter a dependency you cannot resolve, remove it from the SPEC file and try to build the RPM without it.
      # Use script to record your build process
      script
      # Build source + binary RPMs, using yum to install any dependencies.
      rpmbuild -v -ba SPECS/nmap.spec
      # Exit the script command and convert its output to UNIX line-endings
      exit
      dos2unix typescript
      # Submit the typescript file generated by script with your lab.
      
    5. View the new packages. How many binary RPMs were built from the one source RPM? How many source RPMs?
      ls -l RPMS/* SRPMS/*
      
    6. Using the build output saved above, answer the following questions. What processor was the build optimized for (the options for the C compiler gcc should be helpful in answering this question)? What dependencies to each of the binary RPMs have? Include the answers to your questions in your lab.txt file.
      less typescript
      
    7. Install the new RPMs.
      rpm -Uvh RPMS/i386/nmap-4.20*
      
    8. Verify that nmap is installed and check what files it installed.
      rpm -q nmap
      rpm -ql nmap
      
  7. Using non-CentOS Software Repositories
    1. Add Dag's RPMs to your repository list, so you can use yum to install packages from there. Follow the instructions in the Dag FAQ to do this.
    2. Install p0f, then use queries to figure out what the package does. Include the information you added to the sources file in your lab.txt file.
      yum install p0f
      rpm -qi p0f
      rpm -ql p0f
      
 

©2008 James Walden, Ph.D.