Skip to content

Vagrant Odds and Ends

Harry Goldschmitt edited this page Nov 1, 2020 · 3 revisions

Vagrant Command Line Interface

Please view the Vagant Command Line Interface page for a detailed explanation of Vagrant commands.

Vagrantfile Modifications

The Vagrantfile is a text file, and can be easily modified to change memory size, number of CPUs, hostname, etc. Use the Vagrantfile page as well as your favorite search engine to see what can be modified.

Common Vagrantfile Modifications

The following sections illustrate common modifications to that can be made to Vagrantfiles. Many have not been made, since they may adversely effect performance on some host machines. Ensure the working Vagrantfile is saved the before making modifications, so it can be recovered. Then after the modifications are made, issue:

vagrant validate

to make sure the syntax is correct. Vagrantfile modifications will not take effect until after the box is restarted via the:

vagrant halt  
vagrant up

sequence.

Multiple gmat2020a_box Boxes

The gmat2020a_box Vagrantfile comes its host name predefined to gmat2020a-box and with three localhost network ports predefined. One each for ssh, rdp and vnc.

If you want to create a second gmat2020a_box Vagrant box on your host, for example, gmat2020a_box_2, follow these steps:

Clone the gmat2020a_box repository to a new gmat2020a_box_2 directory by issuing:

git clone https://github.com/digitalsats/gmat2020a_box gmat2020a_box_2

from your home direcory. Or use your git GUI command to clone a different copy of the repository.

Edit the gmat2020a_box_2/Vagrantfile using any text editor to make the following changes:

  • Change all instances of gmat2020a-box to gmat2020a-box-2.
  • Find all lines containing "config.vm.network" and change the "host: nnnn" to a different port number. For example, change the line:
config.vm.network "forwarded\_port", guest: 22, host: 2222, id: 'ssh'

to:

config.vm.network "forwarded\_port", guest: 22, host: 2221, id: 'ssh'
  • Change all lines containing "gmat2020a_box" to "gmat2020a_box_2"

Issue:

vagrant validate

to make sure the syntax is correct.

Issue:

vagrant up  

to start the box.

VirtualBox Box Memory

To alter the gmat_box's virtual memory modify its Vagrantfile statement:

vb.memory = "3072"

To the size you desire. The numeric portion is in megabytes.

Number of CPUs

To alter the gmat2020a_box's number of CPUs, add a statement after the Vagrantfile vb.memory statement containing:

vb.cpus = "n"

where n is the number of CPUs you want the box to have. Be somewhat conservative. If your host has 8 cores, do not specify 8, so you can access your host without undue delays.

Restart the Box After Vagrantfile Modifications

Always issue the following command sequence from the directory containing the modified Vagrantfile after making changes:

vagrant validate
vagrant halt
vagrant up

Disk Size Work Arounds

This section applies only to Linux and OSx.

Vagrant will download its boxes and other files to ~/.vagrant.d by default. If your home directory is on a storage constrained drive and you have another drive, it is possible to set up an alternative location for Vagrant's use. Point Vagrant to the desired folder, either with a symbolic link or by adding a shell environment variable.

Create a folder on another drive, by issuing the following command:

mkdir -p [path to desired directory]

If you want to use a symlink enter:

ln -s [path to desired directory] .vagrant.d

If you want to add a shell environment variable:

  • Edit the shell start up file in your home directory [either .bashrc or .zshrc, depending on OSx release] and add the following line:
export VAGRANT_HOME=[path to desired directory]

After saving the file enter:

source ~/.bashrc

or

source ~/.zshrc