头图

记录vagrant使用过程中遇到的问题,会持续补充

Vagrantfile中配置了共享文件,首次vagrant up后失败

原因:
共享文件需要使用VBoxGuestAdditions,而VBoxGuestAdditions安装需要与当前kernel版本匹配,而如果不匹配,则会尝试通过gcc和对应版本的kernel-devel编译安装。如果当前系统没有安装kernel-devel或者gcc则会失败。

解决方法:
手动安装kernel-devel,gcc,详细如下

首次启动
vagrant up

sudo passwd root

# 自动安装VBoxGuestAdditions需要
yum install gcc
yum install kernel-devel-$(uname -r)

关闭vm:
vagrant halt

virtualbox中挂载VBoxGuestAdditions
设置-存储-控制器-添加虚拟光驱-VBoxGuestAdditions.iso

再次启动vm

vagrant up

升级virtualbox后,出现挂载host目录问题

环境

host win10
virtualbox 6.1.22
vm centos 7

问题现象:
之前vm设置过与host的文件共享,Vagrantfile中配置

config.vm.synced_folder "D:/work/vagrant/data", "/vagrant_data"

virtualbox从6.1.16升级到6.1.22, 升级后vagrant up显示如下问题

==> pg12: Checking for guest additions in VM...
==> pg12: Setting hostname...
==> pg12: Configuring and enabling network interfaces...
==> pg12: Mounting shared folders...
    pg12: /vagrant => D:/work/vagrant/vms/pg12
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: Invalid argument

解决方法:
ssh登陆vm,将vagrant(vagrant为vm默认登陆用户,根据实际情况配置)添加到vboxsf,vboxusers 组

sudo groupadd vboxusers
usermod -G vboxusers vagrant
usermod -G vboxsf vagrant

vm关机,再vagrant up启动后即可

[vagrant@pg12 ~]$ groups
vagrant vboxusers

检查共享目录挂载成功

[vagrant@pg12 ~]$ ls /vagrant_data/
a b c.sh

问题现象:

vagrant ssh-config  > ssh-config  && ssh -F ssh-config myvm

Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

解决方法:

修改vagrant-ssh

PasswordAuthentication yes

问题现象:

Vagrantfile 已经设置了hostname但是hostname没有变更成功
  config.vm.hostname = "dw-mst"
  config.vm.define "dw-mst"

[vagrant@centos8-pg12 ~]$

解决方法:
登陆vm后内部更改hostname

# 修改hostname
hostnamectl set-hostname dw-mst

# 修改 /etc/hosts
- 127.0.1.1 centos8-pg12
+ 127.0.1.1 dw-mst dw-mst

# 停止vm
vagrant.exe halt

# 启动vm
vagrant.exe up

# ssh vm
ssh -F vagrant-ssh dw-mst
[vagrant@dw-mst ~]$

问题现象:

升级virtualbox 7后,vagrant报告不兼容

解决方法:

重新到vagrant官网下载最新版本安装

安装后可以兼容

问题现象:
升级vagrant后,启动box失败,看起来是之前安装的plugin不兼容

Vagrant failed to initialize at a very early stage:

The plugins failed to initialize correctly. This may be due to manual
modifications made within the Vagrant home directory. Vagrant can
attempt to automatically correct this issue by running:

  vagrant plugin repair

If Vagrant was recently updated, this error may be due to incompatible
versions of dependencies. To fix this problem please remove and re-install
all plugins. Vagrant can attempt to do this automatically by running:

  vagrant plugin expunge --reinstall

Or you may want to try updating the installed plugins to their latest
versions:

  vagrant plugin update

Error message given during initialization: Unable to resolve dependency: user requested 'micromachine (= 3.0.0)'

解决方法:

重新到vagrant官网下载最新版本安装

vagrant plugin repair
vagrant plugin expunge --reinstall

问题现象

vagrant plugin install vagrant-disksize --plugin-source https://rubygems.org/
Installing the 'vagrant-disksize' plugin. This can take a few minutes...
ERROR:  SSL verification error at depth 3: unable to get local issuer certificate (20)
ERROR:  You must add /C=US/O=Starfield Technologies, Inc./OU=Starfield Class 2 Certification Authority to your local trusted store
Vagrant failed to load a configured plugin source. This can be caused
by a variety of issues including: transient connectivity issues, proxy
filtering rejecting access to a configured plugin source, or a configured
plugin source not responding correctly. Please review the error message
below to help resolve the issue:

  SSL_connect SYSCALL returned=5 errno=0 peeraddr=[2600:9000:2250:9600:11:a45a:acc0:93a1]:443 state=error: certificate verify failed (https://gems.hashicorp.com/specs.4.8.gz)

Source: https://gems.hashicorp.com/                                                                   

解决方法:

https://discuss.hashicorp.com/t/vagrant-2-3-5-unable-to-insta...
下面有一个回复的办法

set SSL_CERT_FILE=C:\HashiCorp\Vagrant\embedded\gems\gems\httpclient-2.8.3\lib\httpclient\cacert.pem

vagrant plugin install --plugin-clean-sources --plugin-source https://rubygems.org vagrant-disksize

// 很多网上的办法都无效,包括
// set VAGRANT_NO_SSL_VERIFY=true

问题现象
安装最新vagrant,virtualbox后 vagrant up失败

vagrant up
Bringing machine 'dw1-seg2' up with 'virtualbox' provider...
==> dw1-seg2: Clearing any previously set network interfaces...
A host only network interface you're attempting to configure via DHCP
already has a conflicting host only adapter with DHCP enabled. The
DHCP on this adapter is incompatible with the DHCP settings. Two
host only network interfaces are not allowed to overlap, and each
host only network interface can have only one DHCP server. Please
reconfigure your host only network or remove the virtual machine
using the other host only network.
 

解决方法:
virtualbox中删除没有使用的网卡

管理-工具-网络管理器
重启后,可以启动,但是之前连接的dhcp server可能会被更改,导致host-only 的IP变化。即使调整了对应的网口也不行。

问题现象
GuestAdditions版本与virtualbox不匹配,一般发生在升级了vagrant,virtualbox软件后。vagrant可能会尝试自动升级GuestAdditions,也可能不会。

vagrant up
[dw1-cn] GuestAdditions versions on your host (7.0.10) and guest (6.1.22) do not match.

解决方法:
重新安装GuestAdditions,但不一定能解决,可能需要重新安装vagrant、virtualbox,但是重新安装可能又会出现其它兼容性问题。

重新安装GuestAdditions的方法
# 前提需要已经安装gcc,make, perl
sudo mount /dev/cdrom /mnt
cd /mnt
sudo ./VBoxLinuxAdditions.run
  • TBD

问题现象:

特别是初次vagrant up,报告VirtualBox Guest Additions安装失败。这会导致与host共享目录等功能不可用。这里的原因是安装Guest Additions时,缺少Kernel headers。

VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel
5.14.0-284.25.1.el9_2.x86_64. Please install them and execute
  /sbin/rcvboxadd setup
ValueError: File context for /opt/VBoxGuestAdditions-7.0.10/other/mount.vboxsf already defined

解决方法:
安装kernel-devel
重新安装GuestAdditions,但不一定能解决,可能需要重新安装vagrant、virtualbox,但是重新安装可能又会出现其它兼容性问题。

这里说本质上不需要更新kernel,只需要安装你当前kernel对应的kernel-devel,如果yum源中没有该版本,可以到下面网站下载对应的rpm,直接通过yum install xxxx.rpm安装即可

https://vault.centos.org/7.7.1908/os/x86_64/Packages/
https://zhuanlan.zhihu.com/p/576669382?utm_id=0

// 尝试安装对应的kernel-devel
yum install kernel-devel-$(uname -r)

// 如果安装源中没有该版本,可以升级kernel到最新版本,再安装对应版本的devel
yum list available | grep kernel-devel
yum update kernel
yum install kernel-devel

// 可能需要首先配置下yum的国内镜像
如[更换yum源](https://www.cnblogs.com/wswind/p/15469768.html)


// 安装完成后,重启vm,vagrant up的时候会自动尝试安装Guest Additions
// 如果没有自动安装,可以手动安装

// virtualbox的gui中执行安装addons,进入vm执行对应的安装脚本
mount /dev/cdrom /mnt
cd /mnt/
./VBoxLinuxAdditions.run

参考资料

network config


黑暗森林
12 声望2 粉丝

弱小和无知不是生存的障碍,傲慢才是!


« 上一篇
vscode 相关
下一篇 »
linux 相关