Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

CentOS 8 - installing Guest additions fails #367

Closed
mhemani-reach opened this issue Jan 31, 2020 · 16 comments · Fixed by #373
Closed

CentOS 8 - installing Guest additions fails #367

mhemani-reach opened this issue Jan 31, 2020 · 16 comments · Fixed by #373

Comments

@mhemani-reach
Copy link

mhemani-reach commented Jan 31, 2020

Plugin version: vagrant-vbguest (0.23.0, global)
Vagrant version: Installed Version: 2.2.7
VirtualBox version: 6.1.2r135662

VagrantFile

Vagrant.configure("2") do |config|
  config.vm.box = "centos/8"
  config.vm.synced_folder ".", "/vagrant", type: "nfs"
  config.vm.network "private_network", type: "dhcp"
  config.ssh.forward_agent = "false"
  config.ssh.keys_only = "true"
end

Output:

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'centos/8' version '1905.1' is up to date...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
[default] No Virtualbox Guest Additions installation found.
Last metadata expiration check: 0:00:01 ago on Fri 31 Jan 2020 03:07:39 AM UTC.
Package centos-release-8.0-0.1905.0.9.el8.x86_64 is already installed.
Dependencies resolved.
================================================================================
 Package               Arch         Version                  Repository    Size
================================================================================
Upgrading:
 centos-release        x86_64       8.1-1.1911.0.8.el8       BaseOS        21 k
Installing dependencies:
 centos-gpg-keys       noarch       8.1-1.1911.0.8.el8       BaseOS        11 k
 centos-repos          x86_64       8.1-1.1911.0.8.el8       BaseOS        12 k

Transaction Summary
================================================================================
Install  2 Packages
Upgrade  1 Package

Total download size: 44 k
Downloading Packages:
(1/3): centos-gpg-keys-8.1-1.1911.0.8.el8.noarc 9.2 kB/s |  11 kB     00:01    
(2/3): centos-repos-8.1-1.1911.0.8.el8.x86_64.r 9.9 kB/s |  12 kB     00:01    
(3/3): centos-release-8.1-1.1911.0.8.el8.x86_64  16 kB/s |  21 kB     00:01    
--------------------------------------------------------------------------------
Total                                            17 kB/s |  44 kB     00:02     
warning: /var/cache/dnf/BaseOS-31c79d9833c65cf7/packages/centos-gpg-keys-8.1-1.1911.0.8.el8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS-8 - Base                                 791 kB/s | 1.6 kB     00:00    
Importing GPG key 0x8483C65D:
 Userid     : "CentOS (CentOS Official Signing Key) <[email protected]>"
 Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Running scriptlet: centos-gpg-keys-8.1-1.1911.0.8.el8.noarch              1/1 
  Installing       : centos-gpg-keys-8.1-1.1911.0.8.el8.noarch              1/4 
  Installing       : centos-repos-8.1-1.1911.0.8.el8.x86_64                 2/4 
  Upgrading        : centos-release-8.1-1.1911.0.8.el8.x86_64               3/4 
  Cleanup          : centos-release-8.0-0.1905.0.9.el8.x86_64               4/4 
  Running scriptlet: centos-release-8.0-0.1905.0.9.el8.x86_64               4/4 
  Verifying        : centos-gpg-keys-8.1-1.1911.0.8.el8.noarch              1/4 
  Verifying        : centos-repos-8.1-1.1911.0.8.el8.x86_64                 2/4 
  Verifying        : centos-release-8.1-1.1911.0.8.el8.x86_64               3/4 
  Verifying        : centos-release-8.0-0.1905.0.9.el8.x86_64               4/4 

Upgraded:
  centos-release-8.1-1.1911.0.8.el8.x86_64                                      

Installed:
  centos-gpg-keys-8.1-1.1911.0.8.el8.noarch                                     
  centos-repos-8.1-1.1911.0.8.el8.x86_64                                        

Complete!
Error: Unknown repo: 'C*-base'
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default: 
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
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'

Also since this is CentOS 8, isn't the preferred OS package manager suppose to be dnf?

@tmiller02
Copy link

tmiller02 commented Feb 3, 2020

I've also encountered this issue.

It seems to be related to the recent release of CentOS 8.1. The Vagrant box installed from centos/8 is still CentOS 8.0 (version 1905.1), which seems to cause the install of the packages required for this plugin to fail.

I've found that removing the existing CentOS 8.0 box and configuring a Vagrantfile explicitly with the url to the CentOS 8.1 Vagrant box seems to work around this issue. ie

$  vagrant box remove centos/8
Removing box 'centos/8' (v1905.1) with provider 'virtualbox'...

and then in my Vagrantfile:

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"

Unlike with CentOS 7 releases, the CentOS-Vault.repo file seems to be empty in CentOS 8.1, hence there are no matching repos for --enablerepo=C*-base --enablerepo=C*-updates.

[root@localhost yum.repos.d]# cat /etc/centos-release
CentOS Linux release 8.1.1911 (Core) 
[root@localhost yum.repos.d]# cat /etc/yum.repos.d/CentOS-Vault.repo 
# CentOS Vault contains rpms from older releases in the CentOS-8
# tree.

[root@localhost yum.repos.d]# 

Using the CentOS 8.1 .box file sidesteps this issue since has_kernel_devel_info will be true and the above yum command which uses --enablerepo=C*-base --enablerepo=C*-updates will not be called.

@pedrofurtado
Copy link
Contributor

pedrofurtado commented Feb 6, 2020

Any news about this issue? @dotless-de @fnordfish 👍

@pedrofurtado
Copy link
Contributor

Where is the repo where the vagrant images of CentOS is generated? Because today the latest vagrant image available is 8.0 ( https://app.vagrantup.com/centos/boxes/8 ).

Is it possible to provide centos 8.1 vagrant image? Is there any repo that I can create a issue for this?

Thank you so much! 👍 🥇

@pedrofurtado
Copy link
Contributor

pedrofurtado commented Feb 6, 2020

I created an issue in the repo: CentOS/sig-cloud-instance-build#168

@KylePeterDavies
Copy link

Same issue.

@choonge
Copy link

choonge commented Mar 23, 2020

Using the CentOS 8.1 image doesn't work here anymore either. It looks like older kernel-devel versions cannot be installed. I've managed to monkey patch it in my Vagrantfile:

VAGRANTFILE_API_VERSION = '2'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define 'centos8', autostart: false do |centos8|
    centos8.vm.hostname = 'centos8'
    centos8.vm.box = 'centos/8'

    # Monkey patch for https://github.com/dotless-de/vagrant-vbguest/issues/367
    class Foo < VagrantVbguest::Installers::CentOS
      def has_rel_repo?
        unless instance_variable_defined?(:@has_rel_repo)
          rel = release_version
          @has_rel_repo = communicate.test("yum repolist")
        end
        @has_rel_repo
      end

      def install_kernel_devel(opts=nil, &block)
        cmd = "yum update kernel -y"
        communicate.sudo(cmd, opts, &block)

        cmd = "yum install -y kernel-devel"
        communicate.sudo(cmd, opts, &block)

        cmd = "shutdown -r now"
        communicate.sudo(cmd, opts, &block)

        begin
          sleep 5
        end until @vm.communicate.ready?
      end
    end
    centos8.vbguest.installer = Foo

So the idea is:

  • remove the --enablerepo arguments
  • grab latest versions of kernel and kernel-devel, then reboot the VM and wait for it to come back up

This puts the fresh CentOS 8 vm in a state where the guest additions can be succesfully built.

@dsofeir
Copy link

dsofeir commented Apr 7, 2020

I've also encountered this issue.

It seems to be related to the recent release of CentOS 8.1. The Vagrant box installed from centos/8 is still CentOS 8.0 (version 1905.1), which seems to cause the install of the packages required for this plugin to fail.

I've found that removing the existing CentOS 8.0 box and configuring a Vagrantfile explicitly with the url to the CentOS 8.1 Vagrant box seems to work around this issue. ie

$  vagrant box remove centos/8
Removing box 'centos/8' (v1905.1) with provider 'virtualbox'...

and then in my Vagrantfile:

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"

Unlike with CentOS 7 releases, the CentOS-Vault.repo file seems to be empty in CentOS 8.1, hence there are no matching repos for --enablerepo=C*-base --enablerepo=C*-updates.

[root@localhost yum.repos.d]# cat /etc/centos-release
CentOS Linux release 8.1.1911 (Core) 
[root@localhost yum.repos.d]# cat /etc/yum.repos.d/CentOS-Vault.repo 
# CentOS Vault contains rpms from older releases in the CentOS-8
# tree.

[root@localhost yum.repos.d]# 

Using the CentOS 8.1 .box file sidesteps this issue since has_kernel_devel_info will be true and the above yum command which uses --enablerepo=C*-base --enablerepo=C*-updates will not be called.

This solution worked for me.

Should the official vagrant box not be updated to 8.1 as suggested by @pedrofurtado?

@kvaradhan3
Copy link

kvaradhan3 commented Apr 24, 2020

Just another datapoint: Specifying the box url did not work for me:

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.provider "virtualbox" do |vb|
    vb.memory = "4096"
  end
end

Some output traces below:

Complete!
Error: Unknown repo: 'C*-base'
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
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'

(Kannan--Shanthis-Home-iMac) Centos7 ➜ vagrant ssh                                                       13:46:48
[vagrant@localhost ~]$ cat /etc/centos-release
CentOS Linux release 8.1.1911 (Core)```

@choonge
Copy link

choonge commented Apr 25, 2020

Using the new box is a work-around which will work temporarily at best. The goal of that work-around is to have up-to-date kernel and kernel-devel packages, which prevents any attempts to install kernel-devel packages.

In the end, the real issue is that the C*- repos simply don't exist on CentOS 8. The best fix would be to prevent using those commandline arguments at all when CentOS 8 is detected.

Additionally, it seems that kernel-devel packages for the specific kernel version are not always available in the repos if the kernel version in the box is outdated.

So imho the real fix should be to:

  1. dont try to reference C*-repos if centos 8 is detected
  2. update kernel to latest version, install accompanying kernel-devel packages for that version, and reboot the VM to activate that kernel version

In the resulting state, the guest additions will be able to compile.

@pedrofurtado
Copy link
Contributor

Everyone, I've created a PR with the suggestion proposed by @choonge 🤝 Happy to see this merged as soon as possible 🎉

@pedrofurtado
Copy link
Contributor

The final workaround, until the PR be merged and released, is to write the vagrantfile with code like that:

# 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

@immo-huneke-zuhlke
Copy link

Many thanks for this careful analysis and workaround. I am pleased to report that it seems to have worked for me.

@pedrofurtado
Copy link
Contributor

pedrofurtado commented Apr 27, 2020

Guys, any help (with tests in your applications, code review, and so on ...) in that PR will be appreciated🎉 : #373

@kvaradhan3
Copy link

@pedrofurtado When is has_rel_repo? invoked? When I run it, I dont see it.

Also, it looks like the box_url does not need to be specified any longer.

@shockinghobby
Copy link

shockinghobby commented May 15, 2020

Neither of these commits are in master or 0.24 tag now.

@yildizib
Copy link

Using the CentOS 8.1 image doesn't work here anymore either. It looks like older kernel-devel versions cannot be installed. I've managed to monkey patch it in my Vagrantfile:

VAGRANTFILE_API_VERSION = '2'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define 'centos8', autostart: false do |centos8|
    centos8.vm.hostname = 'centos8'
    centos8.vm.box = 'centos/8'

    # Monkey patch for https://github.com/dotless-de/vagrant-vbguest/issues/367
    class Foo < VagrantVbguest::Installers::CentOS
      def has_rel_repo?
        unless instance_variable_defined?(:@has_rel_repo)
          rel = release_version
          @has_rel_repo = communicate.test("yum repolist")
        end
        @has_rel_repo
      end

      def install_kernel_devel(opts=nil, &block)
        cmd = "yum update kernel -y"
        communicate.sudo(cmd, opts, &block)

        cmd = "yum install -y kernel-devel"
        communicate.sudo(cmd, opts, &block)

        cmd = "shutdown -r now"
        communicate.sudo(cmd, opts, &block)

        begin
          sleep 5
        end until @vm.communicate.ready?
      end
    end
    centos8.vbguest.installer = Foo

So the idea is:

  • remove the --enablerepo arguments
  • grab latest versions of kernel and kernel-devel, then reboot the VM and wait for it to come back up

This puts the fresh CentOS 8 vm in a state where the guest additions can be succesfully built.

works for me

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants