Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save whatafunc/9eea50f58eeec4a8c3f8f70ed3f1dd67 to your computer and use it in GitHub Desktop.

Select an option

Save whatafunc/9eea50f58eeec4a8c3f8f70ed3f1dd67 to your computer and use it in GitHub Desktop.
Fix CentOS 7 repo to link to vault repos && install KVM/virtualization Python library
#!/bin/bash
sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo
sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo
sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
sed -i 's/^metalink=/#metalink=/g' /etc/yum.repos.d/epel*.repo
sed -i 's|http://download.fedoraproject.org/pub/epel|https://archives.fedoraproject.org/pub/archive/epel|g' /etc/yum.repos.d/epel*.repo
sed -i '/\[base\]/,/enabled=/ s/enabled=0/enabled=1/' /etc/yum.repos.d/CentOS-Base.repo
yum clean all
rm -rf /var/cache/yum
yum makecache
yum --releasever=7 --enablerepo=ol7_kvm_utils install -y python36-libvirt
# it's a repo surgery script that redirects a dead CentOS 7 system to archive mirrors so yum works again,
# then installs a KVM/virtualization Python library. Safe to run if you trust the source
@whatafunc

Copy link
Copy Markdown
Author

CentOS 7 Repository Fix Script Explained

Why This Script Is Needed

CentOS 7 reached end-of-life in June 2024, so the original mirror servers (mirror.centos.org) were shut down. Packages are now only available at a vault/archive URL. This script surgically updates your repo config files so yum works again.


The Script

#!/bin/bash
sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo
sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo
sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
sed -i 's/^metalink=/#metalink=/g' /etc/yum.repos.d/epel*.repo
sed -i 's|http://download.fedoraproject.org/pub/epel|https://archives.fedoraproject.org/pub/archive/epel|g' /etc/yum.repos.d/epel*.repo
sed -i '/\[base\]/,/enabled=/ s/enabled=0/enabled=1/' /etc/yum.repos.d/CentOS-Base.repo
yum clean all
rm -rf /var/cache/yum
yum makecache
yum --releasever=7 --enablerepo=ol7_kvm_utils install -y python36-libvirt

Step-by-Step Breakdown

Lines 2–5 — Fix CentOS Repo Files

  • Replaces mirror.centos.orgvault.centos.org (the official archive)
  • Uncomments baseurl= lines so they are active
  • Comments out mirrorlist= lines (the mirror list no longer works)

Lines 6–7 — Fix the Base Repo Specifically

Same intent as above, using a slightly different sed pattern to handle the CentOS-Base.repo file format.

Lines 8–9 — Fix EPEL Repo

EPEL (Extra Packages for Enterprise Linux) also went offline for CentOS 7:

  • Disables metalink= (also dead)
  • Redirects downloads to archives.fedoraproject.org (the EPEL archive)

Line 10 — Re-enable the [base] Repo

Flips enabled=0enabled=1 in case the base repo was disabled.

Lines 11–13 — Refresh Yum Cache

yum clean all          # Wipe old/broken cache
rm -rf /var/cache/yum  # Remove cached metadata files
yum makecache          # Rebuild cache from the new archive URLs

Line 14 — Install the Target Package

yum --releasever=7 --enablerepo=ol7_kvm_utils install -y python36-libvirt

Installs python36-libvirt — Python 3.6 bindings for libvirt/KVM virtualization — using:

  • --releasever=7: pins to CentOS 7 release files
  • --enablerepo=ol7_kvm_utils: pulls from an Oracle Linux repo for KVM utilities

Summary

Section What It Does
Lines 2–7 Redirect CentOS repos from dead mirrors to vault archive
Lines 8–9 Redirect EPEL repo to Fedora archive
Line 10 Ensure [base] repo is enabled
Lines 11–13 Refresh yum package cache
Line 14 Install python36-libvirt from KVM utils repo

Safe to run on any EOL CentOS 7 system where yum is broken due to dead mirrors.

# CentOS 7 Repository Fix Script Explained

Why This Script Is Needed

CentOS 7 reached end-of-life in June 2024, so the original mirror servers (mirror.centos.org) were shut down. Packages are now only available at a vault/archive URL. This script surgically updates your repo config files so yum works again.


The Script

#!/bin/bash
sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo
sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo
sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
sed -i 's/^metalink=/#metalink=/g' /etc/yum.repos.d/epel*.repo
sed -i 's|http://download.fedoraproject.org/pub/epel|https://archives.fedoraproject.org/pub/archive/epel|g' /etc/yum.repos.d/epel*.repo
sed -i '/\[base\]/,/enabled=/ s/enabled=0/enabled=1/' /etc/yum.repos.d/CentOS-Base.repo
yum clean all
rm -rf /var/cache/yum
yum makecache
yum --releasever=7 --enablerepo=ol7_kvm_utils install -y python36-libvirt

Step-by-Step Breakdown

Lines 2–5 — Fix CentOS Repo Files

  • Replaces mirror.centos.orgvault.centos.org (the official archive)
  • Uncomments baseurl= lines so they are active
  • Comments out mirrorlist= lines (the mirror list no longer works)

Lines 6–7 — Fix the Base Repo Specifically

Same intent as above, using a slightly different sed pattern to handle the CentOS-Base.repo file format.

Lines 8–9 — Fix EPEL Repo

EPEL (Extra Packages for Enterprise Linux) also went offline for CentOS 7:

  • Disables metalink= (also dead)
  • Redirects downloads to archives.fedoraproject.org (the EPEL archive)

Line 10 — Re-enable the [base] Repo

Flips enabled=0enabled=1 in case the base repo was disabled.

Lines 11–13 — Refresh Yum Cache

yum clean all          # Wipe old/broken cache
rm -rf /var/cache/yum  # Remove cached metadata files
yum makecache          # Rebuild cache from the new archive URLs

Line 14 — Install the Target Package

yum --releasever=7 --enablerepo=ol7_kvm_utils install -y python36-libvirt

Installs python36-libvirt — Python 3.6 bindings for libvirt/KVM virtualization — using:

  • --releasever=7: pins to CentOS 7 release files
  • --enablerepo=ol7_kvm_utils: pulls from an Oracle Linux repo for KVM utilities

Summary

Section What It Does
Lines 2–7 Redirect CentOS repos from dead mirrors to vault archive
Lines 8–9 Redirect EPEL repo to Fedora archive
Line 10 Ensure [base] repo is enabled
Lines 11–13 Refresh yum package cache
Line 14 Install python36-libvirt from KVM utils repo

Safe to run on any EOL CentOS 7 system where yum is broken due to dead mirrors.

@whatafunc

Copy link
Copy Markdown
Author

But plain yum update from the vault? It's bounded and safe in terms of compatibility. The concern is more about operational disruption than package conflicts.

@whatafunc

Copy link
Copy Markdown
Author

.. and for the yum update -y docker-ce docker-ce-cli containerd.io - this one can broke the OS? or yum checks what it gets prior to installing?
yum does check before installing — it resolves dependencies automatically. So if a new version of docker-ce requires a newer containerd.io or runc, yum will pull those in together or warn you about conflicts. It won't blindly install something broken.

But there's a small caveat for Docker specifically:

Docker packages (docker-ce, docker-ce-cli) come from Docker's own repo, not the CentOS vault. So unlike the vault which is frozen, Docker's repo does have newer versions. There's a small chance a newer Docker release has a dependency that's slightly ahead of what your CentOS 7 system libraries can support — though in practice Docker has maintained good CentOS 7 compatibility for a long time.

The more realistic risk is operational, not OS breakage:

  • Running containers will not be affected mid-update
  • But the Docker daemon restarts after the update, which means:
    • Containers that aren't set to restart: always will stop
    • Any active docker build or docker exec sessions will drop

Safest way to do it:

# 1. Check what version yum would install first (dry run)
yum update --assumeno docker-ce docker-ce-cli containerd.io

# 2. If it looks fine, do it during a maintenance window
yum update -y docker-ce docker-ce-cli containerd.io

The --assumeno flag lets yum show you exactly what it plans to do without actually doing it. Good habit on a production-ish machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment