最近在使用 vagrant homestead 时,不小心在虚拟机上使用了 exit 命令退出虚拟机,导致再使用 vagrant up 时出现以下错误:
Bringing machine 'laravel53test' up with 'virtualbox' provider...
==> laravel53test: Checking if box 'laravel/homestead' is up to date...
==> laravel53test: Clearing any previously set forwarded ports...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below. Command: ["modifyvm", "81a6bbac-d748-48c4-b9be-c9dd82068879", "--natpf1", "delete", "ssh", "--natpf1", "delete", "tcp33060", "--natpf1", "delete", "tcp44300", "--natpf1", "delete", "tcp54320", "--natpf1", "delete", "tcp8000"] Stderr: VBoxManage.exe: error: Code E_FAIL (0x80004005) - Unspecified error (extended info not available)
VBoxManage.exe: error: Context: "LockMachine(a->session, LockType_Write)" at line 507 of file VBoxManageModifyVM.cpp
在网上搜索了下,判断应该是 VirtualBox 的 bug 引起的,如果不是用 vagrant halt 来退出 box,而是直接在 box 上退出,就有可能引起 box 状态异常,这时用 VirtualBox 启动虚拟机也会报错,而且用 vagrant halt 也没用。
解决方法:打开任务管理器,把 virtualBox 相关的所有进程强制结束掉,然后再使用 vagrant up 就正常了!