Bookmark this page

Guided Exercise: Explain and Investigate RPM Software Packages

In this exercise, you gather information about a package from a third party, extract files from it for inspection, and then install it on a server.

Outcomes

  • Install on a server a package that is not from the software repositories.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command prepares your environment and ensures that all required resources are available.

[student@workstation ~]$ lab start software-rpm

Instructions

  1. Use the ssh command to log in to the servera machine as the student user.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$
  2. View package information and list files in the rhcsa-script-1.0.0-1.noarch.rpm package. Also view the script that runs when you install or uninstall the package.

    1. View information for the rhcsa-script-1.0.0-1.noarch.rpm package.

      [student@servera ~]$ rpm -q -p rhcsa-script-1.0.0-1.noarch.rpm -i
      Name        : rhcsa-script
      Version     : 1.0.0
      Release     : 1
      Architecture: noarch
      Install Date: (not installed)
      Group       : System
      Size        : 593
      License     : GPL
      Signature   : (none)
      Source RPM  : rhcsa-script-1.0.0-1.src.rpm
      Build Date  : Wed 23 Mar 2022 08:24:21 AM EDT
      Build Host  : localhost
      Packager    : Bernardo Gargallo
      URL         : http://example.com
      Summary     : RHCSA Practice Script
      Description :
      A RHCSA practice script.
      The package changes the motd.

      Note

      The preceding package modifies the MOTD, or "Message of the Day". A system displays the MOTD to users as they log in to systems.

    2. List files in the rhcsa-script-1.0.0-1.noarch.rpm package.

      [student@servera ~]$ rpm -q -p rhcsa-script-1.0.0-1.noarch.rpm -l
      /opt/rhcsa-script/mymotd
    3. View the script that runs when you install or uninstall the rhcsa-script-1.0.0-1.noarch.rpm package.

      [student@servera ~]$ rpm -q -p rhcsa-script-1.0.0-1.noarch.rpm --scripts
      preinstall scriptlet (using /bin/sh):
      if [ "$1" == "2" ]; then
         if [ -e /etc/motd.orig ]; then
           mv -f /etc/motd.orig /etc/motd
         fi
      fi
      postinstall scriptlet (using /bin/sh):
      ...output omitted...
  3. Extract the contents of the rhcsa-script-1.0.0-1.noarch.rpm package to the /home/student directory.

    1. Use the rpm2cpio and cpio -tv commands to list the files in the rhcsa-script-1.0.0-1.noarch.rpm package.

      [student@servera ~]$ rpm2cpio rhcsa-script-1.0.0-1.noarch.rpm | cpio -tv
      -rw-r--r--   1 root     root          593 Mar 23 08:24 ./opt/rhcsa-script/mymotd
      2 blocks
    2. Extract all files from the rhcsa-script-1.0.0-1.noarch.rpm package to the /home/student directory. Use the rpm2cpio and cpio -idv commands to extract the files and create the parent directories where needed in verbose mode.

      [student@servera ~]$ rpm2cpio rhcsa-script-1.0.0-1.noarch.rpm | cpio -idv
      ./opt/rhcsa-script/mymotd
      2 blocks
    3. List the files in the /home/student/opt directory to verify that the extracted files are the same as the files inside the package.

      [student@servera ~]$ ls -lR opt
      opt:
      total 0
      drwxr-xr-x. 2 student student 20 Mar 23 09:22 rhcsa-script
      
      opt/rhcsa-script:
      total 4
      -rw-r--r--. 1 student student 593 Mar 23 09:22 mymotd
  4. Install the rhcsa-script-1.0.0-1.noarch.rpm package. Use the sudo command to gain superuser privileges to install the package.

    1. Use the sudo rpm -ivh command to install the rhcsa-script-1.0.0-1.noarch.rpm RPM package.

      [student@servera ~]$ sudo rpm -ivh rhcsa-script-1.0.0-1.noarch.rpm
      [sudo] password for student: student
      Verifying...                          ################################# [100%]
      Preparing...                          ################################# [100%]
      Updating / installing...
         1:rhcsa-script-1.0.0-1             ################################# [100%]
      [student@servera ~]$
    2. Use the rpm command to verify that you correctly installed the package.

      [student@servera ~]$ rpm -q rhcsa-script
      rhcsa-script-1.0.0-1.noarch
  5. Exit from the servera machine and connect again to test the new message of the day.

    [student@servera ~]$ exit
    logout
    Connection to servera closed.
    [student@workstation ~]$ ssh student@servera
    ______         _   _   _       _     _____         _       _
    | ___ \       | | | | | |     | |   |_   _|       (_)     (_)
    | |_/ /___  __| | | |_| | __ _| |_    | |_ __ __ _ _ _ __  _ _ __   __ _
    |    // _ \/ _` | |  _  |/ _` | __|   | | '__/ _` | | '_ \| | '_ \ / _` |
    | |\ \  __/ (_| | | | | | (_| | |_    | | | | (_| | | | | | | | | | (_| |
    \_| \_\___|\__,_| \_| |_/\__,_|\__|   \_/_|  \__,_|_|_| |_|_|_| |_|\__, |
                                                                        __/ |
                                                                       |___/
    
    Activate the web console with: systemctl enable --now cockpit.socket
    
    Register this system with Red Hat Insights: insights-client --register
    Create an account or view all your systems at https://red.ht/insights-dashboard
    Last login: Wed Mar 23 09:21:26 2022 from 172.25.250.9
    [student@servera ~]$
  6. Return to the workstation system as the student user.

    [student@servera ~]$ exit
    logout
    Connection to servera closed.
    [student@workstation ~]$

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish software-rpm

This concludes the section.

Revision: rh124-9.0-398f302