61

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:

[vagrant@192.168.38.4] ~  >> 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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eylon
  • 628
  • 1
  • 3
  • 7
  • The answers here edit the repo files directly, you should be able to simply use [`dnf` itself to update the mirror lists](https://stackoverflow.com/a/71020440/2518317) – Hashbrown Feb 07 '22 at 14:49
  • 4
    It is bit sad to consider this question is offtopic on SO. – Jayan Feb 10 '22 at 07:54
  • 1
    As of 2022-03-26, this question is in the ***top 10*** in terms of view rate among [all Stack Overflow questions younger than about 2 years](https://data.stackexchange.com/stackoverflow/query/120907/) (700 days). – Peter Mortensen Mar 26 '22 at 21:05
  • Does [this](https://stackoverflow.com/q/70963985/11942268) answer your question? – stackprotector Aug 01 '22 at 06:47

2 Answers2

132

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).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
bob stinger
  • 1,314
  • 1
  • 4
  • 4
  • 8
    Here's a better one to keep the files tidy (mirrorlist occurs in other places): ```sudo sed -i -e "s|mirrorlist=|#mirrorlist=|g" -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-Linux-*``` – Pavel Tankov Feb 01 '22 at 12:16
  • 1
    In some cases you might want to change the `$contentdir` as well. E.g. for us, we use old ansible version, i had to sort out the `$contentdir` too. For anyone that needs it (combined with the above command): `sudo sed -i -e "s|mirrorlist=|#mirrorlist=|g" -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" -e "s|\$contentdir|centos|g" /etc/yum.repos.d/CentOS-Linux-*` – MrVentzi Feb 01 '22 at 16:34
  • 7
    Converting from CentOS Linux 8 to CentOS Stream 8 is the "official" process (see https://centos.org/centos-stream/#centos-stream-8): `yum --disablerepo '*' --enablerepo extras swap centos-linux-repos centos-stream-repos` then `yum clean all` and `yum makecache` followed by `yum distro-sync` (you may need to use `--allowerasing` in the last step). – scrutari Feb 01 '22 at 19:02
  • For some reason it didn't work for me with http, but only https (maybe yum doesn't follow the redirects?) – Ezra Steinmetz Feb 07 '22 at 13:01
15

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

pirt
  • 1,153
  • 13
  • 21