How do I associate a Vagrant project directory with an existing VirtualBox VM?

后端 未结 10 1813
梦如初夏
梦如初夏 2020-12-02 03:57

Somehow my Vagrant project has disassociated itself from its VirtualBox VM, so that when I vagrant up Vagrant will import the base-box and create a new virtual

10条回答
  •  难免孤独
    2020-12-02 04:32

    This is modified from @Petecoop's answer.

    Run vagrant halt if you haven't shut down the box yet.

    Then list your virtualboxes: VBoxManage list vms

    It'll list all of your virtualboxes. Identify the box you want to revert to and grab the id between the curly brackets: {}.

    Then edit the project id file: sudo nano .vagrant/machines/default/virtualbox/id (from the project directory)

    Replace it with the id you copied from the list of VBs.

    Try vagrant reload.

    If that doesn't work and gets hung on SSH authorization (where I stumbled), copy the insecure public key from the vagrant git. Replace the content of /.vagrant/machines/default/virtualbox/private_key. Backup the original of course: cp private_key private_key-bak.

    Then run vagrant reload. It'll say it's identified the insecure key and create a new one.

    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
    ==> default: Machine booted and ready!
    

    You should be all set.

提交回复
热议问题