How to Setup YUM repositories From ISO CD-ROM Image

Creation of yum repositories is handled by a separate tool called createrepo, which generates the necessary XML metadata.

Step 1: Mount an ISO file

a) First you need to have the ISO CDROM image of the respective operating system.

b) Then you need to mount that iso image. Mounted devices are stored at: /mnt folder.

So lets create a directory named as “ISO” in /mnt folder. To create a directory use the below command:

   # mkdir -p /mnt/ISO

Once the directory is created then the path will look like /mnt/ISO

c) Now mount the iso image (filename.iso) using the below command:

 # mount -o loop filename.iso /mnt/ISO

 Then to install createrepo package, type the below command:

# yum install createrepo

 During this process if you get message as “createrepo command not found, then that package (createrepo) may not have been availoable on that system and so you need to first install it using the rpm -ivh command and the name of the createrepo-xxx.rpm pakage availabel on your ISO image/DVD.

 Step 2: Create a repository

You need to creat a folder for storing the repository data.
You can create the folder to any desired path but we prefer to create a directory named as “repo” in /mnt folder only for ease of understanding. Once the directory is created then the path will look like /mnt/repo

Use createrepo to generate the necessary XML metadata. Type the below command to do so:

# createrepo -o /mnt/repo .

Step 3: Create config file

a) You need to create a repo config file in /etc/yum.repos.d/ directory. Then add the below content in that file which shares the path where the ISO image has been mounted.

To create a file named as “file.repo” in /etc/yum.repos.d/ directory, type the below command:

# vi /etc/yum.repos.d/file.repo

Then add the below content in that file and then save & close the file:

 [My ISO Repository]
baseurl=file:///mnt/iso
enabled=1

 Step 4: Install the required package from ISO image using the “yum” command

# yum install <package name>