Search

How to mirror or copy a repository in Red Hat Enterprise Linux 9

How to mirror or copy a repository in Red Hat Enterprise Linux 9

How to mirror or copy a repository in Red Hat Enterprise Linux 9

To create a local mirror repo of the latest update for Red Hat Enterprise Linux 9 without using the Satellite server. The main purpose is to create local mirror repo for use to provide packages for the hosts on your LAN that are not connected to the internet, and therefore cannot access the upstream repos directly.

Setting up mirrored repos for Red Hat Enterprise Linux 9

To start, you’ll need to choose the web server that will serve the mirrored repos to your LAN. Then, if you’re using Red Hat Enterprise Linux 9, then to create a basic repo you have to start by installing createrepo_c. Don’t worry, this tool is included in your subscription, too. Install it on your web server with the following:

sudo dnf install createrepo_c

Next, you need the repository ID for the repo you would like to sync. Run yum repolist, and you’ll find the repo ID in the output’s first column:

[root@localhost ~]# subscription-manager repos --list
+----------------------------------------------------------+
    Available Repositories in /etc/yum.repos.d/redhat.repo
+----------------------------------------------------------+
Repo ID:   rhel-9-for-x86_64-appstream-rpms
Repo Name: Red Hat Enterprise Linux 9 for x86_64 - AppStream (RPMs)
Repo URL:  https://cdn.redhat.com/content/dist/rhel9/$releasever/x86_64/appstream/os
Enabled:   1

Repo ID:   rhel-9-for-x86_64-baseos-rpms
Repo Name: Red Hat Enterprise Linux 9 for x86_64 - BaseOS (RPMs)
Repo URL:  https://cdn.redhat.com/content/dist/rhel9/$releasever/x86_64/baseos/os
Enabled:   1

Repo ID:   rhel-9-for-x86_64-baseos-source-rpms
Repo Name: Red Hat Enterprise Linux 9 for x86_64 - BaseOS (Source RPMs)
Repo URL:  https://cdn.redhat.com/content/dist/rhel9/$releasever/x86_64/baseos/source/SRPMS
Enabled:   0

For example, to sync the packages from the "rhel-9-for-x86_64-appstream-rpms" repo and create a basic local repository, execute the following commands:

For example, Basic local repository Location is /var/www/repo :

For Red Hat Enterprise Linux 9, this process is even easier. You only need the reposync command:

Basic syntax of reposync for Red Hat Enterprise Linux 9 :

reposync -p <-download-path-> --download-metadata --repo=<-repo id->  
reposync -p /var/www/repo --download-metadata --repo=rhel-9-for-x86_64-appstream-rpms

Final Repo Location Will be /var/www/repo/rhel-9-for-x86_64-appstream-rpms

Sharing the local repository to Your Local Network

Once the packages are fetched and the local repo is created using either of these methods, the local repository can be distributed among the offline/disconnected systems using a simple web server, FTP, or NFS. The following knowledgebase articles provide the necessary information regarding your choice of distribution:

  • Apache (HTTP)
  • Apache (HTTPS)
  • FTP
  • NFS share

 

Create Repo File in ‘/etc/yum.repos.d/’ Directory

Create a repo file with name "rhel9-local.repo" under the folder /etc/yum.repos.d/ with following content

Create a repo file with name "rhel9-local.repo" under the folder /etc/yum.repos.d/ with following content

sudo vi /etc/yum.repos.d/rhel9-local.repo

Following Repo content

Basic syntax of repo for Red Hat Enterprise Linux 9 :

[<-repo-id->]
baseurl=https://ServerHostname/<-repo-id->/
enabled=1

Basic syntax of repo for Red Hat Enterprise Linux 9. In my case host name is linuxits.com :

 
[rhel-9-for-x86_64-appstream-rpms]
baseurl=https://linuxits.com/rhel-9-for-x86_64-appstream-rpms/
enabled=1

Finnaly Save and close the file.

To Verify Repo content File output will be

cat /etc/yum.repos.d/rhel9-local.repo
 
[rhel-9-for-x86_64-appstream-rpms]
baseurl=https://linuxits.com/rhel-9-for-x86_64-appstream-rpms/
enabled=1

Flush Yum/DNF & Subscription Manager Cache

Execute following commands to clean yum or dnf and subscription manager cache.:

sudo dnf clean all
sudo subscription-manager clean

To Disable Red Hat subscription manager warning message

In the above output, we are getting a warning message ‘This system is not registered with an entitlement’. So, if you want to disable this warning message, edit the file ‘/etc/yum/pluginconf.d/subscription-manager.conf’ , change the parameter ‘enabled=1’ to ‘enabled=0’.

sudo vi /etc/yum/pluginconf.d/subscription-manager.conf

Save and exit the file.

For Test Install any rpm Packages using Local Repository

Now we are all set to test our local repository. Run beneath command to view configure repository.

sudo dnf repolist

Now, You can Install packages using yum/dnf command via above configure local repository.

sudo dnf install httpd

Output,

[root@localhost ~]# sudo dnf install httpd
Last metadata expiration check: 0:22:33 ago on Tue 21 Jun 2022 08:40:50 PM +06.
Dependencies resolved.
=====================================================================================================================================================
 Package                                Architecture                 Version                                 Repository                         Size
=====================================================================================================================================================
Installing:
 httpd                                  x86_64                       2.4.51-7.el9_0                          rhel-9-for-x86_64-appstream-rpms                       1.5 M
Installing dependencies:
 apr                                    x86_64                       1.7.0-11.el9                            rhel-9-for-x86_64-appstream-rpms                       127 k
 apr-util                               x86_64                       1.6.1-20.el9                            rhel-9-for-x86_64-appstream-rpms                        98 k
 apr-util-bdb                           x86_64                       1.6.1-20.el9                            rhel-9-for-x86_64-appstream-rpms                        15 k
 httpd-tools                            x86_64                       2.4.51-7.el9_0                          rhel-9-for-x86_64-appstream-rpms                        88 k
Installing weak dependencies:
 apr-util-openssl                       x86_64                       1.6.1-20.el9                            rhel-9-for-x86_64-appstream-rpms                        17 k
 mod_http2                              x86_64                       1.15.19-2.el9                           rhel-9-for-x86_64-appstream-rpms                       153 k
 mod_lua                                x86_64                       2.4.51-7.el9_0                          rhel-9-for-x86_64-appstream-rpms                        63 k

Transaction Summary
=====================================================================================================================================================
Install  8 Packages

Total size: 2.1 M
Installed size: 5.9 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                             1/1
  Installing       : apr-1.7.0-11.el9.x86_64                                                                                                     1/8
  Installing       : apr-util-bdb-1.6.1-20.el9.x86_64                                                                                            2/8
  Installing       : apr-util-1.6.1-20.el9.x86_64                                                                                                3/8
  Installing       : apr-util-openssl-1.6.1-20.el9.x86_64                                                                                        4/8
  Installing       : httpd-tools-2.4.51-7.el9_0.x86_64                                                                                           5/8
  Installing       : mod_lua-2.4.51-7.el9_0.x86_64                                                                                               6/8
  Installing       : mod_http2-1.15.19-2.el9.x86_64                                                                                              7/8
  Installing       : httpd-2.4.51-7.el9_0.x86_64                                                                                                 8/8
  Running scriptlet: httpd-2.4.51-7.el9_0.x86_64                                                                                                 8/8
  Verifying        : apr-util-openssl-1.6.1-20.el9.x86_64                                                                                        1/8
  Verifying        : apr-util-1.6.1-20.el9.x86_64                                                                                                2/8
  Verifying        : mod_lua-2.4.51-7.el9_0.x86_64                                                                                               3/8
  Verifying        : apr-1.7.0-11.el9.x86_64                                                                                                     4/8
  Verifying        : httpd-2.4.51-7.el9_0.x86_64                                                                                                 5/8
  Verifying        : apr-util-bdb-1.6.1-20.el9.x86_64                                                                                            6/8
  Verifying        : mod_http2-1.15.19-2.el9.x86_64                                                                                              7/8
  Verifying        : httpd-tools-2.4.51-7.el9_0.x86_64                                                                                           8/8
Installed products updated.

Installed:
  apr-1.7.0-11.el9.x86_64         apr-util-1.6.1-20.el9.x86_64          apr-util-bdb-1.6.1-20.el9.x86_64     apr-util-openssl-1.6.1-20.el9.x86_64
  httpd-2.4.51-7.el9_0.x86_64     httpd-tools-2.4.51-7.el9_0.x86_64     mod_http2-1.15.19-2.el9.x86_64       mod_lua-2.4.51-7.el9_0.x86_64

Complete!
[root@localhost ~]#

Conclusion

In this tutorial, We can create a local mirror repo of the latest update for Red Hat Enterprise Linux 9 and update LAN Server.

Sys Admin

Sys Admin

I am a Red Hat Certified Engineer (RHCE) and working as an IT Professional since 2012...