Vagrant taking up too much space - vagrant

I switch between four projects on my local machine and I use vagrant for each on of them.
$ vagrant global-status
id name provider state directory
-------------------------------------------------------------------------
3e1f21e default virtualbox running d:/www/project1/source
9080cd0 default virtualbox poweroff d:/www/project2/source
c4e0461 default virtualbox poweroff d:/www/project3/source
b75805d default virtualbox running d:/www/project4/source
However, my C drive (I'm on a windows 7 machine) is showing that I'm using 16.4GB on the \User\VirtualBox VMs
It seems a little excessive for just 4 VMs. So I opened VirtualBox and saw that I had 7 VMs on there.
I'm thinking these are boxes that I previously destroyed but I could very well be wrong.
I couldn't find anything about it on the web. But could I just delete these items or are they important to vagrant? If so, how can I set up vagrant without having to use up too much space on my laptop?

If you destroyed the boxes with vagrant destroy and it finished without errors, the box should be gone from Virtualbox as well. If this didn't happen, you can remove the box manually from Virtualbox. Just make sure to also delete the local files (Virtualbox will ask you if you wanna keep the HD, which you don't)!
If you are unsure which boxes to remove from Virtualbox because they are all named he same, you can either destroy all boxes from vagrant and then remove all boxes left to Virtualbox. Or you can start all vagrant boxes using vagrant up and then delete the ones from Virtualbox which don't run.

Related

Vagrant creating another VM instead of boot up the default VM

I'm using Vagrant on Windows to create my dev environment. But today when I start it with the command vagrant up, it created another VM instead of using the one I always used it.
Looking in the folder C:/Users/My_User/VirtualBox VMs I found the default VM files.
How to proced to make Vagrant recognize this default VM?
PS: Sorry for my bad english!

VM has become 'inaccessible' - Vagrant no longer working

For some reason this morning when I run 'vagrant up' I get the following error (this has worked absolutely fine for over a year)
Your VM has become "inaccessible". Unfortunately, this is a critical error with VirtualBox that Vagrant can not cleanly recover from. Please open VirtualBox and clear out your inaccessible virtual machines or find a way to fix them.
I could try removing my existing .vagrant folder and doing a vagrant up but that will take forever on our very slow internet speeds - can anyone suggest how to fix this quickly?
this works for me:
In my "C:\Users{user}\VirtualBox VMs{vm-id}" folder are two files
{vm-id}.vbox-prev
{vm-id}.vbox-tmp
Renaming from "{vm-id}.vbox-tmp" to "{vm-id}.vbox" solved my problem and i can call "vagrant up"
You can simply delete the .vagrant folder from your project folder and run vagrant up again.
This worked for me
After some digging through the debug output, I discovered that even though the actual VM is intact (I can load and run it from the VirtualBox GUI app), somewhere in its guts, VirtualBox flagged this VM as "". Vagrant, rightly believing what it's told, spits out the error message.
After looking at VBoxManage's help, I found that one its commands, list vms, unsurprisingly lists all of the VMs registered with VirtualBox:
$ /cygdrive/c/Program\ Files/Oracle/VirtualBox/VBoxManage.exe list vms
"precise64" {3613de48-6295-4a91-81fd-36e936beda4b}
"<inaccessible>" {2568227e-e73d-4056-978e-9ae8596493d9}
"<inaccessible>" {0fb42965-61cb-4388-89c4-de572d4ea7fc}
"<inaccessible>" {c65b1456-5771-4617-a6fb-869dffebeddd}
"<inaccessible>" {9709d3d5-ce4d-42b9-ad5e-07726823fd02}
One of those VMs flagged as inaccessible is my lost VM! Time to fix VBoxManage's wagon, by unregistering the VM as inaccessible, then re-registering it with the correct name:
Open the configuration file for your lost VM. Mine was saved to C:\cygwin\home\Philip\VirtualBox VMs\rails-vm-v2\rails-vm-v2.vbox
Find and copy the value of the uuid attribute of the Machine node. Mine was 9709d3d5-ce4d-42b9-ad5e-07726823fd02.
In a Windows command prompt (or Cygwin terminal), unregister the VM with the unregistervm command, using the [uuid] value from step 2:
$ C:\Program Files\Oracle\VirtualBox\VBoxManage.exe unregistervm [uuid]
Now register the VM using the registervm command, with the path to the VM configuration file:
$ C:\Program Files\Oracle\VirtualBox\VBoxManage.exe registervm C:\cygwin\home\Philip\Virtual VMs\rails-vm-v2\rails-vm-v2.vbox
Now you should be able to start the VM as expected.
Source :
http://www.psteiner.com/2013/04/vagrant-how-to-fix-vm-inaccessible-error.html
Nothing here worked for me.
I deleted (or renamed see first comment) all files from
C:\Users[YourNameHere].VirtualBox
Run vagrant again:
vagrant up
Now it's up.
VirtualBox Manager will likely give you a bit more useful information, for example in my case it reported that the .vbox file did not exist.
After taking a look the problem was indeed that the file didn't exist - something had renamed it to x.vbox-tmp (shutting the PC down with the VM still running maybe?)
I copied the x.vbox-prev file to x.vbox and tried booting the VM again and everything worked fine.
Find the one which is inaccessible with one of the following commands:
$ vagrant global-status
or:
$ VBoxManage list vms
Then note the GUID, and remove it from VirtualBox.xml file (OS X: ~/Library/VirtualBox/VirtualBox.xml, Windows: %HOME%/.VirtualBox).
Alternatively remove .vagrant folder from the folder where is your VM and start from scratch (vagrant up).
See also: Cannot Delete "Inaccessible" virtual machines from Virtualbox GUI at VirtualBox
By chance if someone deletes your vm from VirtualBox VMs folder manually, also in this case your vm would become inaccessible. However, you will not be able to get your machine back but vagrant will still show your vm in the list. To remove it completely from the vm list, go to
\.vagrant.d\data\machine-index
and open index file. Delete the reference of inaccessible machine. Next time when you run below command, it will not show your inaccessible machine.
vagrant global-status --prune
My problem was the same, but the fix was quite different... my VMs are stored on a network drive, accessible by NFS share. The remote drive had failed to come up after a reboot, so the VMs weren't accessible.
Took me a while to realise the reason, and meantime hunted all over SO without a solution.
Then I realised, facepalmed, mounted the paths, and it all worked.
So in a nutshell, it was a path issue.
I felt I should include it here in case it helps someone in the same boat.
By using command line, you can remove all inaccessible boxes by using an one-liner:
VBoxManage list vms |grep inaccessible |cut -d "{" -f2 |cut -d "}" -f1 |xargs -L1 VBoxManage unregistervm
See https://phz.fi/?p=8422
I had to rename [vm-id].vbox-tmp (on VirtualBox VMs) to [vm-id].vbox. After that, without delete the .vagrant folder, I could run vagrant up and it worked very well.
On Linux the following will unregister the machines:
VBoxManage list vms
VBoxManage unregistervm <inaccessible machine UID>
After that you may want to restart VB services:
sudo /sbin/vboxconfig
Deleting .vagrant folder may help but you had to rebuild the machines.
I also had this problem.
when change directory of virtualBox after restart macOS virtualbox get inaccessible to all vms.
my solution worked.
just move virtual box to default directory.
remove all inaccesible vms from gui, then register vms from default path next run it.
or
vagrant up

Does the vagrant destroy works on current folder or globally

I am confused with vagrant destroy command.
The output of vagrant status is
Current machine states:
default running (virtualbox)
But I have two vagrant VMs running in Virtual box
MacBook-Pro:server john$ vboxmanage list runningvms
"john-servers_default_1415665580149_91312" {114ad904-8629-4c4a-9344-d685c78a8228}
"test" {a6be5689-0ac3-4ac7-845d-97f2f4022cd9}
Now when I do vagrant destroy, it says do you want to destroy deafult VM
Now I am not sure which machine it will destroy. I am inside test VM but I don't want to take risk.
I tried this vagrant destroy test or vagrant destroy a6be5689-0ac3-4ac7-845d-97f2f4022cd9 but that didn't work
What is the safe way to delete VM?
To destroy test VM, cd into the test folder and enter vagrant destroy - this will destroy the vagrant environment within this directory. After it is destroyed, the default provider will still be shown when you enter vagrant status, together with a not created (virtualbox) status.
vagrant status only shows one vagrant VM running in virtualbox because this command only shows the state of the underlying guest machine within that directory.
In order to see all vagrant environments, enter vagrant global-status --prune - this brings up the state of all the active vagrant environments no matter what directory you run this command from. You can even destroy a VM that's outside of your current directory by typing vagrant destroy ID_TAG by copying the ID tagged to the unwanted VM.
If you are still unsure if the right VM is destroyed, input vagrant halt within the test directory and test if the right VM is being halted. This is at the very least a reversible action in case the wrong VM is selected. But the initial solution vagrant destroy within the test directory should do the trick.
vagrant destroy would remove, in your case, the "john-servers_default_1415665580149_91312" VM.
Vagrant look the VM ID in the directory containing the Vagrantfile in .vagrant/machines/default/virtualbox/id
If you want to remove the "test" VM, you can use VBoxManage.
VBoxManage unregistervm a6be5689-0ac3-4ac7-845d-97f2f4022cd9 –delete
Keep in mind that the -delete flag will remove all disks associated with this VM

A VirtualBox machine with the name 'homestead' already exists

Since homestead 2.0 homestead laravel has not been working
I don't know why 'homestead init' creates a Homestead.yaml file in mydirectory/.homestead
and not in the project directory. Homestead up OR Vagrant up create the following message
A VirtualBox machine with the name 'homestead' already exists.
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'laravel/homestead'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'laravel/homestead' is up to date...
A VirtualBox machine with the name 'homestead' already exists.
Please use another name or delete the machine with the existing
name, and try again.
I solved by using vboxmanage to get the ID of the VM.
$ vboxmanage list vms
"my-vm" {c700b8b6-b766-4638-871b-736b44b7db18}
Copy the ID of the desired VM (the c700…db18 string) into the contents of ~/.vagrant/machines/default/virtualbox/id. Save the file then run vagrant up to get the vm working without having to destroy it.
For me, the machine was not showing up as an active VM in the VirtualBox application. To fix I had to do this:
vagrant global-status
This gave me the ID of the machine that I needed to destroy. With the ID, run:
vagrant destroy {VM ID}
I had to run that in sudo to actually destroy the machine. At that point, I was able to run
vagrant up
From the following message :
A VirtualBox machine with the name 'vm_name' already exists.
Please use another name or delete the machine with the existing
name, and try again.
I listed current running virtual machines from the command line :
VBoxManage list vms
Result :
"vm_name" {8ba467b7-da96-4f68-9bf8-671dd6f0d007}
Then proceeded with the removal of the offending virtual machine :
VBoxManage unregistervm 8ba467b7-da96-4f68-9bf8-671dd6f0d007 --delete
You probably have a virtualbox running! Open the programme virtualbox and shut down the other virtualbox ;)
http://smallbusiness.chron.com/shut-down-virtualbox-43657.html
If this isn't working then you might want to delete the old homestead folder and place all your projects in the new folder ;)
I'm a bit late to the party on this, but for anyone else having this issue SergioPeluzzi came closest, but didn't get the cigar with this:
Seek for vb.name = settings["name"] = "homestead" line and changed "homestead" to "HOMESTEAD" and "vói lá"
The line is actually:
vb.name = settings["name"] ||= "homestead"
As you can see from the bit that says settings["name"], you just need to add a name field to your Homestead YAML file, e.g.
memory: 2048
cpus: 1
provider: virtualbox
name: my-sexy-homestead-box
I edited Homestead.yaml and add new name for it
ip: "192.168.10.10"
memory: 2048
cpus: 4
provider: virtualbox
name: my-new-homestead-box-name
I solved this editing /Homestead_folder/scripts/homestead.rb
Seek for vb.name = settings["name"] = "homestead" line and changed homestead to HOMESTEAD and "vói lá" that worked for me.
I had an old .vagrant directory in my project which was causing the error :)
If this doesn't fix it for you i would suggest opening VirtualBox and removing all VirtualBoxes and trying again.
You just have to add the key name to your homestead.yaml file right after the provider like this:
name: name_of_you_machine
That works for me.
I had same issue today. Spend few hours to find the solution.
If by any reason you can't find the list of exiting virtual machines then type in terminal
sudo virtualbox
This will run Virtual Box in GUI. You should see the the full list of VMs and from there you'd be able to manage them.
Typing "virtualbox" only won't show anything. You need to be root (administrator).
Thanks to mightyspaj for the tip.
Commands to execute:
vagrant box list
vagrant box remove laravel/homestead
vagrant global-status
vagrant destroy nameOfYourBox
Open your VirtualBox and delete all itens of your homestead
vagrant up
I opened the virtualBox and then deleted homestead vm that was created earlier. It helped.
I was receiving the same error message, even after running "homestead destory", and "vagrant destroy". Same as you, I was using the VirtualBox provider, vagrant, and homestead. Here's what I did:
Opened VirtualBox GUI. I see "homestead" as a VM, but I cannot remove it, button is greyed out.
I logged out of my OS, logged back in and re-opened VirtualBox. Status is now "aborted" and i'm able to remove.
There were some residual files in ~/VirtualBox\ VMs/homestead, so i ran rm -r /Users/gabriel/VirtualBox\ VMs/homestead
I am now able to run "homestead up"
Open VirtualBox GUI. See for your VM and remove it.
It solved my problem.
Sometimes you might not want to delete old box. Yesterday may old Vagrant has broken, I've updated Vagrant and Virtualbox but folders mapping didn't work. I wanted to run new box and had this error.
I didn't want to remove old box (because I wanted to run some backups) but I wanted to run new box. The solution was running VirtualBox, right click on Homestead machine and choose Settings and then changing name from homestead to homestead_old.
After that I was able to install homestead but had this old machine and could also run this to make any backups I needed.
If you are a Windows User, make sure you delete C:\Users\<Username>\VirtualBox VMs\homesteadfolder. Because if there is still a folder named homestead, the action of vagrant up will not be completed
If you want to keep keep your machine, without destroying and recreating following steps should solve your problem.
(I work on OS X El Captain, Vagrant 1.8.1)
Run homestead in debug mode
homestead --debug up
Look for something like in the output:
INFO machine: Initializing machine: default INFO machine: -
Provider: VagrantPlugins::ProviderVirtualBox::Provider INFO machine:
- Box: # INFO machine: - Data dir: /Users/YOUR_HOME_DIR/Workspace/Homestead/.vagrant/machines/default/virtualbox
Data dir, is the path which is interesting for you.
Then vboxmanage list vms
"homestead" {0e8438b9-4a67-4fb1-80cb-2c62cf04ab5c}
"settler_default_1447385930122_73498_1474294682778_13108"
{93ecb93f-f159-4406-a384-5312b4d3ab34}
Edit id file, in the path which you found out in the previous command
vi /Users/YOUR_HOME_DIR/Workspace/Homestead/.vagrant/machines/default/virtualbox/id
Replace content of that file, with the id of the VM you want to fix, in this scenario it is
0e8438b9-4a67-4fb1-80cb-2c62cf04ab5c
Now try
homestead up
VM should start booting. It might work, or you might have issues with ssh authentication
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying...
To fix that do following
Check Homestead SSH config
homestead ssh-config
You should get something like
Host default HostName 127.0.0.1 User vagrant Port 2222
UserKnownHostsFile /dev/null StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile
"/Users/pryznar/.vagrant.d/insecure_private_key"
IdentitiesOnly yes
LogLevel FATAL
Edit IdentityFile file
/Users/YOUR_HOME_DIR/.vagrant.d/insecure_private_key
Check Homestead.yml
cat /Users/YOUR_HOME_DIR/.homestead/Homestead.yaml
Then copy path to the file under the key keys, and copy private key from that file
cat ~/.homestead/ssh/id_rsa
Last step is to replace private key in /Users/YOUR_HOME_DIR/.vagrant.d/insecure_private_key with the one you just copied
Now try rung homestead again, should work.
homestead up
I got some warnings, but so far it works without issues
==> default: Warning: Using a password on the command line interface can be insecure.
==> default: ERROR 1045 (28000): Access denied for user 'homestead'#'localhost' (using password: YES) The SSH command
responded with a non-zero exit status. Vagrant assumes that this means
the command failed. The output for this command should be in the log
above. Please read the output to determine what went wrong.
You can open the VirtualBox GUI and remove the conflicting virtual machine.
None of this worked for me. I was using an old dev machine
I attempted:
vagrant global-status > destroy any by id which you don't need or match what is conflicting
open virtualbox and remove + delete files for any which you don't need or are conflicting
What worked:
locate your ~/.vagrant/machines/ or ~/.vagrant.d/boxes folder. In my case, it contained the conflicting vm and also a bunch of old left over vm machines which steps 1 & 2 did not remove for some reason.
after clearing these, everything worked fine again, finally!
Windows10
Edit Homestead.yaml file and give a new name for the box:
ip: "192.168.10.10"
memory: 2048
cpus: 2
provider: virtualbox
name: my-new-vbox #new name for the box
and run vagrant up or vagrant up --provision
Or
Open Virtualbx application in GUI and delete all the virtualbox that was causing problem and run the above command
Or
Delete the "Vagrant" file inside homestead folder and run the above command.
I had the following error:
Error:
A VirtualBox machine with the name 'homestead-7' already exists.
Please use another name or delete the machine with the existing
name, and try again.
Solution:
Find the VirtualBox VMS folder, in my case it was in ~/VirtualBox VMs
List the elements in the folder with ls command, and review if the virtual machine is there
Delete the folder with the name of the machine, in my case homestead-7
Re-execute the vagrant up command in the homestead folder
That's all, I hope it's helpful, that was my solution.
Regards!
In my case the following article provide the solution. There was a folder named homestead inside the path /var/root/VirtualBox VMs/ that was causing the issue. Once this folder was removed, rm -r homestead, the issue was resolved. If you can not see or have access to this path execute the following commands in your terminal windows:
$ sudo -s
$ cd /var/root/VirtualBox\ VMs
And proceed to delete the homestead folder.
Add --force after box, and before your given name.
Renaming an already existing default VM
Disclaimer
The following procedure will destroy your VM and may be only suiteable in a desting-environment like mine! For production environments, consider to repair the association like described here
I had this problem after overriding the default name of an already existing VM by using
Vagrant.configure("2") do |config|
config.vm.define :ubuntu_test
where the VirtualBox name was also set (as a newbie I assumed that Vagrand will use this name too)
config.vm.provider "virtualbox" do |vb|
vb.name = "Ubuntu-Test"
end
By adding config.vm.define it seems that Vagrant doesn't associate the VirtualBox VM any more with the Vagrant file since even vagrant destroy -f say VM not created but vagrant up throw this error
A VirtualBox machine with the name 'Ubuntu-Test' already exists.
To delete those zombie VM
If the VM is running, stop it first: vboxmanage shutdown <VMName> (Here the name is Ubuntu-Test)
Get the Id by running vboxmanage list vms
Delete it: vboxmanage unregistervm <Id> --delete
Now your VM can be re-created using vagrant up
Using vagrant global-status --prune, your new name is present
For me id file was present in the below-mentioned location.
D:\drupalvm.vagrant\machines\drupalvm\virtualbox
After a few hours of troubleshooting, nothing else worked for me, as no one mentioned this little detail.
Depending on your privileges at the time of installation, you may need to run virtualbox as an administrator. It was only when I did this that I saw my vagrant boxes in the list of virtual machines.
I then proceeded to remove my virtual machine named homestead from virtualbox, and the problem was solved.
If you're using homestead in Windows, just open up your Oracle VM VirtualBox and delete the homestead VM.
The Vagrant relies on VirtualBox (if that's the default provider) so it checks for existing environment first before provisioning your VM.
It is executing the following command:
VBoxManage list vms
and when it finds the VM with the same hostname, so it'll fail.
You can debug it by:
vagrant --debug up
to find out the exact reason.
Solution
If you're planning to use multiple VMs in different folders, then you need to change your config.vm.hostname (possibly config.vm.provider(name) as well) in your Vagrantfile to make it unique. Or simply remove it, so Vagrant will assign a different name for each VM.
If that's not the case, simply shutdown and unregister previous VM which conflicts by running:
VBoxManage controlvm NAMEOFVM poweroff
VBoxManage unregistervm NAMEOFVM --delete
and re-run your vagrant up.
If it fails on directory rename (because you missed --delete), then rename or remove the destination folder, for example:
rm -fr ~/"VirtualBox VMs/NAMEOFVM"
and re-try again.
This problem may be related to: GitHub issue #2969 - vagrant up not detecting a previously run VM
In my case, nothing was indicating that the VM "already exists" besides that error message. Nothing on VirtualBox UI, nothing returned by “vboxmanage list vms”, nothing through “vagrant global-status”, it didn’t exist in “.vagrant.d\boxes” and so on. I resolved it by manually creating a new same-name VM in the VM VirtualBox Manager (using the “new” button + accepting all the defaults), and then removing it (right-click > remove). After that, the “vagrant up” worked as expected.
I had the same issue today. Windows 10. I recently had updated Homestead, so the error was probably because of that. I tried it all, destroy, up, delete folders, whatever. Whenever I tried to run vagrant up, it was showing this kind of errors. The solution? After updating, I noticed that Homestead is now naming the boxes by the project folder name, and Homestead.yaml has all that infos. I just run that Homestead Windows configuration vendor\\bin\\homestead make and later them a vagrant up (before making sure it was all clean) and voilá, looks like the machine is booting now. =) Try that if you need it.

Flag/Mark Vagrant Machine As Provisioned

I don't want to run provision on my vagrant (VirtualBox) machine. I want to vagrant up and the machine marked as "provisioned", even though actually the machine is not provisioned yet. I just want to mark it as "provisioned".
Is this possible? Perhaps, is there some file i can edit in .vagrant?
It seems vagrant looks for the existence of a file :
.vagrant/machines/[machine-name]/[provider]/action_provision
However, it seems that there is more logic to that in
[vagrant-install-path]/lib/vagrant/action/builtin/provision.rb
You can start investigating from there to what exactly vagrant needs to consider a machine as provisioned.
I personally didn't have time to look more into it since I fixed my issue with a workaround :).
Started the machine with vagrant up, so that chef_solo provisioner started running, and then hitting CTRL+C twice (so that chef says "exiting without cleanup") helped making the VM be marked as provisioned, so that it could be started without the --no-provision flag.
Hoping this comes of any help.

Resources