takafumi blog

日々の勉強メモ

【Vagrant】 VirtualBoxのGuestAdditionsを自動で更新する

環境  Vagrant 1.8.1 VirtualBox 5.0.12

割と有名な事らしいけど、VirtualBoxのゲストでカーネルに更新があったときは、GuestAdditionsを入れなおす必要があるらしい。

VirtualBox共有フォルダ覚書 | dark_greenの日記 | スラド

当然知らず、vagrantVM作って即yum upgradeしたところ、vagrantでのファイル共有ができなくなった。

==> default: Mounting shared folders...                                        
    default: /vagrant =>  C:/Users/<ユーザー名>/VirtualBox VMs/CentOS7.x
Failed to mount folders in Linux guest. This is usually because the "vboxsf" file system is not available. Please verify that the guest additions are properly installed in the guest and can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

とはいえ、ゲスト側で毎度GuestAdition入れなおすのは面倒なので、何か方法がないかとググッてみた。

まさにこれです。

vagrantプラグインを以下のコマンドで導入。

PS> vagrant plugin install vagrant-vbguest

後は普通にvagrant upでOK。

起動時にゲストが自動で更新される。



【追記】

と思ったら罠が。

vagrant-vbguestは常に最新版のGuestAdditionsをインストールしようとする。

つまり、カーネル側も最新になっていないと、GuestAdditionsだけが更新され、結局バージョン違いで問題になる事がある。

vagrant-vbguestプラグインがGuestAdditionsを無効にしてしまう - Qiita

dotless-de/vagrant-vbguest · GitHub

と言う事で、Vagrantfileに通常は更新無効の設定を書いておく

Vagrant::Config.run do |config|
  config.vbguest.auto_update = false
end