How to create a local repository using a ISO in CentOS 7

Dear friend, Today we will see how to create a local repository using a ISO in CentOS 7. I will see you step by step commands and process, so that you can easily create a local repository in your server when you need it.

As you know some time we don’t have internet connection and we need to up-grade some packages or we need to install some packages then we can create a local repository using ISO image and we can install and up-grade package using yum tool.

In this tutorial we will cover this below topics: –

How to mount ISO image on CentOS 7?

How to create repository file?

How to clean repository list?

How to check repository list?

How to install packages with yum tool using local repository?

So let’s start step by step process to create local repository in CentOS 7.

First all we need to be copy our ISO image on our server. You can see here I have copied my ISO image on home directory.

[[email protected] ~]# pwd /root [[email protected] ~]# ls -l total 4556820 -rw-r--r--. 1 root root        355 May  5 12:41 1 -rw-------. 1 root root       1225 Apr  9 14:15 anaconda-ks.cfg -rw-r--r--. 1 root root 4470079488 Jan 22 18:10 CentOS-7-x86_64-DVD-1804.iso [[email protected] ~]# 

How to mount ISO image on CentOS 7?

Now we need to be mount this ISO in /mnt directory. We can use below command to mount this ISO file.

[[email protected] ~]# mount -o loop CentOS-7-x86_64-DVD-1804.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
[[email protected] ~]#

We can check our /mnt drive is mounted our not using df -h like below: –

[[email protected] ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        45G  6.1G   39G  14% /
devtmpfs        2.9G     0  2.9G   0% /dev
tmpfs           2.9G     0  2.9G   0% /dev/shm
tmpfs           2.9G  8.6M  2.9G   1% /run
tmpfs           2.9G     0  2.9G   0% /sys/fs/cgroup
/dev/sda1       497M  118M  379M  24% /boot
tmpfs           581M     0  581M   0% /run/user/0
/dev/loop0      4.2G  4.2G     0 100% /mnt
[[email protected] ~]#

You can see in above our /mnt drive has been successfully mounted.

How to create repository file?

Now we need to be create repository file. We can go to /etc/yum.repos.d/ directory and create a centos7.repo with this content. Like below:-

[[email protected] ~]# cat /etc/yum.repos.d/centos7.repo
[CentOS7]
name=CentOS7
baseurl=file:///mnt
enabled=1
gpgcheck=0
[[email protected] ~]#

How to clean repository list?

After the file creation we need to be clean our repository list using below command.

[[email protected] ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: CentOS7 base epel extras remi-php73 remi-safe updates
Cleaning up list of fastest mirrors
[[email protected] ~]#

How to check repository list?

Now we can check our repository list using below command:-

[[email protected] ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base: centos.mirror.ate.info
epel: epel.besthosting.ua
extras: centos.mirror.fr.planethoster.net
remi-php73: fr2.rpmfind.net
remi-safe: ap.stykers.moe
updates: centos.crazyfrogs.org
repo id                                 repo name                                                                             status
CentOS7                                               CentOS7                                                                                3,971
base/7/x86_64                           CentOS-7 - Base                                                                       10,019
*epel/x86_64                            Extra Packages for Enterprise Linux 7 - x86_64                                        13,216
extras/7/x86_64                         CentOS-7 - Extras                                                                        409
remi-php73                              Remi's PHP 7.3 RPM repository for Enterprise Linux 7 - x86_64                            312
remi-safe                               Safe Remi's RPM repository for Enterprise Linux 7 - x86_64                             3,343
updates/7/x86_64                        CentOS-7 - Updates                                                                     1,982
repolist: 33,252
[[email protected] ~]#

How to install packages with yum tool using local repository?

Now we can install packages using our local repository like below:-

[[email protected] ~]# yum install ntp
Loaded plugins: fastestmirror
CentOS7                                                                                                      | 3.6 kB  00:00:00
Loading mirror speeds from cached hostfile
base: centos.mirror.ate.info
epel: epel.besthosting.ua
extras: centos.mirror.fr.planethoster.net
remi-php73: fr2.rpmfind.net
remi-safe: ap.stykers.moe
updates: centos.crazyfrogs.org
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-28.el7.centos will be installed
--> Processing Dependency: ntpdate = 4.2.6p5-28.el7.centos for package: ntp-4.2.6p5-28.el7.centos.x86_64
--> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-28.el7.centos.x86_64
--> Running transaction check
---> Package autogen-libopts.x86_64 0:5.18-5.el7 will be installed
---> Package ntpdate.x86_64 0:4.2.6p5-28.el7.centos will be installed
--> Finished Dependency Resolution 
Dependencies Resolved
 ====================================================================================================================================
Package                           Arch                     Version                                 Repository                 Size
Installing:
ntp                               x86_64                   4.2.6p5-28.el7.centos                   CentOS7                   549 k
Installing for dependencies:
autogen-libopts                   x86_64                   5.18-5.el7                              CentOS7                    66 k
ntpdate                           x86_64                   4.2.6p5-28.el7.centos                   CentOS7                    86 k
Transaction Summary
Install  1 Package (+2 Dependent packages)
Total download size: 701 k
Installed size: 1.6 M
Is this ok [y/d/N]: y
Downloading packages:
Total                                                                                                32 MB/s | 701 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : autogen-libopts-5.18-5.el7.x86_64                                                                                1/3
Installing : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                             2/3
Installing : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                 3/3
Verifying  : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                             1/3
Verifying  : autogen-libopts-5.18-5.el7.x86_64                                                                                2/3
Verifying  : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                 3/3
Installed:
ntp.x86_64 0:4.2.6p5-28.el7.centos
Dependency Installed:
autogen-libopts.x86_64 0:5.18-5.el7                             ntpdate.x86_64 0:4.2.6p5-28.el7.centos
Complete!
[[email protected] ~]#

That’s all we have successfully created local repository using ISO image in CentSO 7 server.

You can also see this below link, how to configure NTP server and NTP client on CentOS 7

2 thoughts on “How to create a local repository using a ISO in CentOS 7

Leave a Reply

Your email address will not be published. Required fields are marked *