Saturday 27 May 2017

Annoying VM issues

I spent all this afternoon trying to get my VM working so I could get some work done. I got a new PC recently, and if I tried to save settings in the BIOS then it wouldn't POST. So I updated the BIOS, and it seems that by default in the new BIOS settings hardware virtualisation is off, so when I tried to start my VM it wouldn't boot. So I turned on hardware virtualisation in the BIOS (which did save properly now, though it seems the failure to POST was due to RAM settings, not BIOS version, and it's actually worse on the new BIOS version).

After doing this vagrant started creating a new machine when I ran vagrant up, rather than running my existing VM. So I thought I'd leave it for later and just run it on my laptop (since no changes had been made there). But then that had exactly the same problem, and created another VM instead of booting the existing VM.

Back on my PC I found this thread: Re-associate vagrant with vm. The main piece of advice there is:

  • Ran vagrant status
  • At this point the VMs where still listed as "(not created)".
  • Ran VBoxManage list vms to find the ids of the VMs
  • Went in to ./vagrant/machines/dev/virtualbox/id and updated the id
  • Ran vagrant status

After that I got a successful result, and so ran vagrant up. But it couldn't ssh into the machine as it had generated a new private key. So I thought I could just copy across the backup of the folder where the vagrant config files for the VM were. But after doing this it went back to trying to create a new machine again, and removing all the vagrant config files.

Running VBoxManage now, I saw that the correct VM wasn't even listed. But it was listed (the only VM) in the VirtualBox GUI and the VirtualBox config file. I tried running VirtualBox GUI as admin since I was running VBoxManage as admin, but still the same.

Eventually I just restarted the PC, ran VBoxManage again, and now it showed only the correct VM. I copied the vagrant machine config files back over from the backup, ran vagrant status, and it all looked good. Ran vagrant up, and the machine started up correctly!

If the same thing happens again in the future, hopefully I'll remember this blog post so I can sort it in 5 minutes instead of 5 hours.

No comments: