Issue using Vagrant SSH when vagrant.d folder is on an external exFAT drive - vagrant

Setting up Vagrant for the first time and I'm using the VAGRANT_HOME environment variable to change the location of the ~/.vagrant.d folder to an external drive (I'm paranoid about SSD wear and tear, sue me). This is causing an issue with the vagrant ssh command as it's complaining about not having the right permissions and I can't use chmod to change the permissions for the file it wants on an exFAT volume.
Is there a workaround? I've checked the documentation and there doesn't seem to be a setting where I can specify a different location for the insecure key, but I might be missing something.
Thanks!

The solution is to move the insecure_private_key file located in the external vagrant.d folder to somewhere in your local home directory and then symlink it back.

Related

What is the logical/conceptual difference between .vagrant and .vagrant.d directory?

I want to know logical/conceptual difference between .vagrant and .vagrant.d directory
And also, what is the difference between the following keys
(Please observe the path of these two) one of which is placed in .vagrant directory and the other one in .vagrant.d directory in Windows 7?
C:\Users\username**.vagrant**\machines\default\virtualbox\private_key
C:\Users\username**.vagrant.d**\insecure_private_key
Could not find anywhere in the documentation and on the Internet as well. Thanks in advance.
.vagrant.d is usually placed in your home folder and stores system-wide data/settings, i.e. downloaded vagrant boxes.
.vagrant is placed in your environment/project folder and stores project-specific settings, i.e. current VM settings.
So if you work in user/myproject, create Vagrantfile there and exec vagrant up, then user/myproject/.vagrant directory will be created with VM specific data.
.vagrant.d/insecure_private_key is default insecure private key to access your VMs, it's replaced by vagrant on first VM start with private_key from project's .vagrant directory. In your example: private_key for default VM started with virtualbox provider.

Vagrant SSH Permissions

I am new to Vagrant and get the following error on vagrant up or vagrant ssh:
The private key to connect to this box via SSH has invalid permissions
set on it. The permissions of the private key should be set to 0600, otherwise SSH will
ignore the key. Vagrant tried to do this automatically for you but failed. Please set the
permissions on the following file to 0600 and then try running this command again:
[...]/.vagrant/machines/default/virtualbox/private_key
I have run:
$ sudo chmod 666 [...]/.vagrant/machines/default/virtualbox/private_key
I also tried (600, 777) but still get the same error.
Please can someone tell me what is wrong and how to fix it?
I just had this issue, and I worked around it moving the private_key file to another place, changing its permission, and then creating a symbolic link at the original place.
So,
$ mv [...]/.vagrant/machines/default/virtualbox/private_key /some/path/where/you/can/change/permissions
$ ln -s /some/path/where/you/can/change/permissions [...]/.vagrant/machines/default/virtualbox/private_key
If you're using the Windows Subsystem for Linux (WSL), this error can occur when you're trying to vagrant up in a directory that is outside the user's home directory.
From the Vagrant docs:
If a Vagrant project directory is not within the user's home directory on the Windows system, certain actions that include permission checks may fail (like vagrant ssh). When accessing Vagrant projects outside the WSL Vagrant will skip these permission checks when the project path is within the path defined in the VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH environment variable.
Changing the VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH to the current working directory (or a directory above it) can fix this. For example, if your project is in /mnt/c/www, then set the environment variable accordingly:
export VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH="/mnt/c/www"
I got the same error now. The problem happened because i was trying to do vagrant up in an NTFS partition, just like the error message tell me.
So i created an directory link in my ext4 partition and an simbloc link in my NTFS to solve this. Works Fine now!
Thanks!
I had this same problem and turns out chmod seems to be working fine but is not actually changing permissions, my files where at an NTFS partition, try changing them to an ext4 or similar.
Got this error using otto (which layers on vagrant)
It is def filesystem related, have a fat partition to allow use with windows (used to, no longer). When the permissions couldn't be set on the partition I just copied the whole directory over to my user directory (as I always should have).
Was using git so I just reset to head to get back to my starting place... re-ran:
otto compile
otto dev
up and running now.

Cannot access Vagrant shared folders

I just trying to add Vagrant to my workflow and I have following probably noob problem. I pull standard hashicorp standard 14.04 image, vagrant up it, SSH to it install my python requirements on it and then then try to execute build commands against code in Vagrant shared folder and run in to problems. Basic errors I get say those locations don't exist or cannot be found.
First action I, go ls /vagrant and can see my shared folders. I cannot cd to them from Vagrant machine I have tried to halt the machine.
Vagrantfile shared folder code.
{"virtualbox":{"/vagrant":{"guestpath":"/vagrant","hostpath":"/Users/Kimmo/Documents/Mist.io","disabled":false}}}
I am using Virtualbox as provider newest version.
My dev machine is OSX 10.9.5
There are not access limitations on the folder itself.
Thanks for you help in advance :)
Does /vagrant exists inside the VM just after you start it ?
If no you can add this parameter : "create":true. According to the doc, for the create: true paramater : If true, the host path will be created if it does not exist. Defaults to false.
If the folder /vagrant exists but you can cd or ls it, you can add parameters wich will define the right/owner of this folder:
owner: (string) the user who should be the owner of this synced folder. By default this will be the SSH user. Some synced folder types don't support modifying the owner.
group: (string) the group that will own the synced folder. By default this will be the SSH user. Some synced folder types don't support modifying the group.
Also for the hostpath parameter you have to give him a folder path, not a file path. In your conf I can see: "hostpath":"/Users/Kimmo/Documents/Mist.io". If Mist.io is a file and you want to access this file inside your VM, just give the path to the folder containing this file, /Users/Kimmo/Documents in your case.

Vagrant syncing process

I've just started using Vagrant and I've managed to set up a box ok it seems. I have been a little confused about syncing folders work though. I took from Vagrant that syncing allowed you to use the file system on your Mac and then sync those changes into your virtual machine, is that right?
I have these settings currently
config.vm.synced_folder "../../../Library/WebServer/Documents/", "/Users/jonnny/ubuntu-vagrant/www"
I would expect that now that when I look in chrome that inside my 127.0.0.1:1234/www/
That the files within my Library/WebServer/Documents/ would be there. But they're not, have I done it wrong or misunderstood what's going on here?
Update
I wasn't sure what you meant with my file/folder structure, so probably best I just show them.
Users
Jonnny
ubuntu-vagrant
- Vagrantfile
- /www (dir)
- bootstrap.sh
VagrantFile
VirtualBox VMs
- ubuntu-vagrant_342374982374923
- box-disk1.vmdk
- logs (dir)
- ubuntu-vagrant_342374982374923.vbox
I did try your suggestion and reload the box, but the folder still didn't seem synced.
The syntax seems to be correct. But for the second argument, /Users/jonnny/ubuntu-vagrant/www, it should be the targeted location inside the ubuntu filesystem, not the one which will be created on your Mac OS filesystem.
Try something like /www/ or /usr/johnny/www, according to the location you want.
Update
For the vagrant arguments:
the first should be the location of the folder you want to share inside your Mac Os filesystem relatively from where the Vagrantfile is in your Mac Os filesystem.
the second is where inside the ubuntu-vagrant filesystem you want to access these files.
I think your folder structure is not good: you dont need a Vagrantfile folder or a www folder in your Mac OS filesystem. Just consider one folder: the one where the Vagrantfile is, Users/Johhny/ubuntu-vagrant. The www folder will just exists inside the VM. Then if the Library folder is at the same level than the Users folder in your Mac OS filesystem, you should have :
Library
...
Users
Johhny
ubuntu-vagrant
Vagrantfile
bootstrap.sh
And inside the Vagrantfile you should have this line :
config.vm.synced_folder "../../../Library/WebServer/Documents/", "/www", create: true
According to the doc, for the create: true paramater : If true, the host path will be created if it does not exist. Defaults to false.

How can I change where Vagrant looks for its virtual hard drive?

I have Vagrant set up on one of my computers. I would like to change the location of its virtual hard drive, which is currently in the default location. How can I do this without breaking Vagrant?
I have Vagrant set up with VirtualBox 4.2.
EDIT: I mean that I want to move the location of the VirtualBox machine folder, which is currently at C:\Users\Kevin\VirtualBox VMs\my_vm\box-disk1.vmdk.
Not sure if you want to change the ~/.vagrant.d or VirtualBox default machine folder.
If you want to move ~/.vagrant.d to somewhere else. You can set environment variable VAGRANT_HOME, see this https://stackoverflow.com/a/14804694/1801697
Update:
To change VirtualBox's Default Machine Folder, either do it in GUI => Prefs - General - Default Machine Folder or manually edit the ~/.VirtualBox/VirtualBox.xml
<SystemProperties defaultMachineFolder="/path/to/VirtualBox/VMs" defaultHardDiskFormat="VDI" VRDEAuthLibrary="VBoxAuth" webServiceAuthLibrary="VBoxAuth" LogHistoryCount="3"/>
you can use the command :
VBoxManage setproperty machinefolder
here the doc for more information : https://www.virtualbox.org/manual/ch08.html#vboxmanage-setproperty
You have to change your ~/.VirtualBox/VirtualBox.xml defaultMachineFolder "SystemProperty"(see other answer). As the name already suggests this seems to be a system property / environment variable.
If you then run vagrant from an already running windows console the old value is used and even your edited VirtualBox.xml is overwritten!
So make sure to close and open a new CMD-Window. after the change.

Resources