LoginSignup
5
4

More than 5 years have passed since last update.

VagrantでホストPCとフォルダ同期したいのに毎回イライラする

Last updated at Posted at 2018-05-18

毎回 イライラ 時間を取られるので、VBoxGuestAdditionsのインストール方法をまとめます。

あと、ちなみに完全に同期しないで起動時にコピーするだけならVBoxGuestAdditionsは不要です。
👇参照ください。

💭あ、あと未確認ですが、Vagrantで公開しているBOXイメージなら最初からVBoxGuestAdditionsが入っている模様?

[追記:2018/05/08 17:34]

Yoshiaki Asaka さまから上記についてコメントいただきました。

Vagrantで公開しているBOXイメージなら最初からVBoxGuestAdditionsが入っています。
が、ViutalBOXのVersionが、公開されているBOXで使われているVersionと違うと同じような目に会います。
VagrantのVersionが違った時にもあったので、Vagrant Bentoのboxで使われているVagrant,VitualBOXの
Versionと同じ物を使う事をオススメします。

Vagrant Bentoのイメージ使っても根本的な解決にはならないので、バージョンを合わせることが大事とのことですね!
ということで、このあたりを自動でやってくれるのが👇

🔰超重要🔰

コメント欄で tenmyo さまにご指摘頂きましたが、普通は

👆を使ってください。自動が怖い、とかなんか不安とか、昔おかしくなって大変な思いをした、とかない限り確実に便利です!

よく見るエラー

$ vagrant up
(snip)
==> default: Mounting shared folders...
    default: /vagrant_go => /Users/y-amadatsu/go
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_go /vagrant_go

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

ぐぬぬ、。。

ホストのVirtualBoxのバージョンを確認する

$ VBoxManage -v
5.1.28r117968

ゲストにssh接続して、ホストのVirtualBoxバージョンにあったVBoxGuestAdditionsをダウンロードする

http://download.virtualbox.org/virtualbox/ からバージョンが同じISOイメージを選択してダウンロード

[vagrant@localhost ~]$ wget http://download.virtualbox.org/virtualbox/5.1.28/VBoxGuestAdditions_5.1.28.iso

VBoxGuestAdditionsのISOイメージをマウント

[vagrant@localhost ~]$ sudo mkdir /media/VBoxGuestAdditions
[vagrant@localhost ~]$ sudo mount -o loop,ro VBoxGuestAdditions_5.1.28.iso /media/VBoxGuestAdditions

とりあえずインストールしてみる

[vagrant@localhost ~]$ sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run

無事インストールできればOK.

下記のようなエラーが出たら…

(snip)
Installing additional modules ...
vboxadd.sh: Starting the VirtualBox Guest Additions.
Failed to set up service vboxadd, please check the log file
/var/log/VBoxGuestAdditions.log for details.
An error occurred during installation of VirtualBox Guest Additions 5.1.28. Some functionality may not work as intended.
In most cases it is OK that the “Window System drivers” installation failed.
Redirecting to /bin/systemctl start vboxadd.service
Job for vboxadd.service failed because the control process exited with error code. See “systemctl status vboxadd.service” and “journalctl -xe” for details.
Unmounting Virtualbox Guest Additions ISO from: /mnt
——
$ vagrant ssh
Last login: Thu May 17 04:38:28 2018 from 10.0.2.2
[vagrant@localhost ~]$ cat /var/log/VBoxGuestAdditions.log

vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
vboxadd.sh: failed: modprobe vboxguest failed.
[vagrant@localhost ~]$ cat /var/log/vboxadd-install.log
/tmp/vbox.0/Makefile.include.header:112: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.  Stop.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

Error: unable to find the sources of your current Linux kernel. なのでカーネルのソースコードがないですね。ここで注意なのですが、 カーネルバージョンにあったソースコードが必要です!

他の記事では yum update してとか書いてあるものもありますが、簡単に yum update できない案件もありますよね。ここでは、要はとにかくカーネルバージョンに合わせればOKなのです。

なので、まずは

[vagrant@localhost ~]$ uname -r
3.10.0-862.2.3.el7.x86_64

でカーネルバージョンを確認し、

[vagrant@localhost ~]$ sudo yum install -y kernel-devel-3.10.0-862.2.3.el7.x86_64

でOKです。

あとはもう一度インストールをためしてください!

sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run

この記事が役に立てば幸いです!

5
4
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4