I have written about the yum package manager in the past, and it’s one of the main reasons I use CentOS and Fedora Linux. Various 3rd party yum repositories are also available, allowing you to gain access to numerous packages that aren’t available in the stock distributions. This is great, but sometimes you want to create your own packages and distribute them to your clients. This is a piece of cake with yum, since you can create your own yum repositories.
To create your own yum repository, you will first need to install the yum-utils and createrepo packages:
yum install yum-utils createrepo
The createrepo package contains the createrepo utility, which can be used to create the repository metadata from a set of RPMS. The yum-utils package contains a couple of useful tools for managing repositories, including the verifytree and reposync commands. Once you have the tools installed, you will need to create a directory to store your RPMs and metadataa.
mkdir -p /var/www/html/repo/centos/5.3/updates
After the directory is created, you can use your favorite tool to copy the RPMs to this directory:
rsync -a rsync://mirrors.usc.edu/centos/5.3/updates/x86_64/RPMS/ /var/www/html/repo/centos/5.3/updates/RPMS
Next up, we need to create the repository metadata to go along with the RPMs. The createrepo utility was written to do just this, and takes the path to the base RPM directory as an argument:
createrepo -v -s md5 /var/www/html/repo/centos/5.3/updates
This will take several minutes to run, and will populate a number of files in the repodata directory:
total 3208 -rw-r--r--. 1 root root 2509241 2009-11-24 11:43 filelists.xml.gz -rw-r--r--. 1 root root 381198 2009-11-24 11:43 other.xml.gz -rw-r--r--. 1 root root 371826 2009-11-24 11:43 primary.xml.gz -rw-r--r--. 1 root root 984 2009-11-24 11:43 repomd.xml
The repomd.xml file contains the package sources, as well as pointers to one or more .gz files. The .gz files contains the list of packages that are available, as well as metadata to describe the package. If the repository was created successfully, you can verify the contents with the verifytree utility:
Loaded plugins: refresh-packagekit Checking repodata: verifying repomd.xml with yum verifying filelists checksum verifying other checksum verifying primary checksum Checking groups (comps.xml): verifying comps.xml with yum comps file missing or unparseable
Assuming all went as planned, you should now have a usable repository! To tell your clients to use it, you can create a new repository file in /etc/yum.repos.d. Here is an example:
[mattys-updates] name=Mattys Update Server baseurl=http://master/repo/centos/5.3/updates enabled=1 gpgcheck=1
Now the next time you run ‘yum search’ on your clients, the packages in the newly created repository should be available. I really dig yum, and love the fact that they make the entire package management process relatively simple and straight forward!