/vagrantのマウントに失敗 – その2

表題の通り。また最近使っていて同じ現象(?)に当たったので、以前にも書いたのと似たようなものだけど書いておく。

■ 環境

  • Vagrant 1.9.1
  • Mac OSX El Capitan

■ bento/centos-6.7

CentOS 6“のVMを使いたくて下記boxを利用している。

Vagrant box bento/centos-6.7 | Atlas by HashiCorp
https://atlas.hashicorp.com/bento/boxes/centos-6.7

このboxを起動すると、いつも下記のような黄色いメッセージと最後に赤いメッセージで起動に失敗となってしまう。複数のVMを起動しようとしてるときは、最初のVMで失敗してしまうので後続が起動してくれない。

$ vagrant up centos67
  :
[cent67] GuestAdditions versions on your host (5.1.16) and guest (5.0.20) do not match.
  :
Installing Virtualbox Guest Additions 5.1.16 - guest version is 5.0.20
  :
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.0.20
VBoxService inside the vm claims: 5.1.16
Going on, assuming VBoxService is correct...
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.0.20
VBoxService inside the vm claims: 5.1.16
Going on, assuming VBoxService is correct...
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.0.20
VBoxService inside the vm claims: 5.1.16
Going on, assuming VBoxService is correct...
Restarting VM to apply changes...
  :
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=500,gid=500 vagrant /vagrant

The error output from the command was:

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

$

/vagrant“はもちろんマウントできていない。VM側の”Guest Addition“が古いのが原因のようである。しかし”bento/centos-6.7“のversionはこれ以上新しいものはリリースされていない。

$ vagrant box list
bento/centos-6.7 (virtualbox, 2.2.7)
centos/7         (virtualbox, 1608.02)
ubuntu/trusty64  (virtualbox, 20170222.0.0)
ubuntu/xenial64  (virtualbox, 20170331.0.0)
$

状況を確認する。プラグイン。

$ vagrant plugin list
vagrant-share (1.1.6, system)
vagrant-vbguest (0.13.0)
$

vbguest“のプラグインが新しくなっていないか?と思い確認。

$ vagrant plugin update vagrant-vbguest
Updating plugins: vagrant-vbguest. This may take a few minutes...
All plugins are up to date.
$

`update`対象は無いようである。”vbguest“の状態を確認する。

$ vagrant vbguest cent67 --status
[cent67] No installation found.
$
$ vagrant vbguest cent67
[cent67] No installation found.
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: mirror.qoxy.com
 * updates: mirror.vodien.com
No package kernel-devel-2.6.32-573.el6.x86_64 available.
Package gcc-4.4.7-18.el6.x86_64 already installed and latest version
Package binutils-2.20.51.0.2-5.47.el6_9.1.x86_64 already installed and latest version
Package 1:make-3.81-23.el6.x86_64 already installed and latest version
Package 4:perl-5.10.1-144.el6.x86_64 already installed and latest version
Package bzip2-1.0.5-7.el6_0.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
Installing Virtualbox Guest Additions 5.1.16 - guest version is unknown
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.16 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Removing installed version 5.1.16 of VirtualBox Guest Additions...
vboxadd.sh: Stopping VirtualBox Additions.
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Building Guest Additions kernel modules.
Failed to set up service vboxadd, please check the log file
/var/log/VBoxGuestAdditions.log for details.

$
$ vagrant vbguest cent67 --status
[cent67] No installation found.
$

状況は変わらない。以前のエントリの通りログインして操作することにする。

$ vagrant ssh cent67
[vagrant@cent67 ~]$ sudo yum update

VMを再起動してみる。

$ vagrant reload cent67
  :
[cent67] No installation found.
  :
Installing Virtualbox Guest Additions 5.1.16 - guest version is unknown
  :
$

気になるメッセージはまた表示されているが、マウントはしてくれた。

一度起動して対応して…と、最初の起動時からは解決できていないので根本解決にはなっていないが仕方が無い。

以上。

■ 関連

VirtualBoxの/vagrantがマウントに失敗

Vagrantのアップグレードとプラグイン

表題の通り。

■ 環境

  • Vagrant 1.8.5 -> 1.9.1
  • Mac OSX El Capitan

■ version

現状を確認したところ、下記のようにあったので`upgrade`した。

$ vagrant version
Installed Version: 1.8.5
Latest Version: 1.9.1

To upgrade to the latest version, visit the downloads page and
download and install the latest version of Vagrant from the URL
below:

https://www.vagrantup.com/downloads.html

If you're curious what changed in the latest release, view the
CHANGELOG below:

https://github.com/mitchellh/vagrant/blob/v1.9.1/CHANGELOG.md
$

■ plugin

`upgrade`終了後に再度確認してみたところ、下記のようにエラーが発生。

$ vagrant version
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

Error message given during initialization: Unable to resolve dependency: user requested 'vagrant-vbguest (> 0)'
$

使用しているプラグイン”vagrant-vbguest“が古いようである。表記されていたコマンドをそのまま実行した。

$ vagrant plugin expunge --reinstall

This command permanently deletes all currently installed user plugins. It
should only be used when a repair command is unable to properly fix the
system.

Continue? [Y/N]:Y

All user installed plugins have been removed from this Vagrant environment!

Vagrant will now attempt to reinstall user plugins that were removed.
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Fetching: micromachine-2.0.0.gem (100%)
Fetching: vagrant-vbguest-0.13.0.gem (100%)
Installed the plugin 'vagrant-vbguest (0.13.0)'!
$

これで正常に使用できるようになったようである。

以上。

Vagrantfileを最小で初期化

表題の通り。知らなかったのでメモ。

■ 環境

  • Vagrant 1.8.5
  • Mac OSX El Capitan

■ vagrant init

最初に`Vagrantfile`を作成するときは、いつも下記のように実行していた。

$ vagrant init centos/7

その後、`Vagrantfile`の中身で不要なコメントを消して…と。この不要な設定例を毎回消しているのが面倒だなと思っていたのだが、どうやらこれを最初から出力させないようにできるらしい。

$ vagrant init -m centos/7

上記で作成された`Vagrantfile`は下記の通りである。

$ cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
end
$

こざっぱりした。

`-m`は`–minimal`の短い形式である。

以上。

VagrantでDocker Provisioner

表題の通り。今までにもそういった環境は何度も試していたのだが、設定でちょっと気になるものを知ったので試してみる。

■ 環境

  • CentOS 7
  • Vagrant 1.8.4
  • Mac OSX El Capitan

■ Vagrant

下記のVagrantfileで`vagrant up`している。

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
end

このまま起動した時点ではもちろんDockerが動いているはずがない。

$ vagrant ssh
Last login: Thu Jul 21 10:12:16 2016 from 10.0.2.2
[vagrant@localhost ~]$ which docker
/usr/bin/which: no docker in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vagrant/.local/bin:/home/vagrant/bin)
[vagrant@localhost ~]$
[vagrant@localhost ~]$ ps -ef | grep docker
vagrant   1442  1422  0 10:12 pts/0    00:00:00 grep --color=auto docker
[vagrant@localhost ~]$

続いて下記のようにVagrantfileに追記する。

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.provision "docker"
end

これは下記ドキュメントにあった。

Docker Provisioner
https://www.vagrantup.com/docs/provisioning/docker.html

VMに対して`provision`を実行する。

$ vagrant provision
==> default: Running provisioner: docker...
    default: Installing Docker onto machine...
$

動作しているか確認。

$ vagrant ssh
Last login: Thu Jul 21 10:22:24 2016 from 10.0.2.2
[vagrant@localhost ~]$ which docker
/usr/bin/docker
[vagrant@localhost ~]$
[vagrant@localhost ~]$ ps -ef | grep docker
root      2350     1  0 10:22 ?        00:00:00 /usr/bin/docker daemon -H fd://
root      2353  2350  0 10:22 ?        00:00:00 docker-containerd -l /var/run/docker/libcontainerd/docker-containerd.sock --runtime docker-runc --start-timeout 2m
vagrant   2900  2878  0 10:23 pts/0    00:00:00 grep --color=auto docker
[vagrant@localhost ~]$
[vagrant@localhost ~]$ docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 1.11.2
Storage Driver: devicemapper
 Pool Name: docker-253:0-525826-pool
 Pool Blocksize: 65.54 kB
 Base Device Size: 10.74 GB
 Backing Filesystem: xfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 11.8 MB
 Data Space Total: 107.4 GB
 Data Space Available: 38.38 GB
 Metadata Space Used: 581.6 kB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.147 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Deferred Deletion Enabled: false
 Deferred Deleted Device Count: 0
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 WARNING: Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.107-RHEL7 (2016-06-09)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: null host bridge
Kernel Version: 3.10.0-327.22.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 489 MiB
Name: localhost.localdomain
ID: 4E6P:5GS2:6A5R:JBF7:4IIJ:RYGN:WUE2:2ND2:V2KS:D2CL:FWCG:FTT7
Docker Root Dir: /var/lib/docker
Debug mode (client): false
Debug mode (server): false
Registry: https://index.docker.io/v1/
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
[vagrant@localhost ~]$

なるほど。自身でわざわざインストールする必要がないのか。これは確かに便利そうである。が、Docker for Macや`docker-machine`でほとんど十分であろう。その他の実験的な環境を作る時には重宝しそうなので覚えておくことにしよう。

以上。

■ 関連

作成したVagrantBoxからvagrant up

表題の通り。先日の下記エントリの続きである。

VirtualBoxのVMからVagrantBoxを作成

■ 環境

  • Vagrant 1.8.1
  • Mac OSX El Capitan

■ alpine-3.4.1.box

先日のエントリの通り、下記boxファイルが作成されている。

$ ls -l
-rw-r--r--  1 withsin  staff  144878996  7  5 19:09 alpine-3.4.1.box
$

このboxファイルをvagrantで使用できるようにする。まずはboxに追加である。

$ vagrant box add withsin/alpine alpine-3.4.1.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'withsin/alpine' (v0) for provider:
    box: Unpacking necessary files from: file:///Users/withsin/work/alpine/alpine-3.4.1.box
==> box: Successfully added box 'withsin/alpine' (v0) for 'virtualbox'!
$

withsin/alpine“という名前で追加した。下記の通り確認できる。

$ vagrant box list
centos/7                  (virtualbox, 1603.01)
centos/atomic-host        (virtualbox, 7.20151101)
maier/alpine-3.3.1-x86_64 (virtualbox, 1.0.0)
ubuntu/vivid64            (virtualbox, 20160128.0.0)
withsin/alpine            (virtualbox, 0)
$

versionは特に指定していないので”0″になっているのであろう。この追加したboxで起動できるかを確認する。

■ vagrant up

$ vagrant init withsin/alpine
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
$
$ ls
Vagrantfile
$
$ cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "withsin/alpine"
  :
$

`init`は問題なくできたので、実際に`up`してみる。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'withsin/alpine'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1467701682504_52757
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> 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: Warning: Remote connection disconnect. Retrying...
The configured shell (config.ssh.shell) is invalid and unable
to properly execute commands. The most common cause for this is
using a shell that is unavailable on the system. Please verify
you're using the full path to the shell and that the shell is
executable by the SSH user.
$

エラーとなった。SSHでログインできないようである。VMは起動しているので停止させておく。

$ vagrant status
Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.
$
$$ vagrant destroy
    default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
$

SSH SETTINGS
https://www.vagrantup.com/docs/vagrantfile/ssh_settings.html

上記ドキュメントを確認すると、デフォルトでは”bash”が適用されるようだ。”Alpine Linux“のデフォルトシェルは”ash“であったはず。”bash“はインストールしなければいけなかったはず。というわけで”sh“を指定することにする。

config.ssh.shell = "sh"

上記をVagrantfileに記述して再度`up`する。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'withsin/alpine'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1467702010684_99055
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> 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: Warning: Remote connection disconnect. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Mounting shared folders...
    default: /vagrant => /Users/withsin/work/test
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

The error output from the last command was:

mount: mounting vagrant on /vagrant failed: No such device

$

起動はしたが、”/vagrant“をマウントできないようだ。これは以前も見た記憶がある。今回はGuestAdditionsも入れていないので確かに起こりそうだ。一旦は今回は後回しにする。

$ vagrant ssh
Welcome to Alpine!
localhost:~$ cat /etc/alpine-release
3.4.1
localhost:~$

以上。

■ 関連