How to create local repository distributed through apache of Red Hat Enterprise Linux 5/6/7/8/9 using DVD iso for update or installation?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 9

Issue

  • How do I configure a yum local repository distributed through apache to share the contents of a DVD ISO via HTTP on Red Hat Enterprise Linux?
  • What are the steps required to use the Network Installation method for Red Hat Enterprise Linux using http source?
  • How to create local repository of Red Hat Enterprise Linux 5/6/7/8/9 using DVD iso for update or installation?
  • How to upgrade the minor version of RHEL when not connected to internet?
  • How to configure internal yum repository?

Resolution

Create a repo via ISO image which can only be used by this server itself(Self-hosted):

  • Mount the iso file to /mnt/rhiso as the yum destination.

    # mkdir -p /mnt/rhiso
    # mount -o loop RHELX-XXXX.iso /mnt/rhiso
    
  • If using a DVD, put the DVD into cdrom and mount the DVD to /mnt/rhiso as the yum destination.

    # mkdir -p /mnt/rhiso
    # mount /dev/cdrom /mnt/rhiso
    
  • Create a yum repo file, /etc/yum.repos.d/dvd.repo on the server:

    [RHEL5-Server-DVD]
    name=Red Hat Enterprise Linux $releasever - $basearch (DVD)
    baseurl=file:///mnt/rhiso/Server
    enabled=1
    gpgcheck=1 
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
    
  • If using RHEL for workstation, then:

    [RHEL-Server-DVD]
    name=Red Hat Enterprise Linux $releasever - $basearch (DVD)
    baseurl=file:///mnt/rhiso/Workstation
    enabled=1
    gpgcheck=1 
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
    
  • If using Red Hat Enterprise Linux 8/9, then:

       # vi /etc/yum.repos.d/BaseOS.repo
       [BaseOS]
       name=Red Hat Enterprise Linux 8.0 BaseOS
       baseurl=file:///mnt/rhiso/BaseOS/
       enabled=1
       gpgcheck=1
       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
    
       # vi /etc/yum.repos.d/AppStream.repo
       [AppStream]
       name=Red Hat Enterprise Linux 8.0 AppStream
       baseurl=file:///mnt/rhiso/AppStream/
       enabled=1
       gpgcheck=1
       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
    

Configure apache (httpd) based yum repository, which can be used by this server and another server.

Prerequisites:
  • The server hosting the yum repository must have the httpd and yum packages installed.
  • The client servers using the yum repository must have the yum package installed.
Steps:
  • On the httpd server, copy the contents from the Red Hat Enterprise Linux DVD ISO RHELX-XXXX.iso to the destination web directory.

    # mkdir -p /var/www/html/cdrom/
    # mount -o loop RHELX-XXXX.iso /media
    # shopt -s dotglob
    # cp -apvR /media/* /var/www/html/cdrom/
    
  • Modify the following entries in /etc/httpd/conf/httpd.conf, where <ip_address> is the repository server's IP address.

    ServerAdmin root@<ip_address>
    DocumentRoot /var/www/html/
    ServerName <ip_address> 
    

Note : The ServerName parameter might be absent.

  • Confirm the httpd configuration, then restart the service:

    # httpd -t
    # service httpd start
    
  • Now, one should be able to access the all important repomd.xml file with lynx :

    # lynx http://<ip_address>/cdrom/repodata/repomd.xml
    
  • If Apache throws a 403 forbidden error error this could very well be SELinux getting in the way. Make sure SELinux context is correct on httpd contents.

       # chcon -R -t httpd_sys_content_t /var/www/html/cdrom/
    
       Or
    
       # restorecon -vR /var/www/html/cdrom/
    
  • Verify the change in context. The context httpd_sys_content_t is expected instead of iso9660_t or otherwise.

    # ls -ldZ /var/www/html/cdrom/*
    dr-xr-xr-x. 2 root root system_u:object_r:httpd_sys_content_t:s0 61440 Dec 21 21:02 /var/www/html/cdrom/Packages
    dr-xr-xr-x. 2 root root system_u:object_r:httpd_sys_content_t:s0  4096 Jan 17 08:12 /var/www/html/cdrom/repodata
    <snip>
    
  • On the client system, configure a yum repo file that points to the server:

    # cat /etc/yum.repos.d/dvd.repo
    [RHEL5-Server-DVD]
    name=Red Hat Enterprise Linux $releasever - $basearch (DVD)
    baseurl=http://<ip_address>/cdrom/
    enabled=1
    gpgcheck=1 
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
    
  • If you wish to install/update Cluster and Cluster Storage packages in RHEL5, add the below lines in /etc/yum.repos.d/dvd.repo file.

       # cat /etc/yum.repos.d/dvd.repo
       [RHEL5-Cluster]
       name=Red Hat Enterprise Linux Cluster
       baseurl=http://<ip_address>/cdrom/Cluster
       enabled=1
       gpgcheck=1 
       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
    
       [RHEL5-ClusterStorage]
       name=Red Hat Enterprise Linux - ClusterStorage
       baseurl=http://<ip_address>/cdrom/ClusterStorage
       enabled=1
       gpgcheck=1 
       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
    
  • If you wish to update HighAvailability and ResilientStorage packages in RHEL6, add the below lines in /etc/yum.repos.d/dvd.repo file.

       # cat /etc/yum.repos.d/dvd.repo
       [RHEL6-HighAvailability]
       name=Red Hat Enterprise Linux HighAvailability
       baseurl=http://<ip_address>/cdrom/HighAvailability
       enabled=1
       gpgcheck=1 
       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
    
       [RHEL6-ResilientStorage]
       name=Red Hat Enterprise Linux - ResilientStorage
       baseurl=http://<ip_address>/cdrom/ResilientStorage
       enabled=1
       gpgcheck=1 
       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
    
  • Verify the client configuration:

       # yum clean all
       # yum repolist
       [...]
       RHEL5-Server-DVD             | 1.5 kB     00:00     
       RHEL5-Server-DVD/primary     | 920 kB     00:00     
       RHEL5-Server-DVD                               3285/3285
    
       repo id          repo name       status
    
       RHEL5-Server-DVD Red Hat Enterprise Linux 5Server - x86_64 (DVD)    3,285
                   repolist: 3,285
    
  • To update the client:

    # yum update
    
HTTPD Source for kickstart installations:
  1. Install httpd package, if installed, skip this step.

    #  yum install httpd
    
  2. Create a directory /var/www/html/rhel6/, if created, skip this step.

    #  mkdir /var/www/html/rhel6/
    
  3. Insert the RHEL DVD into the DVD drive and mount that under /mnt

    #  mount /dev/sr0 /mnt
    
  4. Now prepare the shell to copy each and every content to /var/www/html/rhel6/ directory.

    #  shopt -s dotglob
    #  cp -apvrf /mnt/* /var/www/html/rhel6/
    
  5. Start the service and make it on in chkconfig.

    #  service httpd restart;chkconfig httpd on
    
  6. Now use the following url in kickstart file, the installation will be done through http source.

    url --url=http://<ip>/rhel6/
    

For Red Hat Enterprise Linux 8 & 9, the only difference is that there are now two repositories need to setup through DVD ISO

The steps can be as follows.

  • Mount the Red Hat Enterprise Linux 8/9 DVD ISO as follows.

    # mount -o loop  rhel-8.0-x86_64-dvd.iso /mnt
    
  • Copy all data to /var/www/html/ or to any local directory.

    # shopt -s dotglob
    # cp -avRpf /mnt/* /var/www/html/
    
  • Create .repo files as follows for clients. Choose appropriate 'name' lable for RHEL 9 .repo entries

       # cat /etc/yum.repos.d/BaseOS.repo
       [BaseOS]
       name=Red Hat Enterprise Linux 8.0 BaseOS
       enabled=1
       gpgcheck=1
       baseurl=http://<Server-IP>/BaseOS/
    
       # cat /etc/yum.repos.d/AppStream.repo
       [AppStream]
       name=Red Hat Enterprise Linux 8.0 AppStream
       enabled=1
       gpgcheck=1
       baseurl=http://<Server-IP>/AppStream/
    
  • Clean existing yum/dnf cache and get updated repository lists on clients.

    # dnf clean all
    # rm -rf /var/cache/yum/*
    # dnf makecache
    # dnf repolist
    
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.