表題の通り。先日の下記エントリの続きである。
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:~$
以上。
■ 関連