Mount an ISO File in Linux and Create a Local Package Repository

Problem Overview

  • In many environments, Linux servers do not have direct internet access due to security restrictions or network policies. Installing or updating packages in such systems becomes difficult when online repositories are unavailable.
  • To solve this, Linux provides a way to mount an ISO image locally and use it as a local package repository. This approach is commonly used for:
    • Offline servers
    • Air-gapped environments
    • Faster package installations
    • Consistent package versions across systems
  • By creating a local repository from an ISO file, package management tools can install software without relying on external networks.

Prerequisites

Before creating a local repository from an ISO file, ensure the following:

  • Root or sudo access on the system
  • ISO file of the Linux distribution available locally
  • Sufficient disk space for mounting
  •  
  • System running a supported Linux distribution

Solution

  • Copy the required RHEL ISO file to the Linux system where the local repository will be configured.

    • [root@pythonlinuxhub ~]# cd /home/pythonlinuxhub/
      [root@pythonlinuxhub pythonlinuxhub]# ls -lrth
      total 13G
      -rw-r--r--. 1 pythonlinuxhub pythonlinuxhub  13G Jan  6 00:11 rhel-9.7-x86_64-dvd.iso
  • Mount the ISO file to a directory using a loop device so it behaves like installation media.

    • [root@pythonlinuxhub pythonlinuxhub]# mkdir -p /mnt/disc
      [root@pythonlinuxhub pythonlinuxhub]# mount -o loop rhel-9.7-x86_64-dvd.iso /mnt/disc
      mount: /mnt/disc: WARNING: source write-protected, mounted read-only.
  • Create a repository file named rhel9.repo inside /etc/yum.repos.d/ and configure it to point to the mounted ISO path.

    • [root@pythonlinuxhub pythonlinuxhub]# cd /etc/yum.repos.d/
      [root@pythonlinuxhub yum.repos.d]# cat rhel9.repo
      [BaseOS]
      name=BaseOS Packages Red Hat Enterprise Linux 9
      metadata_expire=-1
      gpgcheck=0
      enabled=1
      baseurl=file:///mnt/disc/BaseOS/
      
      [AppStream]
      name=AppStream Packages Red Hat Enterprise Linux 9
      metadata_expire=-1
      gpgcheck=0
      enabled=1
      baseurl=file:///mnt/disc/AppStream/
  • Clear existifng package manager cache and refresh repository metadata to load the new local repository.

    • [root@pythonlinuxhub yum.repos.d]# yum clean all
      Updating Subscription Management repositories.
      Unable to read consumer identity
      
      This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.
      
      0 files removed
      
      [root@pythonlinuxhub yum.repos.d]# yum repolist
      Updating Subscription Management repositories.
      Unable to read consumer identity
      
      This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.
      
      repo id                                                      repo name
      AppStream                                                    AppStream Packages Red Hat Enterprise Linux 9
      BaseOS                                                       BaseOS Packages Red Hat Enterprise Linux 9
  • Validate the setup by installing the httpd package from the newly created local repository.

    • [root@pythonlinuxhub yum.repos.d]# yum install -y httpd

Shaik Mohammed Faruk

Software Engineer sharing practical tutorials and insights on Linux, Python, SQL, and modern technologies.

Read more About Me

0 0 votes
Article Rating
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Thanks for your interest!

Content for this is getting ready and will be published soon.

0
Would love your thoughts, please comment.x
()
x