Skip to main content

RHEL | Mounting ISO and Setting as Local Repo

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 command in the terminal:

cat /etc/os-release

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

[user@lab-rhel8 ~]$ 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 DVD drive is located at /dev/sr0Take note of this device.

[user@lab-rhel8 ~]$ 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 /appdata
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 mountpoint, if it does not exist yet.

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

[user@lab-rhel8 ~]$ 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@lab-rhel8 ~]$ sudo mkdir /mnt/disc
[user@lab-rhel8 ~]$ 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@lab-rhel8 ~]$ 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@lab-rhel8 ~]$ 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@lab-rhel8 ~]$ sudo cp /mnt/disc/media.repo /etc/yum.repos.d/rhel8dvd.repo
[user@lab-rhel8 ~]$ sudo chmod 644 /etc/yum.repos.d/rhel8dvd.repo

Step 7: Editing the rhel8dvd.repo

Edit the new repo file:

[user@lab-rhel8 ~]$ 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 the any repo files that is 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@lab-rhel8 ~]$ cd /etc/yum.repos.d/
[user@lab-rhel8 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@lab-rhel8 ~]$ sudo yum clean all
[user@lab-rhel8 ~]$ 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 packages with yum install <packagename> or update installed packages with yum update.

Disabling the Local Repo and Unmounting the DVD

This step is to be done before unmounting the DVD. To disable the local repo, simply delete the local repo file.

[user@lab-rhel8 ~]$ cd /etc/yum.repos.d
[user@lab-rhel8 yum.repos.d]$ sudo rm rhel8dvd.repo

Unmount the DVD Drive from the mountpoint

[user@lab-rhel8 yum.repos.d]$ sudo umount /mnt/disc