Tough as nail, VM refused to die after vagrant destroy

17 views
Skip to first unread message

Sorcerer Stone

unread,
May 8, 2020, 1:13:47 PM5/8/20
to Vagrant
Hello All,
My working environment:
Win10Pro with HyperV disabled, Vagrant, Virtualbox, then running docker containers.
I have 2 different opensource docker projects and each has its own vagrantfile.

I have no problem running each project individually in the above environment.

My goal is to have these 2 separate VMs to run concurrently and to exchange data between them.
To avoid ssh port collision, I have added the following port forwarding line to one of the project, let it call dockApp2 for now.
(the other project, I left it run with default vagrant setting aka port 22 to port 2222)

config.vm.network "forwarded_port", guest: 22, host: 2000, id: "ssh", auto_correct: true

Note:  Port 2000 is currently unused in my Host OS.

Then I issued "vagrant destroy" to this dockApp2.
Then I manually went into the directory for this dockApp2 (the directory where the vagrantfile is located) on my Window host and delete the .vagrant folder.

Then with the new port forwarding line in this vagrantfile for dockApp2, I ran vagrant up again.
However, I got an error. The error is "The name of your virtual machine couldn't be set because VirtualBox is reporting another VM with that name already exists."

How can this be? I have issued vagrant destroy. In addition, I issued this command to clear out all existing boxes after I issued vagrant destroy:

vagrant box list | cut -f 1 -d ' ' | xargs -L 1 vagrant box remove -f --all

I also manually deleted the .vagrant folder mentioned above. And in VirtualBox UI, this VM workspace disappeared after I ran "vagrant destroy".

Can someone please advise what I have done wrong or forgotten to do and how do I rectify this error?

Thanks in advance.

Dennis Chang

unread,
May 8, 2020, 1:52:43 PM5/8/20
to Vagrant
Hi Socerer Stone,

So .vagrant directory exists within your folder (which also contains your Vagrantfile).
However, the actual box exists on "C:\Users\yourname\.vagrant.d" and `vagrant destroy` should delete it.

My .vagrant.d

```
Windows2012R2 dchang$ ls -l ~/.vagrant.d/
boxes/                gems/                 plugins.json          setup_version
data/                 insecure_private_key  rgloader/             tmp/
Windows2012R2 dchang$ ls -l ~/.vagrant.d/boxes/
alpine-3.10/                                  generic-VAGRANTSLASH-centos6/
alpine-VAGRANTSLASH-alpine64/                 generic-VAGRANTSLASH-centos7/
bento-VAGRANTSLASH-ubuntu-14.04-i386/         mwrock-VAGRANTSLASH-Windows2012R2/
cb-training-certification-1584111440/         mwrock-VAGRANTSLASH-Windows2016/
cb-training-jenkins-fundamentals-1550622005/  ubuntu-VAGRANTSLASH-bionic64/
cb-training-pipeline-fundamentals-1574353126/ ubuntu-VAGRANTSLASH-focal64/
centos-VAGRANTSLASH-7/                        ubuntu-VAGRANTSLASH-xenial64/
dchang-VAGRANTSLASH-centos7/                  windows-2000-professional-base/
```

Sorcerer Stone

unread,
May 8, 2020, 4:48:51 PM5/8/20
to Vagrant
Hello Dennis,
Thanks again (Ran into you again!!)
Ok. I think I got this problem under control done. I foolishly did "vagrant destroy" to clean both projects.
Then I looked into this ".vagrant.d" directory. Most of the sub-folders, in particularly "data" were empty. What ever remains in other subfolders were pre-dated to my problems. So, I ignored them.
Then I "vagrant up" the first project (the one I kept all default settings of Vagrant). It ran.
Then I "vagrant up" the second project. It generated the same error. But this time, there were new suggestions that I should look at a directory which I didn't know it exist. It is called "VirtualBox VMs". I poked inside this folder.
It has, as you mentioned above, images of all my previous VMs for my projects.
I deleted the image for the project in question. Then I ran "Vagrant Up" for it.
The second project is up and I am able to ssh into the VM using the new ssh port forwarding settings.
Thanks.

BTW. Another newbie question.
If I want to purge all the folders created by a particular VM (say, I corrupted the configurations and need to clean them out) - short of destroying the VM and rebuilding it again, is there some vagrant commands (on Host OS) I can use so that I can purge all the temporary cache data in the relevant directory within the VM in question? If there is, can you kindly point the URL so that I can read up?

Dennis Chang

unread,
May 8, 2020, 5:37:42 PM5/8/20
to Vagrant
Hi  Sorcerer Stone,

:) Happy to help. I actually  don't usually poke around with those files/folders in the "VirtualBox VM" folder (on the host).
So I'm not sure I understand if you're referring to files in that folder, or if you're referring to folders inside the VM.
But, anyway, I don't know the answer to that one. If there is anything worth saving within your VM, you should be saving it
in a shared folder. If a cache doesn't survive a reboot you can always `vagrant  reload` to restart the VM.

But, files inside the VM are all contained in a virtual disk file with name [your VM name].VMDK {or VDI, RAW, other virtual disk formats} or similar. Just look for the largest file (in "VirtualBox VM") and you'll find it.

I hope that helps,
Dennis
Reply all
Reply to author
Forward
0 new messages