使用Vagrant和VirtualBox,在最新版本的CentOS7 vbox(centos/7 2004.01)中无法挂载的问题

很久没有更新最新版本后,当我执行 vagrant up 命令时,遇到了无法挂载的问题,因此将调查结果记录下来。

环境

nameversionWindows 102004(19041.685)VirtualBox6.1.16Vagrant2.2.14vagrant-vbguest0.28.0

这种现象同样也会在MacOS系统上发生。

现象

当你执行vagrant up命令时,无法进行以下这样的挂载操作。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' version '2004.01' is up to date...
==> default: Setting the name of the VM: centos7_default_1608725302718_27652
==> 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: Running 'pre-boot' VM customizations...
==> 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.
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
Resolving Dependencies
--> Running transaction check
---> Package centos-release.x86_64 0:7-8.2003.0.el7.centos will be updated
---> Package centos-release.x86_64 0:7-9.2009.1.el7.centos will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package             Arch        Version                     Repository    Size
================================================================================
Updating:
 centos-release      x86_64      7-9.2009.1.el7.centos       updates       27 k

Transaction Summary
================================================================================
Upgrade  1 Package

Total download size: 27 k
Downloading packages:
No Presto metadata available for updates

・・・中略・・・

No package kernel-devel-3.10.0-1127.el7.x86_64 available.
Error: Nothing to do
Unmounting Virtualbox Guest Additions ISO from: /mnt
umount: /mnt: not mounted
==> 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!

umount /mnt

Stdout from the command:



Stderr from the command:

umount: /mnt: not mounted

导致这一情况的原因

由于CentOS 7.9已经发布,所以vbox的配置是基于CentOS 7.8的。然而,因为此次升级,无法再从软件仓库中获取与已安装内核版本匹配的kernel-devel软件包。

由于使用了 vbguest,因此无法获取适用于相应版本的 kernel-devel 来更新 VirtualBox Guest Additions,导致更新失败。

处理方法

即使“vagrant up”命令失败,也能够启动并建立SSH连接,所以可以通过以下步骤进行内核更新,以完成该过程。

    1. 运行 “vagrant up” 失败

 

    1. 运行 “vagrant ssh”

 

    1. 运行 “sudo yum -y update kernel”

 

    1. 退出

 

    运行 “vagrant reload –provision”

由于只是临时对策,因此只能自己创建更新过的vbox,或者等待官方vbox更新。

参考:

VBox guest editions fails on CentOS 7 – kernel-devel-3.10.0-862.14.4.el7.x86_64 not found – github.com

Vagrant box fails to install Virtual Box additions after publishing of new CentOS Release – bugs.centos.org

VagrantでCentOSを利用した場合に、ある日突然、VirtualBox Guest Additionsが更新できなくなる原因と対応 – stupiddog.jp

广告
将在 10 秒后关闭
bannerAds