Install fresh copies of centos 7 base repos
Asked Answered
D

3

11

I am using centos 7. During some testing, I accidentally removed all files in yum.repo.d. Is there a way, to download and configure all basic repos in centos 7

Density answered 25/4, 2017 at 9:33 Comment(0)
U
16

Assuming you are running CentOS-7.3, you can get back the repo files the following way,

# ReInstall the centos-release rpm
~]#  rpm -Uvh --force \
     http://mirror.centos.org/centos-7/7/os/x86_64/Packages/centos-release-7-3.1611.el7.centos.x86_64.rpm

# Clean YUM cache
~]# yum clean all

# Try an update
~]# yum update

centos-release RPM contains all the repo files,

~]#  rpm -qlp \
     http://mirror.centos.org/centos-7/7/os/x86_64/Packages/centos-release-7-3.1611.el7.centos.x86_64.rpm 2>/dev/null | grep repo
/etc/yum.repos.d/CentOS-Base.repo
/etc/yum.repos.d/CentOS-CR.repo
/etc/yum.repos.d/CentOS-Debuginfo.repo
/etc/yum.repos.d/CentOS-Media.repo
/etc/yum.repos.d/CentOS-Sources.repo
/etc/yum.repos.d/CentOS-Vault.repo
/etc/yum.repos.d/CentOS-fasttrack.repo
Used answered 26/4, 2017 at 1:19 Comment(6)
For getting the correct URL it is possible to run "rpm --query centos-release" or directly "rpm -Uvh --force mirror.centos.org/centos-7/7/os/x86_64/Packages/$("rpm --query centos-release).rpm"Szombathely
Note, older releases are not always in the same URL. They are moved to vault.centos.org.Used
Also there slipped a quotation mark into the brackets ;-) Sorry for that.Szombathely
The release url is: mirror.centos.org/centos-7/7/os/x86_64/Packages/…Lais
NOTE: older release: mirror.centos.org/centos-7/7/os/x86_64/Packages/… is moved to vault.centos.org/7.3.1611/os/x86_64/Packages/… rpm -Uvh --force \ vault.centos.org/7.3.1611/os/x86_64/Packages/…Superorder
@Szombathely - doesnt work, maybe this way but still doesnt work rpm -Uvh --force http://mirror.centos.org/centos-7/7/os/x86_64/Packages/`rpm --query centos-release`.rpmDiphenylamine
G
8

Old good copy/paste approach has right to live:

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates 

[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Gaea answered 13/10, 2018 at 11:47 Comment(0)
S
7
#!/bin/bash

install-centos-release() {
 releasever="$(rpm -q --qf '%{VERSION}' "$(rpm -q --whatprovides centos-release)")" \
 && releasever="$(printf "%s" "$releasever" | sed -e 's/\..*$//g')" \
 && basearch="$(uname -m)" \
 && reposurl=$(printf "%s" "http://mirror.centos.org/centos/$releasever/os/$basearch/Packages/") \
 && releaserpm=$(curl --silent "$reposurl" | grep -oP '(?<=")centos-release.*.rpm(?=")') \
 && releaseuri=$(printf "%s%s" "$reposurl" "$releaserpm") \
 && rpm -Uvh --force "$releaseuri"
}

Usage:

# Either launch a new terminal and copy `install-centos-release` into the current shell process, 
# or create a shell script and add it to the PATH to enable command invocation with bash.

install-centos-release

# Refresh YUM repository(ies)
yum clean all
yum -y update
Sheen answered 2/5, 2018 at 3:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.