Sie sind auf Seite 1von 4

Generated by Foxit PDF Creator © Foxit Software

http://www.foxitsoftware.com For evaluation only.

INSTALL AND BUILDING PACKAGES

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, deb. There are
several dozen RPM-based Linux distributions, including CentOS, Fedora Core, Red Hat
Enterprise Linux, and SUSE, Debian, Ubuntu.

First, we'll use the rpm (dpkg) 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 (apt-get) 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 Fedora repository by saving
the zsh-4.2.6-1.i386.rpm file to disk (use wget on your VM), then
using rpm to install it.

rpm -ivh zsh-4.2.6-1.i386.rpm

2. Install emacs, an alternative to vim, from the Fedora 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


Generated by Foxit PDF Creator © Foxit Software
http://www.foxitsoftware.com For evaluation only.

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

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
• Updating and Installing Software with yum
• Update all installed packages.
yum update
• 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
• 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
• Testing Packages with rpm

1. Verify the zsh 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.
Generated by Foxit PDF Creator © Foxit Software
http://www.foxitsoftware.com For evaluation only.

cd /
rpm2cpio /home/your_username/zsh*rpm | cpio -vi ./bin/zsh
ls -l /bin/zsh
rpm -V zsh
• 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? Record the answers in your lab.txt file.

ls -l RPMS/* SRPMS/*
Generated by Foxit PDF Creator © Foxit Software
http://www.foxitsoftware.com For evaluation only.

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. You may need to resolve dependencies with yum. This need
may be surprising, as you already resolved dependencies while building nmap.
However, those dependencies were the ones required to compile the software and
did not include the libraries needed by the software at runtime.

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

Das könnte Ihnen auch gefallen