Linux Training : k. rpm

RPM - package management

RPM (Redhat Package Manager) is the core mechanism for maintaining the functional coherency of binaries on a RHEL system. This requires the knowledge of all required library versions and helper application versions. Without a package management tool like rpm, the sheer scope of the task is to large for effective administration. The Fedora RPM tutorial is an excellent resource for what all can be done with rpm and how to do it.

Unknown macro: {bgcolor}

There is a serious warning about don't be root while building rpm's that needs to be read.

  • yum - updates and dependencies.

  • yum (LIN:Yellowdog Updater Modified) is how RHEL now handles updates. Yum uses repositories for the source of rpm files and then uses rpm to understand each update file's specific needs. It will automatically get the required dependencies for any package being updated. man yum is your friend.
    • yum basic commands
      • yum search foo find all packages from the repo list that have foo in the name in the info for the packages.
      • yum info foo* provides a list of data about the package foo such as installed status, name, repo, license, description.
      • yum check-update checks system for any needed updates.
      • yum install foo installs the package foo for all appropriate architectures.
      • yum install foo.x86_64 install foo for the x86_64 architecture.
      • yum remove foo removes package foo and all other packages that depend on it.
      • yum reinstall foo downloads and reinstall package foo overwriting everything previously installed except modified config files.
  • RPM build environment

    The best ways to build packages with rpmbuild is to set up your own build tree and edit ~/.rpmmacros to use it.
    • mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
    • echo "%_topdir %(echo $HOME)/rpmbuild" > ~/.rpmmacros
    • Now new rpm source code goes into ~/rpmbuild/SOURCES into a <new directory> named after the package name and the spec file goes into ~/rpmbuild/SPECS
    • To build new scripts into rpms, create a tar.gz file of the SOURCES/<new directory>, edit the spec file and run rpmbuild -ba <package name>.spec

    • You may need to install some additional tools in order to build rpm's. Specifically you will need

      rpm-build
      rpmlint
      rpmdevtools

      Use yum to install the rpm-build, rpmlint and rpmdevtools packages
  • RPM patches

    RPM uses the concept of "pristine code plus patches". So the original code is unchanged. Anything that needed to be changed to make the code run or install with the RPM or RedHat environment is handled by external patches. The patches are applied from the spec file in the order presented. Patches are applied before the build (obviously). This illustrated with spec file for the booty source rpm
    Summary: simple python bootloader config lib
    Name: booty
    Version: 0.80.6
    Release: 5
    License: LGPL
    Group: System Environment/Libraries
    BuildRoot: %{_tmppath}/%{name}-root
    Requires: rhpl
    BuildRequires: python-devel
    BuildArch: noarch
    Source0: %{name}-%{version}.tar.bz2
    Patch0: booty-0.80.4-multipath.patch
    Patch1: booty-0.80.4-bz464791-serial-init.patch
    Patch2: booty-0.80.6-no-ia64-com-on-vmm.patch
    
    %description
    Small python library for use with bootloader configuration by anaconda
    and up2date.
    
    
    %prep
    %setup -q
    %patch0 -p1
    %patch1 -p1
    %patch2 -p1
    
    %build
    make
    
    %install
    rm -rf $RPM_BUILD_ROOT
    make DESTDIR=$RPM_BUILD_ROOT install
    
    %clean
    rm -rf $RPM_BUILD_ROOT
    
    %files
    %defattr(-,root,root)
    %doc README TODO
    /usr/lib/booty
    
    
    %changelog
    * Tue Oct 07 2008 Peter Jones <pjones@redhat.com> - 0.80.6-5
    - Fix dropped changelog entries.
      Related: rhbz#465454
    
    <snip other changelog entries>
    
    The patch files are listed before they are applied. The -p1 is the patch level used by the patch command. The patches are created using the diff -u command with the unified patch flag. The *.patch files are placed in the SOURCES directory with the pristine tar.bz2 source.

See LIN:here at answer #8 for a good example of how to package bash scripts into an rpm.

Unknown macro: {bgcolor}

NOTE: your SOURCE directory is not the same as the example script.