Image of Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series)
Image of Beginning Google Maps API 3
Image of Operating System Concepts
Image of Modern Operating Systems (3rd Edition)

Configure a Host ISO-based Package Repository on a CentOS 7.2 VM

In a recent blog post, I demonstrated how to set up a local RPM repository (repo) in a VMware CentOS 7.2 VM (AKA guest) running under VMware Workstation (AKA the host.) This made the CentOS VM independent of the need for network access w.r.t. RPM package installation. However, the trade off for the ability to install packages without Internet access is the 6 GB plus increase in the size of the VM necessitated for storing all the packages and metadata.

Consider the following alternative scenario. You have downloaded the CentOS-7-x86_64-Everything-1511.iso from the CentOS Project or a mirror, used the ISO to create a CentoOS VM in VMware Workstation, and now want to be able to access a repo while you have no network access but without creating a local repo in the guest VM.

Well, it so happens that the CentOS ISO you downloaded contains a full repo and you can easily access the repo from your CentOS VM by following the steps described in this post. For the purposes of the post I use /var/centos72 as the mount point for the CD/DVD device connected to the CentOS ISO but, in practice, you can use any suitable mount point.

In the VM settings, add a CD/DVD device if necessary and connect (associate) the CentOS ISO with the CD/DVD device and ensure that the Connect at power on tickbox is ticked as shown in the following screenshot:

Once your VM has booted up and you are logged in a root, eject the CentOS DVD if it shows up on your desktop. Create a new subdirectory /var/centos72 and remount the DVD drive as shown below:

As you can see from the above image, if the mount worked, you can then cd to /var/centos72 and the contents of the ISO are available to you in the usual Unix tree-like structure.

To access the packages on the ISO using yum or dnf, you need to disable your existing repos (remember enabled=0?) and add a new repo which points to /var/centos72. Here is an example of such a repo definition.

# cat /etc/yum.repos.d/dvd.repo
name=CentOS 7.2 1511 All

To test if you have your repo definitions configured correctly, run yum -v repolist as shown below:

Only your newly created repo should be listed and you should see output similar to what is highlighted in the red box. It is also a good ides to run yum clear all first. I named my repo “DVD” but you are free to name it anything you like.

You can also use rpm -p to access package information as shown below:

To persist access to your new repository after a reboot, you need to add a suitable entry to /etc/fstab. Here is an example of such an entry based on the mount command used earlier in this post:

 /dev/sr0  /var/centos72  iso9660  loop,ro  0  0

What if the ISO is not mounted or if it’s location was moved and the VM setting for the path to the ISO was not updated? What if the ISO was not connected to the DVD device in the VM settings? Well, you are going to end up in emergency mode as shown below:

As shown in the screenshot, use journalctl to check for a /dev/sr0 mount failure. If you find such a failure, you can assume that the path to the Centos72 ISO was changed or the ISO was not connected to the DVD device.

To fix this issue you could comment out the /dev/sr0 entry in /etc/fstab and reboot the CentOS VM, or you could power off the VM, configure the correct path to the CentOS ISO or connect the ISO to the appropriate DVD device, and reboot the VM.

If you comment out the appropriate entry in /etc/fstab and try to continue booting using systemctl default, you will end up with a boot failure similar to the following:

The oddball-sounding g-io-error-quark is an artifact of Glib. A quark is a non-zero integer which uniquely identifies a particular string.

At this stage you only sane option is to reboot the VM or power it off.


P.S Something for you to explore. Can multiple CentOS VMs on a single host use a single host-locate ISO as their repo?

Leave a Reply