hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.23k stars 4.43k forks source link

Vagrant/VMware Fusion changed directory and vmware status says default not created #11024

Open phillipswdc opened 5 years ago

phillipswdc commented 5 years ago

Vagrant version

Vagrant 2.2.4 VMware Fusion Version 11.0.3 (12992109)

Host operating system

This is the operating system that you run locally.

Guest operating system

os x Mojave version 10.14.5 (18F132)

Vagrantfile

Vagrant.configure("2") do |config|

  config.vm.box = "bento/ubuntu-18.04"

    config.vm.provider "vmware_fusion" do |v|
      v.vmx["memsize"] = "4096"
      v.vmx["numvcpus"] = "2"
    end

  config.vm.hostname = "arterosil-local"

  config.vm.synced_folder "./arterosil", "/var/www/html", id: "arterosil-local",
    owner: "www-data",
    group: "www-data"

    # Run the bootstrap file to setup the VM. 
      # config.vm.provision :shell, path: "bootstrap.sh"
end

Debug output

N/A

Expected behavior

box should load on vagrant up command

Actual behavior

machine wants to load new server instead of using existing box. Vagrant status will actually remove all files in the /Volumes/portable/arterosil/.vagrant/machines/default/vmware_fusion directory.

My goal is to move my entire library of projects into a new external ssd drive so I can move in between my macbook and imac. yet I am unable to even move them to the ssd drive on the imac and load a box.

Steps to reproduce

  1. change directory name or move directory to another location
  2. cd into new directory and vagrant status or vagrant up
briancain commented 5 years ago
  1. Change directory name or move directory to another location

What directory are you changing? Your current working directory with Vagrant where your Vagrantfile lives, or something else?

phillipswdc commented 5 years ago

the directory that I have had for a long time is as follows...

~/kevin/development

inside that directory I have my projects...

~/kevin/development/project_ex_1 ~/kevin/development/project_ex_2 ~/kevin/development/project_ex_3 ~/kevin/development/project_ex_4

inside the directories is where the project files and .vagrant/vmware are located, like...

~/kevin/development/project_ex_1/.vagrant ~/kevin/development/project_ex_1/project_folder (synced to /var/www/html) ~/kevin/development/project_ex_1/Vagrantfile

I want to move the entire parent directory of each project. New location would look like this...

/Volumes/portable/project_ex_1

/Volumes/portable/project_ex_1/.vagrant /Volumes/portable/project_ex_1/project_folder /Volumes/portable/project_ex_1/Vagrantfile

where portable is an ssd drive runnign over usb C

Currently though just changing the name of the original directory (~/kevin/development -> ~/kevin/development-old) sends things into a tail spin and would require me to install the ubuntu box and all of the components again.

briancain commented 5 years ago

Can you confirm for me that the .vagrant folder was copied with it and its contents match what was previously there prior to the move? And once you move it, can you show me the very first initial output with a --debug flag after you have moved your project directory? Thanks!

phillipswdc commented 5 years ago

Yes I can confirm that the entire .vagrant folder was moved over. Including...

.vagrant/machines/default/vmware_fusion with the vm disks inside etc.

phillipswdc commented 5 years ago

here is a gist with the output from --debug flag video link at line 1 https://gist.github.com/phillipswdc/025f91872dd898a95396b86b28ecfd93

briancain commented 5 years ago

Thanks for taking the time to make the video @phillipswdc ! Interesting...I was able to reproduce it locally too. With the VirtualBox provider this doesn't happen, but it does happen with the vmware provider. Thanks for the report. Looks like a bug to me :thinking:

briancain commented 5 years ago

Actually, another question @phillipswdc - Before coping your guests, did you halt the vms you were planning to copy to the new location?

I was able to get this to work after a bit. I believe the issue here for me when I tried reproducing was when I ran vagrant status, the vmware guest was by default configured with the VirtualBox provider, so running vagrant status ends up removing the relevant files inside the .vagrant folder. After copying, I did a vagrant up --provider vmware_desktop on the guest instead and this ended up working for me as a work around. That was my issue at least. That being said, after looking at the debug log, it doesn't look like that might be the case for you.

brian@localghost:linux-sandbox % be vagrant up ubuntu --provider vmware_desktop                             ±[master]
Bringing machine 'ubuntu' up with 'vmware_desktop' provider...
==> ubuntu: Cloning VMware VM: 'bento/ubuntu-18.04'. This can take some time...
==> ubuntu: Checking if box 'bento/ubuntu-18.04' version '201906.18.0' is up to date...
==> ubuntu: Verifying vmnet devices are healthy...
==> ubuntu: Preparing network adapters...
==> ubuntu: Starting the VMware VM...
==> ubuntu: Waiting for the VM to receive an address...
==> ubuntu: Forwarding ports...
    ubuntu: -- 22 => 2222
==> ubuntu: Waiting for machine to boot. This may take a few minutes...
    ubuntu: SSH address: 127.0.0.1:2222
    ubuntu: SSH username: vagrant
    ubuntu: SSH auth method: private key
    ubuntu:
    ubuntu: Vagrant insecure key detected. Vagrant will automatically replace
    ubuntu: this with a newly generated keypair for better security.
    ubuntu:
    ubuntu: Inserting generated public key within guest...
    ubuntu: Removing insecure key from the guest if it's present...
    ubuntu: Key inserted! Disconnecting and reconnecting using new SSH key...
==> ubuntu: Machine booted and ready!
==> ubuntu: Configuring network adapters within the VM...
==> ubuntu: Waiting for HGFS to become available...
==> ubuntu: Enabling and configuring shared folders...
    ubuntu: -- /home/brian/code/vagrant-sandbox/linux-sandbox: /vagrant
brian@localghost:linux-sandbox % tree .vagrant                                                              ±[master]
.vagrant
├── machines
│   ├── docker-1
│   │   └── docker
│   │       └── vagrant_cwd
│   ├── docker-2
│   │   └── docker
│   │       └── vagrant_cwd
│   ├── docker-3
│   │   └── docker
│   │       └── vagrant_cwd
│   ├── hashicorp
│   │   └── virtualbox
│   │       └── vagrant_cwd
│   ├── ubuntu
│   │   ├── virtualbox
│   │   │   └── vagrant_cwd
│   │   └── vmware_desktop
│   │       ├── 96b9e5fa-77d3-4ff6-ae20-48d94a68d2e6
│   │       │   ├── disk-cl1-s001.vmdk
│   │       │   ├── disk-cl1-s002.vmdk
│   │       │   ├── disk-cl1-s003.vmdk
│   │       │   ├── disk-cl1-s004.vmdk
│   │       │   ├── disk-cl1-s005.vmdk
│   │       │   ├── disk-cl1-s006.vmdk
│   │       │   ├── disk-cl1-s007.vmdk
│   │       │   ├── disk-cl1-s008.vmdk
│   │       │   ├── disk-cl1-s009.vmdk
│   │       │   ├── disk-cl1-s010.vmdk
│   │       │   ├── disk-cl1-s011.vmdk
│   │       │   ├── disk-cl1-s012.vmdk
│   │       │   ├── disk-cl1-s013.vmdk
│   │       │   ├── disk-cl1-s014.vmdk
│   │       │   ├── disk-cl1-s015.vmdk
│   │       │   ├── disk-cl1-s016.vmdk
│   │       │   ├── disk-cl1-s017.vmdk
│   │       │   ├── disk-cl1.vmdk
│   │       │   ├── disk-cl1.vmdk.lck
│   │       │   │   └── M39660.lck
│   │       │   ├── ubuntu-18.04-amd64.nvram
│   │       │   ├── ubuntu-18.04-amd64.vmsd
│   │       │   ├── ubuntu-18.04-amd64.vmx
│   │       │   ├── ubuntu-18.04-amd64.vmxf
│   │       │   └── vmware.log
│   │       ├── action_provision
│   │       ├── box_meta
│   │       ├── creator_uid
│   │       ├── forwarded_ports
│   │       ├── id
│   │       ├── index_uuid
│   │       ├── private_key
│   │       ├── synced_folders
│   │       └── vagrant_cwd
│   └── windows
│       └── vmware_desktop
│           └── vagrant_cwd
└── rgloader
    └── loader.rb

17 directories, 40 files
brian@localghost:linux-sandbox %                                                                            ±[master]
brian@localghost:linux-sandbox % ls -lah                                                                    ±[master]
total 20K
drwxr-xr-x  3 brian brian 4.0K Aug 15 15:12 .
drwxr-xr-x 23 brian brian 4.0K Aug 15 14:53 ..
-rw-r--r--  1 brian brian   96 Nov 16  2018 readme.md
drwxr-xr-x  4 brian brian 4.0K Aug 15 15:12 .vagrant
-rw-r--r--  1 brian brian  915 Aug  7 14:02 Vagrantfile
brian@localghost:linux-sandbox % cp readme.md Vagrantfile .vagrant ../a-different-dir                       ±[master]
cp: -r not specified; omitting directory '.vagrant'
brian@localghost:linux-sandbox % cp -r readme.md Vagrantfile .vagrant ../a-different-dir                    ±[master]
brian@localghost:linux-sandbox % cd ../a-different-dir                               
brian@localghost:a-different-dir % be vagrant up ubuntu --provider vmware_desktop                        ±[●][master]
Bringing machine 'ubuntu' up with 'vmware_desktop' provider...
==> ubuntu: This machine used to live in /home/brian/code/vagrant-sandbox/linux-sandbox but it's now at /home/brian/code/vagrant-sandbox/a-different-dir.
==> ubuntu: Depending on your current provider you may need to change the name of
==> ubuntu: the machine to run it as a different machine.
==> ubuntu: Checking if box 'bento/ubuntu-18.04' version '201906.18.0' is up to date...
==> ubuntu: Machine is already running.
brian@localghost:a-different-dir % be vagrant status                                                     ±[●][master]
Current machine states:

ubuntu                    running (vmware_desktop)
hashicorp                 not created (virtualbox)
windows                   not created (vmware_desktop)
docker-1                  not created (docker)
docker-2                  not created (docker)
docker-3                  not created (docker)

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.
phillipswdc commented 5 years ago

That's a good question, I am not sure if each time it was halted. I did however just test and made sure the original was not running. Copying over to the external drive still resulted in the same thing.

Odd thing is that if there is a copy on my internal hard drive and it has not changed, the version I copy over works perfectly.

briancain commented 5 years ago

@phillipswdc another thing that might be worth trying is to halt the vm, and use terminal to copy the files rather than finder. I was able to get that to work just fine, although I did not try to copy from an internal to external HD.

phillipswdc commented 5 years ago

Here is what I did

  1. cd local directory
  2. vagrant halt
  3. cd ..; cp -r directory /Volumes/portable/directory
  4. cd /Volumes/portable/directory
  5. vagrant status = not running

Great, now I remove the original directory and then go back to terminal type vagrant status and it says it is not created and vmware_fusion is cleared out.

It is looking like my external hard drive is the Bermuda triangle. Files go in and they disappear!!

zouyonghao commented 3 months ago

I did a similar thing today. I moved a created vagrant vm (VirtualBox) to another machine (Linux to Linux). I failed several times and finally got it work with the following steps:

  1. create a same user in the target machine
  2. copy ~/.vagrant.d ~/VirtualBox VMs <project_folder> ~/.config/virtualbox
  3. change the <project_folder>/.vagrant/machines/.../virtualbox/creator_uid to the uid in the target machine
  4. try vagrant status, if it's not working, copy the <project_folder>/.vagrant folder and change uid again

For changing directories, I think it's much more complex. You need to change several configuration files in .vagrant, <project_folder>/.vagrant.d and .config/virtualbox or vmware config files.