Create a RHEL/CentOS local yum repo from the OS disk
Creating a local yum repository from the OS installer disk(s) (CD/DVD) can be useful in many situations where the machine doesn’t have Internet access to install additional packages. While the installer disk can still be used after the initial OS installation, it is more convenient to use a local repository especially if more than one machine need access to the packages.
This guide is for RHEL6.3 but it should work fairly well with other RHEL releases (e.g. RHEL 6.4), clones (CentOS 6.4) and RHEL-like distributions (Fedora).
step1: mount the OS disk and copy the contents to a local path which will be the main repository path:
mkdir -p /mnt/cd /opt/yum/rhel6.3/repodata mount -o loop /dev/sr0 /mnt/cd cp -a /mnt/cd/Packages/*.rpm /opt/yum/rhel6.3
step2: copy the main xml file from main repodata folder to the new repo path:
cp /mnt/cd/repodata/*comps*.xml /opt/yum/rhel6.3/repodata/comps.xml
Note: This is not necessarily needed, but it is useful if you want to use yum to query / install package groups (e.g. yum grouplist).
step3: generate local repository files
cd /opt/yum/rhel6.3/ createrepo -g repodata/comps.xml .
Note: the createrepo RPM is available in the official RHEL/CentOS/Fedora repositories.
step4.1: create new yum repository (e.g. rhel-local.repo)
cat /etc/yum.repos.d/rhel-local.repo [rhel6.3-local] name=RHEL 6.3 local repository baseurl=file:///opt/yum/rhel6.3/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release enabled=1
step4.2 (optional): store repository on a local FTP server
- copy /opt/yum/rhel6.3/ to the remote machine in its FTP path (e.g. /var/ftp/) and make sure FTP is reachable
- copy the RPM GPG key from /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release to the remote FTP path (e.g. /var/ftp/rhel6.3)
- create the repository file on the local machine (e.g. rhel-ftp.repo)
cat /etc/yum.repos.d/rhel-ftp.repo [rhel6.3-ftp] name=RHEL 6.3 FTP repository baseurl=ftp://192.168.0.100/rhel6.3/ gpgcheck=1 gpgkey=ftp://192.168.0.100/rhel6.3/RPM-GPG-KEY-redhat-release enabled=1
step5: test the repository
yum clean all yum repolist repo id repo name status rhel6.3-ftp RHEL 6.3 FTP repository 3,653 rhel6.3-local RHEL 6.3 local repository 3,653
That’s it, both the local and the FTP yum repositories are now fully functional.
Hi,
1.You need to just copy the packages folder and run createrepo to create repository and then create the client file dvd.repo.
2. Mount dvd in a custom location ie /media/dvd (avoid spaces in b/w mountpoint name – as its tough while pointing in yum URL) and then create the client file dvd.repo
But if i need to include updates ie the new updates? What should i do? How can i download all those to my local system? Please let me know if there is some solution to this?
@Jithinsha: one way is to use a tool such as reposync to synchronize a remote yum repository to a local folder.
@admin
Yes, reposync is an option. But this option works fine for CentOS. But not for RedHat.
@Jithinsha: According to Red Hat reposync works with RHEL5/6/7
@admin : I have tried to use reposync on Redhat and it failed. If someone can provide some tips on using reposync over RHN would be appreciated.
What software can you recommend to back up a small server that is compatible with CentOS that can back up to cd’s?