ようへいの日々精進XP

よかろうもん

古いバージョンの VirtualBox で作った VM が vagrant up で起動しなくなった際の対処方法(VirtualBox をコマンドラインで扱うメモ)

tl;dr

以下のようなエラーが出てしまい仮想マシンが起動しない。ガビーン。

Vagrant has detected that you have a version of VirtualBox installed
that is not supported. Please install one of the supported versions
listed below to use Vagrant:

4.0, 4.1, 4.2, 4.3

きっと Docker Machine をインストールした際に最新の VirtualBox をインストールしてしまったためだろう。ということで、vagrant 経由での仮想マシン起動は諦めて VirtualBox 単体で仮想マシン起動を模索した。


参考

qiita.com

ヘッドレスで仮想マシンを起動する方法を参考にさせて頂きました。

ありがとうございます。


手順

仮想マシンの一覧を取得する

$ VBoxManage list vms

以下のように出力される。

(snip)

"ubuntu-dev_ubuntu_dev_1435925046744_48053" {cc121867-1e41-43e6-adc8-83e1f471d9fd}
"coreos-vagrant_core-01_1439212749090_55574" {7c403882-414f-46c9-b126-6cb3b0150530}
"coreos-vagrant_core-02_1439212777619_19675" {b684b63c-d149-4b63-a854-937e545bffc3}
"coreos-vagrant_core-03_1439212806731_29336" {730dc2c6-fda0-4459-a201-25dec9034e52}
"default" {f0914457-b68c-49d6-a5ec-e4d3b47b503b}
"swarm-master" {37d2d6b9-4c09-4bcf-8fa9-fccdb3c64a30}
"swarm-node01" {6637a089-9b55-446a-a1ff-cc4911c7e320}
"swarm-node02" {f418bac5-93b3-4ca2-aab9-2a24572ac336}

今回は "ubuntu-dev_ubuntu_dev_1435925046744_48053" を起動したいので名前 ubuntu-dev_ubuntu_dev_1435925046744_48053 又は UID となる cc121867-1e41-43e6-adc8-83e1f471d9fd を控えておく。

仮想マシンの起動

以下のように startvm オプションに UID 又は名前を指定して起動する。

$ VBoxManage startvm cc121867-1e41-43e6-adc8-83e1f471d9fd

以下のように出力される。

Waiting for VM "cc121867-1e41-43e6-adc8-83e1f471d9fd" to power on...
VM "cc121867-1e41-43e6-adc8-83e1f471d9fd" has been successfully started.

startvm には以下のようなオプションタイプがあり --type ${TypeName} で指定する。

Usage:

VBoxManage startvm          <uuid|vmname>...
                            [--type gui|headless|separate]

詳細はこちらに。

SSH でアクセス

VM が起動したら SSH でアクセスする為に SSH のポート番号を確認する必要があるので以下のように確認する。

$ VBoxManage showvminfo ubuntu-dev_ubuntu_dev_1435925046744_48053 | grep ssh
NIC 1 Rule(3):   name = ssh, protocol = tcp, host ip = 127.0.0.1, host port = 2202, guest ip = , guest port = 22

この確認方法が正しいのかはわからないがひとまず SSH のポートは 2202 で開いているのがわかる。

$ ssh vagrant@127.0.0.1 -p 2202

接続完了。

vagrant@127.0.0.1's password:
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-55-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Sun Sep 27 01:14:29 UTC 2015

  System load: 0.0                Memory usage: 2%   Processes:       50
  Usage of /:  41.1% of 39.34GB   Swap usage:   0%   Users logged in: 0

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

159 packages can be updated.
63 updates are security updates.


Last login: Fri Sep 25 05:12:01 2015 from 10.0.2.2

仮想マシンの停止

仮想マシンの起動が startvm オプションだったので stopvm だろうと思ったら違った。以下のように仮想マシンを停止する。

$ VBoxManage controlvm cc121867-1e41-43e6-adc8-83e1f471d9fd poweroff

contorlvm のサブオプションとして poweroff オプションを利用する。controlvm オプションには複数のサブオプションがあるので詳細はこちら


以上

簡単なメモでした。