LoginSignup
61
59

More than 5 years have passed since last update.

vagrant upで A VirtualBox machine already exists.とでる解決方法

Last updated at Posted at 2015-03-25

vagrant upでVagrantが
起動できなくなり困りました。その際の解決方法です。

vagrant up で box already exist

vagrant upをしてもboxが存在すると言われて起動できません。

vagrantの起動が失敗
vagrant up

A VirtualBox machine with the name 'hoge' already exists.
Please use another name or delete the machine with the existing
name, and try again.

vagrant destroy

単にvagrant destroyを実行すると、その場でdestroyしていいか聞いてきますのでyを入力して実行するとdestroyを実行できます。

vagrant destroy で Nameを指定

vagrant global-statusを実行すると、いまある環境がわかります。そこからvagrant destroyでNameをdestroyするとvagrant upが走るかもしれません。

destroyでNameを指定
vagrant destroy local.example.com

ただ、ここで以下のようにエラーが出る場合があります。

A VirtualBox machine with the name 'local.pugiemonn.com' already exists.
Please use another name or delete the machine with the existing
name, and try again.

この場合はvagrant global-statusでなくオプションを付けてください。

vagrant global-status --prune

--pruneはcacheを削除するオプションみたいです。

vagrant box remove で boxを削除

もしくはvagrant box removeでboxを削除するとvagrant upが動くかもしれません。
boxの一覧はvagrant box listでboxの一覧を確認できます。

vagrantの起動が失敗
vagrant box remove hoge
Box 'hoge' (v0.1.1) with provider 'virtualbox' appears
to still be in use by at least one Vagrant environment. Removing
the box could corrupt the environment. We recommend destroying
these environments first:

default (ID: 9c5d026830a7a7s91dadb21bbb3f6f34)

Are you sure you want to remove this box? [y/N]

VBoxのディレクトリを削除する

VBoxのディレクトリに書き込めない場合はディレクトリを削除して作りなおすとvagrant upが走るかもしれません。

何度か実行しているうちに以下の様エラーがでました。

The name of your virtual machine couldn't be set because VirtualBox
is reporting another VM with that name already exists. Most of the
time, this is because of an error with VirtualBox not cleaning up
properly. To fix this, verify that no VMs with that name do exist
(by opening the VirtualBox GUI). If they don't, then look at the
folder in the error message from VirtualBox below and remove it
if there isn't any information you need in there.

VirtualBox error:

VBoxManage: error: Could not rename the directory '/Users/kawasakiosamu/VirtualBox VMs/hoge_1426591193616_11769' to '/Users/kawasakiosamu/VirtualBox VMs/hoge' to save the settings file (VERR_ALREADY_EXISTS)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component SessionMachine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "SaveSettings()" at line 2788 of file VBoxManageModifyVM.cpp

この場合/Users/kawasakiosamu/VirtualBox VMs/hogeがVERR_ALREADY_EXISTSということなので消してしまいました。

ディレクトリを削除
sudo rm -rf /Users/kawasakiosamu/VirtualBox¥ VMs/hoge

VirtualBoxから停止

VitualBoxを起動し、該当のVMを停止するのも有効です。

/etc/exportsのディレクトリがかぶっている

nfsを使っている場合これがでるかもしれません。

remove this file or specify a different file name for outputting.

上記のように表示され場合 /etc/exportsを編集して書き込まれているディレクトリの表記を削除すると起動できます。

最終的に

vagrant upが走りました。

参考

61
59
0

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
61
59