LoginSignup
8
6

More than 5 years have passed since last update.

Vagrant アンインストール時のトラブルシューティング

Last updated at Posted at 2018-05-11

もう使われなくなったサーバマシンをおもちゃにしても良い、とのことだったので、まずは HDD の大半を占めている Vagrant を軽い気持ちでアンインストールしようとしました。Vagrant 初めて触るのに。
猫と遊んだりしながらだらだらと作業をしていたら思った以上に失敗したので FYI です。
反面教師にしてください。

要は Vagrant をアンインストールする前に vagrant destroy をちゃんとやっておけ、という話。

Vagrant のアンインストール

公式を見たところ、以下のディレクトリを削除すれば良いとのこと。

On Linux:
rm -rf /opt/vagrant
rm -f /usr/bin/vagrant

アンインストール超簡単!HDD の空きはどのぐらい増えたのかな?
と思って確認すると・・・全然増えてないな・・・

On all platforms, remove the ~/.vagrant.d directory to delete the user data. When debugging, the Vagrant support team may ask you to remove this directory. Before removing this directory, please make a backup.

同じページに User Data の消し方も書いてあったので、

# rm -rf ~/.vagrant.d

それでも空き容量は増えません。

~/VirtualBox VMs/ 配下を削除

~/VirtualBox VMs/ の仮想イメージファイルっぽいものを発見。
OK、これを消せば良いんだな。

# rm -rf ~/VirtualBox\ VMs/centos_default

まだまだ空き容量は増えません。

Vagrant アンインストール後に仮想マシンを削除する方法

ここら辺でいよいよ「これ以上場当たり的なことをせず、ちゃんと調べよう」と思い立ちます。

どうも Vagrant をアンインストールする前に vagrant destroy で仮想マシンを破棄していなかったことが悪かった模様。
上記リンクで確認したところ、VBoxManage で削除する方法が記載してありました。

# VBoxManage list vms
"centos_default" {UUID}

VBoxManage list vms で見つけた仮想マシンを削除します。

# VBoxManage unregistervm centos_default --delete
VBoxManage: error: Cannot unregister the machine 'centos_default' while it is locked
VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "Unregister(CleanupMode_DetachAllReturnHardDisksOnly, ComSafeArrayAsOutParam(aMedia))" at line 156 of file VBoxManageMisc.cpp

ギャフン

仮想マシン削除時に「Cannot unregister the machine 'xxx' while it is locked」というエラーが出た時の対処

また調べます。
* vagrant destroyが「Cannot unregister the machine 'xxx' while it is locked」というメッセージを出して失敗する

なるほど、プロセスが生きてるのか。

# ps -ef | grep -i vboxheadless
root      6972  6466 10  2017 ?        16-18:53:10 /usr/lib/virtualbox/VBoxHeadless --comment centos_default --startvm uuid --vrde config
root     11107 10504  0 14:12 pts/0    00:00:00 grep -i vboxheadless```
# kill 6972

さて改めて削除するか、と仮想マシンを再度確認すると、

# VBoxManage list vms
"<inaccessible>" {uuid}

ギャフン

仮想マシンが inaccessible になった時の対処

df コマンドで確認したところ、この時点で予想していた分だけ HDD 空き容量は増えていました。
(プロセスを kill する前には増えていたのかも。)

とはいえ Virtual Box に inaccessible が残っているのは気持ちが悪い・・・
今度は --delete オプションなしの VBoxManage unregistervm で登録されている VM を解除します。

VBoxManage unregistervm {uuid}```
# VBoxManage list vms
#

これにて落着。


Vagrant をアンインストールする機会というのはあまりないかもしれませんが、エラーメッセージなどで検索してきた人に、この記事が少しでも役に立てたら何よりです。

8
6
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
8
6