LoginSignup
10
4

More than 3 years have passed since last update.

VagrantでCentOS8を起動すると「Error: Unknown repo: 'C*-base'」のエラーが出る

Last updated at Posted at 2020-03-03

概要

Vagrantfileのboxイメージcentos/8を利用してvagrant upするとError: Unknown repo: 'C*-base'のエラーが発生してしまいます。
そこでそのエラーを解消するための紆余曲折をQiita記事にまとめました。

環境

  • Vagrant 2.2.7
  • VirtualBox 6.1

エラーが発生する事象の確認

まずは以下のようにVagrantfileを定義します。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "centos/8"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--memory", "2048"]
  end
end

以下のコマンドで起動するとエラーが発生します。

$vagrant up

....
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

yum install -y kernel-devel-`uname -r` --enablerepo=C*-base --enablerepo=C*-updates

Stdout from the command:



Stderr from the command:

Error: Unknown repo: 'C*-base'

解決方法

ここに記載している方法は、2020/03/03時点で検証したときには、無事に解決した対応手順です。
ただ、この手順が2020/06/11時点では根本解消につながらない手順ということで、別の解決方法を @poyoyon 様にご教示頂きましたので、その内容の通り検証し、エラーが解消できましたので、ここにその方法を記載します。

Vagrantfileに以下の内容の定義をします。
参考:https://github.com/dotless-de/vagrant-vbguest/issues/367#issuecomment-619375784

Vagrantfile
# https://github.com/dotless-de/vagrant-vbguest/issues/367
# https://github.com/dotless-de/vagrant-vbguest/pull/373
if defined?(VagrantVbguest)
  class MyWorkaroundInstallerUntilPR373IsMerged < VagrantVbguest::Installers::CentOS
    protected

    def has_rel_repo?
      unless instance_variable_defined?(:@has_rel_repo)
        rel = release_version
        @has_rel_repo = communicate.test(centos_8? ? 'yum repolist' : "yum repolist --enablerepo=C#{rel}-base --enablerepo=C#{rel}-updates")
      end
      @has_rel_repo
    end

    def centos_8?
      release_version && release_version.to_s.start_with?('8')
    end

    def install_kernel_devel(opts=nil, &block)
      if centos_8?
        communicate.sudo('yum update -y kernel', opts, &block)
        communicate.sudo('yum install -y kernel-devel', opts, &block)
        communicate.sudo('shutdown -r now', opts, &block)

        begin
          sleep 10
        end until @vm.communicate.ready?
      else
        rel = has_rel_repo? ? release_version : '*'
        cmd = "yum install -y kernel-devel-`uname -r` --enablerepo=C#{rel}-base --enablerepo=C#{rel}-updates"
        communicate.sudo(cmd, opts, &block)
      end
    end
  end
end

Vagrant.configure('2') do |config|
  config.vagrant.plugins = ['vagrant-vbguest']
  config.vbguest.auto_update = true
  config.vm.box = 'centos/8'
  config.vm.box_url = 'https://cloud.centos.org/centos/8/x86_64/images/CentOS-8-Vagrant-8.1.1911-20200113.3.x86_64.vagrant-virtualbox.box'

  if defined?(MyWorkaroundInstallerUntilPR373IsMerged)
    config.vbguest.installer = MyWorkaroundInstallerUntilPR373IsMerged
  end
end

あとはvagrant upするだけで正常に起動します。

スクリーンショット 2020-06-11 20.04.20.png

Error: Unknown repo: 'C*-base'のエラーが出ないことが確認できます。

@poyoyon 様ご教示頂きましてありがとうございました。

2020/03/03時点までは有効だった解決手順

@poyoyon 様にご教示頂く前の本記事で記載していた解決方法の手順は以下の内容でした。
2020/03/03時点でこの記事を作った時には、この手順で問題なく動作したのですが、2020/06/11現在では、この方法でもエラーが解消しない状態となってしまいました。

不要な情報ですが、せっかく記事をまとめましたので、この方法が無駄だということが分かるように、残しておこうと思います。

以下のサイトを参考に、上記エラーが出たので対応します。
https://github.com/dotless-de/vagrant-vbguest/issues/367

どうやら CentOS8.1のリリースが行われた影響で、Vagrant boxイメージのcentos/8
まだCentOS 8.0(v1905.1)という状態なのが原因とのこと。
そのため、config.vm.box_urlでCentOS8.1のBOXイメージを指定することで解消するようです。

一度、起動したVagrantを落として、殺して、boxを削除します。

$vagrant halt
$vagrant destroy
$vagrant box remove centos/8

config.vm.box_urlをVagrantfileに追加。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "centos/8"
  config.vm.box_url = "http://cloud.centos.org/centos/8/x86_64/images/CentOS-8-Vagrant-8.1.1911-20200113.3.x86_64.vagrant-virtualbox.box"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--memory", "2048"]
  end
end

これでvagrant upすると正常に起動する。
問題解消。(問題解消しません。。。)

10
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
4