CentOS through a VM - no URLs in mirrorlist

LinuxCentosVagrantVirtualboxRedhat

Linux Problem Overview


I am trying to run a CentOS 8 server through VirtualBox (6.1.30) (Vagrant), which worked just fine yesterday for me, but today I tried running a sudo yum update. I keep getting this error for some reason:

[[email protected]] ~  >> sudo yum update
CentOS Linux 8 - AppStream                       71  B/s |  38  B     00:00
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

I already tried to change the namespaces on /etc/resolve.conf, remove the DNF folders and everything. On other computers, this works just fine, so I think the problem is with my host machine. I also tried to reset the network settings (I am on a Windows 10 host), without success either. It's not a DNS problem; it works just fine.

After I reinstalled Windows, I still have the same error in my VM.

File dnf.log:

2022-01-31T15:28:03+0000 INFO --- logging initialized ---
2022-01-31T15:28:03+0000 DDEBUG timer: config: 2 ms
2022-01-31T15:28:03+0000 DEBUG Loaded plugins: builddep, changelog, config-manager, copr, debug, debuginfo-install, download, generate_completion_cache, groups-manager, needs-restarting, playground, repoclosure, repodiff, repograph, repomanage, reposync
2022-01-31T15:28:03+0000 DEBUG YUM version: 4.4.2
2022-01-31T15:28:03+0000 DDEBUG Command: yum update
2022-01-31T15:28:03+0000 DDEBUG Installroot: /
2022-01-31T15:28:03+0000 DDEBUG Releasever: 8
2022-01-31T15:28:03+0000 DEBUG cachedir: /var/cache/dnf
2022-01-31T15:28:03+0000 DDEBUG Base command: update
2022-01-31T15:28:03+0000 DDEBUG Extra commands: ['update']
2022-01-31T15:28:03+0000 DEBUG User-Agent: constructed: 'libdnf (CentOS Linux 8; generic; Linux.x86_64)'
2022-01-31T15:28:05+0000 DDEBUG Cleaning up.
2022-01-31T15:28:05+0000 SUBDEBUG
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 574, in load
    ret = self._repo.load()
  File "/usr/lib64/python3.6/site-packages/libdnf/repo.py", line 397, in load
    return _repo.Repo_load(self)
libdnf._error.Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 67, in main
    return _main(base, args, cli_class, option_parser_class)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 106, in _main
    return cli_run(cli, base)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 122, in cli_run
    cli.run()
  File "/usr/lib/python3.6/site-packages/dnf/cli/cli.py", line 1050, in run
    self._process_demands()
  File "/usr/lib/python3.6/site-packages/dnf/cli/cli.py", line 740, in _process_demands
    load_available_repos=self.demands.available_repos)
  File "/usr/lib/python3.6/site-packages/dnf/base.py", line 394, in fill_sack
    self._add_repo_to_sack(r)
  File "/usr/lib/python3.6/site-packages/dnf/base.py", line 137, in _add_repo_to_sack
    repo.load()
  File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 581, in load
    raise dnf.exceptions.RepoError(str(e))
dnf.exceptions.RepoError: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
2022-01-31T15:28:05+0000 CRITICAL Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

Linux Solutions


Solution 1 - Linux

Check out this article: CentOS Linux EOL

The below commands helped me:

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*

Doing this will make DNF work, but you will no longer receive any updates.

To upgrade to CentOS 8 stream:

sudo dnf install centos-release-stream -y
sudo dnf swap centos-{linux,stream}-repos -y
sudo dnf distro-sync -y

Optionally reboot if your kernel updated (not needed in containers).

Solution 2 - Linux

CentOS 8 became EOL at the end of 2021. A long term solution is to migrate to a different operating system, like Rocky Linux.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEylonView Question on Stackoverflow
Solution 1 - Linuxbob stingerView Answer on Stackoverflow
Solution 2 - LinuxpirtView Answer on Stackoverflow