Building a Repository With createrepo_c
Goal
You collect rpms, build a repository with createrepo_c, register it with a .repo file, and install from that repository alone.
Why it matters
The number one cause of the most frequent report on air-gapped networks, "I put it in the repository but it doesn't show", is forgetting createrepo_c --update. The files are visible but dnf does not know. The second is the client cache. If you get the order of these two into your hands, 90% of those reports end within minutes.
And if you know the structure of repomd.xml, you can judge what is and is not in the repository — for example, if there is no updateinfo, dnf update --security quietly does nothing.
Steps
- Create the
/root/repo/pooldirectory and download thetreepackage and its dependencies into that directory without installing. There must be at least one.rpm. - Build metadata in
/root/repo/poolwithcreaterepo_c.repodata/repomd.xmlmust appear. - Create
/etc/yum.repos.d/labhub-local.repo. The repository ID islabhub-local, thenamemust contain a snapshot date (the stringsnapshotandYYYY-MM-DD), and it must includebaseurl=file:///root/repo/pool,enabled=1,gpgcheck=0, andmetadata_expire=-1. - Refresh the cache and save the repository list to
/root/repo/repolist.txt.labhub-localmust be visible. - With all other repositories turned off and only
labhub-localon, reinstalltree, and save that command's output to/root/repo/install.txt. - Download the
nanopackage into the pool as well, then incrementally update the metadata, and after updating, write the number of packages in thelabhub-localrepository as a single numeric line in/root/repo/pkgcount.txt. - From
repomd.xml, pull out only the metadata type names and write them in/root/repo/mdtypes.txt, one per line.primary,filelists, andothermust all be present. - Make
/root/repo/report.txtwith the following 4 lines.REPO_ID=labhub-local/PACKAGES=<6번 값>/MDTYPES=<7번 파일의 줄 수>/HAS_UPDATEINFO=<yes|no>(that is, the value from step 6, the number of lines in the step 7 file, and yes or no)
Notes
- Downloading is
dnf download --resolve --destdir=/root/repo/pool tree. - To use just one repository, it takes the form
dnf --disablerepo='*' --enablerepo=labhub-local install -y tree. If it is already installed and you want to fetch it again, use thereinstallsubcommand, notinstall --reinstall— in this dnf (4.14),install --reinstalldies withunrecognized arguments. - The incremental update is
createrepo_c --update /root/repo/pool. - You can count the packages per repository with something like
dnf --disablerepo='*' --enablerepo=labhub-local list available --all | wc -l.repoqueryis also good. - Common mistake 1: not running
dnf clean expire-cacheafter reindexing in step 6, so you see the old information. - Common mistake 2: getting the number of slashes in
baseurlwrong in step 3. A local path isfile://followed by an absolute path, so there are three slashes.
Collecting rpms
Create the /root/repo/pool directory and download the tree package and its dependencies into that directory without installing. There must be at least one .rpm.
dnf has a command that downloads only the rpm without installing. Also use the option that downloads the dependencies as well.
Generating metadata
Build metadata in /root/repo/pool with createrepo_c. repodata/repomd.xml must appear.
If you give createrepo_c a directory, it creates repodata under it.
Writing the repository definition
Create /etc/yum.repos.d/labhub-local.repo. The repository ID is labhub-local, the name must contain a snapshot date (the string snapshot and YYYY-MM-DD), and it must include baseurl=file:///root/repo/pool, enabled=1, gpgcheck=0, and metadata_expire=-1.
It is a .repo file under yum.repos.d. What is inside the square brackets is the repository ID, and name, baseurl, and enabled are required.
Refreshing the cache and checking
Refresh the cache and save the repository list to /root/repo/repolist.txt. labhub-local must be visible.
After marking the metadata cache as expired, look at the repository list. The new repository must be visible.
Installing from that repository alone
With all other repositories turned off and only labhub-local on, reinstall tree, and save that command's output to /root/repo/install.txt.
There is an option combination that turns off all repositories and turns on only one.
Updating after adding a package
Download the nano package into the pool as well, then incrementally update the metadata, and after updating, write the number of packages in the labhub-local repository as a single numeric line in /root/repo/pkgcount.txt.
dnf sees it only if you put in the rpm and reindex. There is an incremental update option.
Checking the repomd.xml structure
From repomd.xml, pull out only the metadata type names and write them in /root/repo/mdtypes.txt, one per line. primary, filelists, and other must all be present.
Each metadata type is shown with the type attribute. Pull out only the type names.
Repository report
Make /root/repo/report.txt with the following 4 lines.
REPO_ID=labhub-local / PACKAGES=<6번 값> / MDTYPES=<7번 파일의 줄 수> / HAS_UPDATEINFO=<yes|no> (that is, the value from step 6, the number of lines in the step 7 file, and yes or no)
Gather the number of packages and the metadata types. The values must be actual check results.