web-technical-blog

web開発に関する技術メモ

VagrantのGuest GuestAdditionsについて

共有フォルダを作成したいときに、 「Guest Additions Version」と「VirtualBox Version」が違うとエラーが発生する

環境

>vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Installed the plugin 'vagrant-vbguest (0.16.0)'!
  • VagrantFile
#
# Note: set environment vars "HOSTNAME" and "IP", or replace the below
#

Vagrant.configure("2") do |config|
  config.vm.box = "bento/centos-7.3"
  config.vm.hostname = "redash"
  config.ssh.insert_key = false
  config.vm.network "private_network", ip: "192.168.56.203"
  config.vbguest.auto_update = false
  config.vbguest.no_remote = true
  config.vm.provider "virtualbox" do |vb|
    vb.name = config.vm.hostname
    vb.memory = "2048"
    vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    vb.customize ["setextradata", :id, "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled", 0]
    vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
  end
  config.vm.provision "shell", inline: <<-SHELL
    sudo systemctl restart network.service
    sudo yum -y update
    sudo yum install -y zsh vim tree telnet dstat git tig
    sudo gpasswd -a vagrant vboxsf
  SHELL
end

Guest Additionsのアップデートと再起動

>vagrant vbguest
>vagrant reload
>vagrant vbguest --status
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.1.26
VBoxService inside the vm claims: 5.2.12
Going on, assuming VBoxService is correct...
[default] GuestAdditions 5.2.12 running --- OK.
>vagrant halt

virtualbox側で、共有フォルダの設定を正しくする(不要かもしれないが...)

  • [設定] -> [共有フォルダ] -> 自動マウントの設定

  • vagrantの起動

>vagrant up

上記で起動しないと、共有フォルダは設定されない

参考URL

https://qiita.com/isaoshimizu/items/e217008b8f6e79eccc85