Skip to main content

RHEL | Mounting ISO and Setting as Local Repo

This document provides a guide on mounting the RHEL ISO and setting it up as a local repo. This will enable RedHat Linux to install and update RPM packages.

This guide may work on another type of Linux as it is based on editing the repo file and mounting ISO media.

Prerequisite

  1. A Free RedHat Account
  2. Official Redhat Linux ISO

No Redhat license is required.


Step 1: Identify the Red Hat OS version

Run the following:

cat /etc/os-release

Look for the line VERSION="8.7 (Ootpa)" in the output. This will shows the version number.

[user@demo ~]$ cat /etc/os-release
NAME="Red Hat Enterprise Linux"
VERSION="8.7 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.7"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.7 (Ootpa)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8::baseos"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/red_hat_enterprise_linux/8/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

Step 2: Download the RHEL ISO of the correct version

If you do not have an account, you must register a free account before downloading. Download the RHEL ISO of your version from the official RHEL download website.

Step 3: Mount the ISO from your Hypervisor

From your Hyper-V manager, add the ISO to the DVD drive device of the Virtual Machine.

Step 4: Identify the DVD Drive inside Red Hat Linux

Run the following to identify the correct device name of the DVD drive: lsblk

Look for the label rom in the TYPE column. For below example, it is sr0. This means that the DVD drive is located at /dev/sr0Take note of this device.

[user@demo ~]$ lsblk
NAME                   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                      8:0    0  100G  0 disk
├─sda1                   8:1    0    2G  0 part /boot
└─sda2                   8:2    0   97G  0 part
  ├─rhel-tmp           253:0    0    5G  0 lvm  /tmp
  ├─rhel-var_log       253:1    0   20G  0 lvm  /var/log
  ├─rhel-var           253:2    0   10G  0 lvm  /var
  ├─rhel-swap          253:3    0   12G  0 lvm  [SWAP]
  ├─rhel-home          253:4    0   10G  0 lvm  /home
  ├─rhel-root          253:5    0   30G  0 lvm  /
  ├─rhel-var_log_audit 253:6    0    5G  0 lvm  /var/log/audit
  └─rhel-var_tmp       253:7    0    5G  0 lvm  /var/tmp
sdb                      8:16   0  300G  0 disk
└─sdb1                   8:17   0  300G  0 part /data
sr0                     11:0    1  6.6G  0 rom

Step 5: Create a mountpoint and mount the DVD Drive locally

For this guide, the mountpoint used will be in /mnt/disc.

Run the following command. file /mnt/disc to create a mount point if it does not exist yet.

Output will show No such file or directory if it does not exist.

[user@demo ~]$ file /mnt/disc
/mnt/disc: cannot open `/mnt/disc' (No such file or directory)

Create the mountpoint /mnt/disc directory with sudo mkdir /mnt/disc.

[user@demo ~]$ sudo mkdir /mnt/disc
[user@demo ~]$ file /mnt/disc
/mnt/disc: directory

Next, mount the DVD drive (/dev/sr0) to the mountpoint (/mnt/disc) with the command mount -o loop RHEL7.9.iso /mnt/disc.

[user@demo ~]$ sudo mount -o loop /dev/sr0 /mnt/disc

With the DVD drive mounted, you can now list the content inside the disc with ls -al /mnt/disc.

[user@demo ~]$ ls -al /mnt/disc
total 53
dr-xr-xr-x. 7 root root  2048 Apr  4  2019 .
drwxr-xr-x. 3 root root    18 May 12 14:51 ..
dr-xr-xr-x. 4 root root  2048 Apr  4  2019 AppStream
dr-xr-xr-x. 4 root root  2048 Apr  4  2019 BaseOS
-r--r--r--. 1 root root    60 Apr  4  2019 .discinfo
dr-xr-xr-x. 3 root root  2048 Apr  4  2019 EFI
-r--r--r--. 1 root root  8266 Mar  1  2019 EULA
-r--r--r--. 1 root root  1455 Apr  4  2019 extra_files.json
-r--r--r--. 1 root root 18092 Mar  1  2019 GPL
dr-xr-xr-x. 3 root root  2048 Apr  4  2019 images
dr-xr-xr-x. 2 root root  2048 Apr  4  2019 isolinux
-r--r--r--. 1 root root   103 Apr  4  2019 media.repo
-r--r--r--. 1 root root  1669 Mar  1  2019 RPM-GPG-KEY-redhat-beta
-r--r--r--. 1 root root  5134 Mar  1  2019 RPM-GPG-KEY-redhat-release
-r--r--r--. 1 root root  1796 Apr  4  2019 TRANS.TBL
-r--r--r--. 1 root root  1566 Apr  4  2019 .treeinfo

Step 6: Copying the media.repo file

Copy the media.repo file from the root of the mounted directory to /etc/yum.repos.d/ and set the permissions to 644.

[user@demo ~]$ sudo cp /mnt/disc/media.repo /etc/yum.repos.d/rhel8dvd.repo
[user@demo ~]$ sudo chmod 644 /etc/yum.repos.d/rhel8dvd.repo

Step 7: Editing the rhel8dvd.repo

Edit the new repo file:

[user@demo ~]$ sudo vi /etc/yum.repos.d/rhel8dvd.repo

Copy the following into the file:

[InstallMedia-BaseOS]
name=Red Hat Enterprise Linux DVD BaseOS
mediaid=None
metadata_expire=-1
gpgcheck=1
cost=500
enabled=1
baseurl=file:///mnt/disc/BaseOS
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[InstallMedia-AppStream]
name=Red Hat Enterprise Linux DVD AppStream
mediaid=None
metadata_expire=-1
gpgcheck=1
cost=500
enabled=1
baseurl=file:///mnt/disc/AppStream
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

Disable any repo files that are not in use. Look for the line enabled = 1 and make sure that all are set to enabled = 0 in the other repo files.

[user@demo ~]$ cd /etc/yum.repos.d/
[user@demo yum.repos.d]$ sudo vi redhat.repo

Step 8: Clear the yum cache

Clear the cache and check whether you can get the packages list from the DVD repo

[user@demo ~]$ sudo yum clean all
[user@demo ~]$ sudo yum repolist enabled
Updating Subscription Management repositories.
repo id                                         repo name
InstallMedia-BaseOS                             Red Hat Enterprise Linux 8.7.0 BaseOS
InstallMedia-AppStream                          Red Hat Enterprise Linux 8.7.0 AppStream

Now, you can install any package with yum install <packagename> or update installed packages with yum update.


Disabling the Local Repo and Unmounting the DVD

This step should be completed before unmounting the DVD. To disable the local repo, delete the local repo file.

[user@demo ~]$ sudo rm rhel8dvd.repo

Unmount the DVD Drive from the mountpoint

[user@demo ~]$ sudo umount /mnt/disc
Now, you can remove the ISO from the DVD drive from the hypervisor.

Links