Scenario
A RHEL-like server was cloned into a lab network and package installs are failing. The repo configuration may be incomplete, or a custom repo was added incorrectly. You need to audit what is enabled, confirm repo definitions on disk, add a repo file safely, validate metadata, then disable the broken repo cleanly.
Repo failures can block patching and incident response. Treat repo files as configuration artifacts: back up before changes, validate repodata, and disable cleanly so you can restore service without losing context.
Objective
- List enabled repositories and inspect a repo’s details.
-
Audit repo definition files under
/etc/yum.repos.d. - Back up an existing repo file before changes.
-
Create a new
.repofile with a valid repo id. -
Validate repodata and caching behavior with
dnf makecache. - Disable a broken repo without deleting the file.
- Clean metadata and confirm the repo is no longer enabled.
Concepts
-
DNF consumes repository definitions from
/etc/yum.repos.d/*.repoand treats each bracketed section as a repo id. -
Repo health is primarily a metadata problem. If DNF cannot
fetch
repodata/repomd.xml, installs and updates will stall. - Disable broken repos before deleting anything. Preserving repo files keeps evidence for root cause and rollback.
- Cache behavior matters. After repo changes, clean metadata so you are not validating against stale repodata.
-
Use targeted repo inspection (
dnf repoinfo) to confirm baseurls and enablement state before you troubleshoot higher layers.
Walkthrough
dnf repolist enabled
This is the fastest baseline check when installs fail. If expected repos are missing or disabled, nothing downstream will work.
repo id repo name
appstream Rocky Linux 9 - AppStream
baseos Rocky Linux 9 - BaseOS
extras Rocky Linux 9 - Extras
ls -1 /etc/yum.repos.d
Repos are defined by
.repo
files in this directory. Missing files often explains
missing repos.
rocky.repo
rocky-addons.repo
sudo cp /etc/yum.repos.d/rocky.repo /etc/yum.repos.d/rocky.repo.bak
This is your safety net. If a repo change breaks installs, restore quickly and keep troubleshooting with known-good configuration.
Backup created: /etc/yum.repos.d/rocky.repo.bak
dnf repoinfo baseos
Confirm the
baseurl
and whether the repo is enabled. A bad URL usually turns
into metadata errors.
Repo-id : baseos
Repo-name : Rocky Linux 9 - BaseOS
Repo-baseurl : https://download.rockylinux.org/pub/rocky/9/BaseOS/x86_64/os/
Repo-enabled : yes
/etc/yum.repos.d
(custom.repo).
sudo vim /etc/yum.repos.d/custom.repo
A repo file must include a repo id in brackets and a
baseurl. This lab uses a deliberately broken URL so you can
recognize the failure mode.
[custom-tools]
name=Custom Tools Repo
baseurl=https://repo.example.lab/rhel/9/x86_64/
enabled=1
gpgcheck=0
sudo cat /etc/yum.repos.d/custom.repo
You want to see the bracketed repo id and the URL. Typos here become metadata failures later.
sudo dnf makecache
This forces DNF to read repo configuration and attempt to
fetch
repodata/repomd.xml. A 404 usually means the baseurl is wrong or the repo is not
structured correctly.
Custom Tools Repo 0.0 B/s | 0 B 00:00
Errors during downloading metadata for repository 'custom-tools':
- Status code: 404 for https://repo.example.lab/rhel/9/x86_64/repodata/repomd.xml
sudo dnf config-manager --set-disabled custom-tools
Disabling keeps the configuration on disk for review, while immediately unblocking package operations.
Repository 'custom-tools' is disabled.
sudo dnf clean metadata
This removes cached metadata so you can rebuild cleanly and confirm the error no longer appears.
0 files removed
dnf repolist enabled
Verification is the final step. You should see only expected repos enabled.
repo id repo name
appstream Rocky Linux 9 - AppStream
baseos Rocky Linux 9 - BaseOS
extras Rocky Linux 9 - Extras
(custom-tools is disabled)
Common breakpoints
If you have no enabled repos, package operations will fail
across the board. Confirm repo files exist in
/etc/yum.repos.d
and that expected sections are set to
enabled=1.
A 404 usually means the baseurl path is wrong or the repo is not laid out correctly. Timeouts usually indicate DNS, routing, proxy, or firewall issues between the host and the repo endpoint.
If
dnf config-manager
is unavailable, the plugin package may not be installed on
your distro. Install the appropriate plugin package, or
disable the repo by editing the repo file and setting
enabled=0.
Cached metadata may still reference the repo. Run
dnf clean metadata
and retry
dnf makecache
to confirm you are validating against a clean state.
Cleanup checklist
Your cleanup is confirming the system is back to a known-good repo state and the broken repo is disabled but preserved on disk for review.
dnf repolist enabled
sudo dnf clean metadata
sudo dnf makecache
Metadata builds without errors, and
dnf repolist enabled
shows only the expected repos.
Reference
-
ls -1 /etc/yum.repos.d: Lists repo definition files present on disk. -
cp /etc/yum.repos.d/<file> /etc/yum.repos.d/<file>.bak: Creates a backup of a repo file before changes. -
vim /etc/yum.repos.d/<name>.repo: Creates or edits a repo definition file. -
cat /etc/yum.repos.d/<name>.repo: Validates a repo file is readable and contains expected keys. -
dnf repolist enabled: Shows repositories currently enabled. -
dnf repoinfo <repoid>: Shows repository details (baseurl, enabled state, etc.). -
dnf makecache: Builds repository metadata cache to validate repo access. -
dnf config-manager --set-disabled <repoid>: Disables a repo without deleting the repo file.-
--set-disabled: Marks the repo as disabled.
-
-
dnf clean metadata: Removes cached metadata after repo changes.