Create Local YUM Repository from Systemd Mounted DVD on RHEL 7

We can mount DVDs/partitions using systemd.mount by writing a mount unit file.

Ensure that a RHEL7 DVD is inserted (or attached if using a VM).

Create a mountpoint:

# mkdir /mnt/rhel7dvd

Note that mount units must be named after the mountpoint directories they control. In our case, the mountpoint /mnt/rhel7dvd has to be configured in the file mnt-rhel7dvd.mount. The unit file name has to match the mountpoint path.

Here’s the context of the newly created file /etc/systemd/system/mnt-rhel7dvd.mount:

[Unit]
Description=rhel7dvd

[Mount]
What=/dev/cdrom
Where=/mnt/rhel7dvd

[Install]
WantedBy=multi-user.target

Reload the systemd daemon and start the unit:

# systemctl daemon-reload
# systemctl start mnt-rhel7dvd.mount
# systemctl enable mnt-rhel7dvd.mount

Create a Yum repo file /etc/yum.repos.d/rhel7dvd.repo with the following content:

[dvd]
name=rhel7 dvd
baseurl=file:///mnt/rhel7dvd
enabled=1
gpgcheck=1
gpgkey=file:///mnt/rhel7dvd/RPM-GPG-KEY-redhat-release

[dvd-ha]
name=add-on HighAvailability
baseurl=file:///mnt/rhel7dvd/addons/HighAvailability
enabled=1
gpgcheck=1
gpgkey=file:///mnt/rhel7dvd/RPM-GPG-KEY-redhat-release

[dvd-rs]
name=add-on ResilientStorage
baseurl=file:///mnt/rhel7dvd/addons/ResilientStorage
enabled=1
gpgcheck=1
gpgkey=file:///mnt/rhel7dvd/RPM-GPG-KEY-redhat-release

Verify:

# yum clean all && yum repolist
Cleaning repos: dvd dvd-ha dvd-rs
Cleaning up everything
Loaded plugins: product-id, subscription-manager
dvd                                                | 4.1 kB     00:00     
dvd-ha                                             | 4.1 kB     00:00     
dvd-rs                                             | 4.1 kB     00:00     
(1/6): dvd/group_gz                                  | 134 kB   00:00     
(2/6): dvd-rs/primary_db                             |  28 kB   00:00     
(3/6): dvd/primary_db                                | 3.4 MB   00:00     
(4/6): dvd-ha/group_gz                               | 3.4 kB   00:00     
(5/6): dvd-ha/primary_db                             |  21 kB   00:00     
(6/6): dvd-rs/group_gz                               | 4.9 kB   00:00     
repo id                   repo name                                 status
dvd                       rhel7 dvd                                 4,371
dvd-ha                    add-on HighAvailability                      25
dvd-rs                    add-on ResilientStorage                      36
repolist: 4,432

14 thoughts on “Create Local YUM Repository from Systemd Mounted DVD on RHEL 7

  1. Hi Tomas , just wanted to know what is the purpose of using a mount unit file instead of using normal mount command to mount the rhel7 DVD.
    Thanks.

    • The fstab way is simpler, but I wouldn’t say that it’s any better compared to systemd, likely the opposite. For example, systemd gives you flexibility to specify when to mount each point.

    • The createrepo program creates a repomd repository from a set of rpms. There is no need to use it on a DVD because the content of the DVD is already a repository.

      When you install RedHat/CentOS from a DVD, you use that DVD as an installation media repository.

    • Strangely my experience was different… After I unpacked the .iso to a directory on an http server and configured the repo to download from there, I got errors 404 for the repodata files. It only got fixed after running createrepo on the extracted files.

  2. Wait, what kind of dark magic is this? ;-) You aren’t issuing mount command nor editing /etc/fstab yet you get the cdrom/dvdrom mounted?! :-)
    Great guide, thanks for compiling it. And thank you for compiling your entire blog, the name “blog” itself may be misleading, you created something way beyond just a blog…

Leave a Reply

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