You are here:

Creating a Local YUM Repository with a CentOS ISO VPS Image

Creating a Local YUM Repository with a CentOS ISO VPS Image

Here are simple steps to utilize an ISO image to build a local YUM repository:

First, perform the preparatory work by downloading or copying the CentOS or Red Hat ISO image to the local system.

For example, you can place the ISO image in the directory /usr/local/src/. Let’s assume the file is named CentOS-6.4-x86_64-bin-DVD1.iso.

Second, mount the ISO image.

Create a new mount directory:

mkdir -p /mnt/cdrom1

Mount the ISO image to the created directory:

#Mount iso
/usr/local/src/CentOS-6.4-x86_64-bin-DVD1.iso /mnt/cdrom1 iso9660 loop,defaults 0 0

The implementation of the mount command with the -a option will automatically detect and activate the mount. If there are no reported issues, you can verify the results using the df -h command.

Third, configure and refresh the YUM repository.

Add the YUM configuration file:

Note:

  • If you are working in a completely offline environment, it is recommended to remove all online YUM sources:mv -f /etc/yum.repos.d/* /home/
  • After that, create and edit the `/etc/yum.repos.d/local.repo` file:sudo vi /etc/yum.repos.d/local.repo
  • Add the following lines, ensuring the third line specifies the ISO mount directory:[local] name=Local Repository baseurl=file:///mnt/iso enabled=1 gpgcheck=0
  • Save and exit the editor.
[local-yum]
name=Local Repository
baseurl=file:///mnt/cdrom1
enabled=1
gpgcheck=0

Refresh and check if YUM is effective:

yum clean all && yum list

If there are no errors during the steps above, your local YUM repository is now configured. You can install the required software without the need for a network connection using the appropriate YUM commands.

Fourth, a variation for handling multiple ISO images:

Note: The following instructions are provided to address differences.

When mounting multiple ISOs, each ISO will be mounted individually. For example, CentOS 6.4 may have two ISOs:

#Create 2 mount directories
mkdir -p /mnt/cdrom{1,2}
#Mount iso
/usr/local/src/CentOS-6.4-x86_64-bin-DVD1.iso /mnt/cdrom1 iso9660 loop,defaults 0 0
/usr/local/src/CentOS-6.4-x86_64-bin-DVD2.iso /mnt/cdrom2 iso9660 loop,defaults 0 0
#Activate the mount
mount -a

Edit the YUM configuration file, and the path needs to be adjusted accordingly. For instance:

[local-yum]
name=Local Repository
baseurl=file:///mnt/
enabled=1
gpgcheck=0

Use the createrepo command to create a YUM repository:

cd /mnt/
createrepo .
Was this article helpful?
Dislike 0