How to use yum on EOL CentOS 6 [Repository change]

table of contents
Hello everyone.
I'm Naka from the System Solutions Department, and I hope that network lines of 1Gbps or more will become the default.
It is strongly recommended to migrate older environments such as CentOS 6 environments, but they may remain for various reasons
In such an environment, you are likely to encounter situations where you cannot use "yum" to update or add something (or an error will occur if you try to use it)
This time, we will explain and provide instructions on how to "make yum available on CentOS 6 (change repository)" to resolve this situation
Introduction
- We do not recommend using CentOS 6.
This is a temporary solution for CentOS 6, which exists for unavoidable reasons - The goal is not to use the base repository, but to make it possible to use "yum"
- This is the procedure to resolve the issue caused by the default repository
Execution environment
■ Windows environment
OS: Windows 11 Pro (version: 23H2)
Language setting: Changed to Japanese■ Verification CentOS 6 environment (Vagrant + VirtualBox)
OS: CentOS 6.9 (bento/centos-6.9)
Vagrant: 2.4.1
VirtualBox: 7.0.18 r162988 (Qt5.15.2)
IP: 192.168.33.15
Hostname: targetnode
Username: vagrant
Repository Cause - Error: Cannot find a valid baseurl for repo: base
$ yum info Loaded plugins: fastestmirror Determining fastest mirrors YumRepo Error: All mirror URLs are not using ftp, http[s] or file. Eg. Invalid release/repo/arch combination/ removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt Error: Cannot find a valid baseurl for repo: base
When you try to use "yum" you will most likely see the error "Error: Cannot find a valid baseurl for repo: base"
error occurs because all default repositories have been closed (terminated) due to EOL,
To resolve this issue, you will need to configure a separate repository for CentOS 6 that you can use
Work Procedure
0. Check for yum errors
Just to be sure, check to make sure you don't proceed with the work even though there are no problems
$ yum info Loaded plugins: fastestmirror Determining fastest mirrors YumRepo Error: All mirror URLs are not using ftp, http[s] or file. Eg. Invalid release/repo/arch combination/ removing mirrorlist with no valid mirrors: /var/tmp/yum-vagrant-BcYfuY/x86_64/6/base/mirrorlist.txt Error: Cannot find a valid baseurl for repo: base
⇓
Error: Cannot find a valid baseurl for repo: base
Now that we've identified the error, let's get to work
1. Back up your repository
Before making any changes to your repository, make a dated backup
There is a possibility that you may end up saving it with all of its contents deleted, so it's a good idea to keep it
$ cp -p /etc/yum.repos.d/CentOS-Base.repo /tmp/CentOS-Base.repo.`date +%Y%m%d` $ ls -l /tmp | grep CentOS-Base.repo -rw-r--r--. 1 vagrant vagrant 1991 Mar 28 2017 CentOS-Base.repo.2024xxxx
(It is a temporary backup so it is created in /tmp)
TIps: CentOS-Base.repo.`date +%Y%m%d`
The command result is treated as a string using backquotes (`).
Within this, the data command, which can display the date and time, is used with the specified format (year, month, day).
This is convenient because you can take a backup without having to look at a calendar, with the file name ending in the date and year at the time the command was executed
2. Modifying the repository
○ 2-1. Check the default state
If you leave the repository as default, it should look like this:
$ less /etc/yum.repos.d/CentOS-Base.repo ~Omitted~ [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/ ~Omitted~ [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/ ~Omitted~ [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/ ~Omitted~ [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/ ~Omitted~ [contrib] name=CentOS-$releasever - Contrib mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/ ~Omitted~
○ 2-2. The mirror list is not functioning, so disable it (comment out)
Comment out the "mirrorlist=http://mirrorlist.centos.org" part, but editing multiple places can easily result in mistakes
Therefore, we will use the sed command to perform a bulk replacement
$ sudo sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\/mirrorlist.centos.org/g" /etc/yum.repos.d/CentOS-Base.repo
○ 2-3. Rewrite baseurl and enable it (comment in)
Uncomment "#baseurl=" and specify that you want to use the CentOS repository provided by IIJ.
*This specifies a repository that is available as of July 2024. If the repository is discontinued in the future, please specify a different one.
This can also be replaced in bulk using the sed command
$ sudo sed -i -e "s/^#baseurl=http:\/\/mirror.centos.org\/centos\/\$releasever/baseurl=http:\/\/ftp.iij.ad.jp\/pub\/linux\/centos-vault\/\$releasever/g" /etc/yum.repos.d/CentOS-Base.repo
If you want to rewrite it manually, change the "#baseurl=" part as shown below
#baseurl=http://mirror.centos.org/centos/$releasever ⇓ baseurl=http://ftp.iij.ad.jp/pub/linux/centos-vault/$releasever
○ 2-4. Check changes/differences
Check the differences between the edited repo and the backup repo to make sure the changes are what you intended
$ diff /etc/yum.repos.d/CentOS-Base.repo /tmp/CentOS-Base.repo.`date +%Y%m%d` 15,16c15,16 < #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra < baseurl=http://ftp.iij.ad.jp/pub/linux/centos-vault/$releasever/os/$basearch/ --- > mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra > #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ ~Omitted~
As shown above, there is no problem as long as the difference between the before and after changes can be obtained
○ 2-5. Specify the variable "$releasever"
To pin a minor release, include the version in the "releasever" variable
This is done by creating a variable file to fix the values.
(If the values are already specified/fixed, this step is not necessary.)
$ ls -l /etc/yum/vars/ | grep releasever *Make sure it hasn't been created $ sudo sh -c 'echo "6.9" > /etc/yum/vars/releasever' *Create and add *If you run it as root, echo "6.9" > /etc/yum/vars/releasever is fine. $ cat /etc/yum/vars/releasever *Make sure it's listed 6.9
There is no problem as the written value 6.9 is displayed
3. Check that yum is working and clear the cache
3-1. Check that yum is available with yum info
Let's display the package information for php:
$ yum info php Loaded plugins: fastestmirror Determining fastest mirrors Available Packages Name: php Arch: x86_64 Version: 5.3.3 Release: 49.el6 Size: 1.1 M Repo: base Summary: PHP scripting language for creating dynamic web sites URL: http://www.php.net/ License: PHP Description: PHP is an HTML-embedded scripting language. PHP attempts to make it ~omitted~
If the version and other information is displayed as shown above, yum is working properly
○ 3-2. Clear yum cache
Although it is not necessary, since we have made changes to yum, we will clear the cache
$ sudo yum clean all Loaded plugins: fastestmirror Cleaning repos: base extras updates Cleaning up Everything Cleaning up list of fastest mirrors
completion
This completes the repository change procedure to resolve the "yum" error
lastly
This process itself is not difficult.
However, it is easy to get stuck with this error when you want to use "yum", so it is easier to do it in advance in a CentOS 6 environment.
I hope this article will provide some useful knowledge and information to those who read it.
Thank you for reading this far.
Reference materials
How do I change the CentOS 6 repository address? | Alibaba Cloud
https://www.alibabacloud.com/help/en/ecs/user-guide/change-the-centos-6-source-address
8.2.3. Displaying Package Information | RHEL6
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/sec-displaying_package_information
4