フォルダ共有(type: ‘vboxsf’の場合)するには、 VBoxGuestAddtions
というのが必要で、
それを管理してくれるプラグインが vboxguest
。
ちなみに、 type: rsync
では VBoxGuestAddtions は不要。
Contents
試した環境
ホストOS:
- macOS 10.13.6 High Sierra
- Vagrant 2.1.5
- Virtualbox 5.2.18
ゲストOS:
1 2 3 |
[vagrant@localhost ~]$ cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) |
1 2 3 |
[vagrant@localhost ~]$ uname -a Linux localhost.localdomain 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux |
例えばこんな Vagrantfile
1 2 3 4 5 6 7 |
Vagrant.configure("2") do |config| config.vm.box = "centos/7" # same version for Amazon LightSail config.vbguest.auto_update = false config.vm.network "private_network", ip: "192.168.33.10" config.vm.synced_folder "web/html", "/var/www/public" end |
vagrant up
すると フォルダをマウントできないかどでエラーが発生
する、
ただし vagrant ssh はできる状態
になる。
vbguest プラグインを入れる
ホストOSで以下を実行
1 2 |
$ vagrant plugin install vagrant-vbguest |
vagrant vbguest する
ホストOSで以下を実行(エラーが発生する)
1 2 |
$ vagrant vbguest |
エラーの場合
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
[default] No installation found. Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * updates: ftp.iij.ad.jp Package kernel-devel-3.10.0-957.1.3.el7.x86_64 already installed and latest version No package kernel-devel-3.10.0-862.14.4.el7.x86_64 available. Package gcc-4.8.5-36.el7.x86_64 already installed and latest version Package binutils-2.27-34.base.el7.x86_64 already installed and latest version Package 1:make-3.82-23.el7.x86_64 already installed and latest version Package 4:perl-5.16.3-293.el7.x86_64 already installed and latest version Package bzip2-1.0.6-13.el7.x86_64 already installed and latest version Nothing to do Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso Mounting Virtualbox Guest Additions ISO to: /mnt mount: /dev/loop1 is write-protected, mounting read-only Installing Virtualbox Guest Additions 5.2.18 - guest version is unknown Verifying archive integrity... All good. Uncompressing VirtualBox 5.2.18 Guest Additions for Linux........ VirtualBox Guest Additions installer Removing installed version 5.2.18 of VirtualBox Guest Additions... Copying additional installer modules ... Installing additional modules ... VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. This system is currently not set up to build kernel modules. Please install the Linux kernel "header" files matching the current kernel for adding new hardware support to the system. The distribution packages containing the headers are probably: kernel-devel kernel-devel-3.10.0-862.14.4.el7.x86_64 VirtualBox Guest Additions: Starting. VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. This system is currently not set up to build kernel modules. Please install the Linux kernel "header" files matching the current kernel for adding new hardware support to the system. The distribution packages containing the headers are probably: kernel-devel kernel-devel-3.10.0-862.14.4.el7.x86_64 An error occurred during installation of VirtualBox Guest Additions 5.2.18. 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 |
ようするに、「kernelのヘッダーファイルが必要なんだけど存在しないのでVirtualBox Guest Additionsをビルドできまへん」ということらしい。
なので、yumで必要なkernel-develを入れる。
解決策
sshします:
1 2 |
[ホストOS] $ vagrant ssh |
yum で kernel-devel を入れます
1 2 3 4 |
[ゲストOS] $ sudo yum groupinstall -y "Development Tools" [ゲストos] $ sudo yum install -y ftp://ftp.riken.jp/Linux/cern/centos/7/updates/x86_64/Packages/kernel-devel-3.10.0-862.14.4.el7.x86_64.rpm [ゲストos] $ exit |
どのバージョンをいれればよいかは、
ゲストOS上で uname -a
して調べるとよいかも。
再度 vagrant vbguest する
ホストOS上で以下を実行:
1 2 |
$ vagrant vbguest |
VBoxGuestAdditionsのビルド&インストール成功したログ:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
[default] No installation found. Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * updates: ftp.iij.ad.jp Package kernel-devel-3.10.0-957.1.3.el7.x86_64 already installed and latest version Package gcc-4.8.5-36.el7.x86_64 already installed and latest version Package binutils-2.27-34.base.el7.x86_64 already installed and latest version Package 1:make-3.82-23.el7.x86_64 already installed and latest version Package 4:perl-5.16.3-293.el7.x86_64 already installed and latest version Package bzip2-1.0.6-13.el7.x86_64 already installed and latest version Nothing to do Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso Mounting Virtualbox Guest Additions ISO to: /mnt mount: /dev/loop1 is write-protected, mounting read-only Installing Virtualbox Guest Additions 5.2.18 - guest version is unknown Verifying archive integrity... All good. Uncompressing VirtualBox 5.2.18 Guest Additions for Linux........ VirtualBox Guest Additions installer Removing installed version 5.2.18 of VirtualBox Guest Additions... Copying additional installer modules ... Installing additional modules ... VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. VirtualBox Guest Additions: Starting. Redirecting to /bin/systemctl start vboxadd.service Redirecting to /bin/systemctl start vboxadd-service.service Unmounting Virtualbox Guest Additions ISO from: /mnt |
VM起動してみる
vagrant up
または vagrant reload
する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
$ vagrant up ==> default: [vagrant-hostsupdater] Removing hosts ==> default: Attempting graceful shutdown of VM... ==> default: Checking if box 'centos/7' is up to date... ==> default: A newer version of the box 'centos/7' for provider 'virtualbox' is ==> default: available! You currently have version '1809.01'. The latest is version ==> default: '1811.01'. Run `vagrant box update` to update. ==> default: Clearing any previously set forwarded ports... ==> 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: 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: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: [vagrant-hostsupdater] Checking for host entries ==> default: Configuring and enabling network interfaces... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key ==> default: Rsyncing folder: /Users/yokada/vps1/ => /vagrant ==> default: Mounting shared folders... default: /var/www/public => /Users/yokada/web/html |
共有フォルダのマウントに失敗しなくなればok。
NFSでファイル更新したらすぐ反映させる場合の設定
1 2 3 4 5 |
... config.vm.network "private_network", ip: "192.168.33.10" config.vm.synced_folder ".", "/vagrant", type: "nfs" ... |
No comment yet, add your voice below!