Running Vagrant + VirtualBox from an External Drive

I have a MacBook Air with a 128 GB SSD, so I'm always in a bit of a crunch for space on my hard drive. Developing with local VMs provisioned by Vagrant and VirtualBox makes my Drupal (and other) development experience great, but it also quickly fills up the (tiny amount of) remaining space on my SSD!

Here's how you can move your Vagrant files and VirtualBox VMs out of your home folder onto an external hard drive:

  1. Copy the .vagrant.d folder from your home folder (~/.vagrant.d) to your external drive (I renamed the folder to vagrant_home:
    cp -R ~/.vagrant.d /Volumes/[VOLUME_NAME]/vagrant_home"
  2. Delete the .vagrant.d folder from your home folder:
    rm -rf ~/vagrant.d
  3. Edit your .bash_profile file, and add the following line (example for Mac OS X):
    export VAGRANT_HOME="/Volumes/[VOLUME_NAME]/vagrant_home"
  4. Open VirtualBox, go to Preferences, and set the Default Machine Folder to a location on your external hard drive (I created a new folder called 'VirtualBox VMs').

At this point, if you download new base boxes, or provision new VMs, they should be on your external drive. (This assumes that you didn't have any existing VMs that you needed to move; in that case, read Moving VirtualBox and Vagrant to an external drive.

Caveats

Unfortunately, there are a couple of downsides to storing VMs externally like this:

  • You have to have your hard drive plugged in at all times when running your VMs. (A quick vagrant suspend, at a minimum, is required before unmounting a drive).
  • You will need to set the VAGRANT_HOME variable differently for home and work if you use different drives at home and work.

One more note: if you're on a Mac or Linux machine, make sure you use NFS instead of the native folder syncing method. When running a drupal codebase with thousands of files under a shared directory, you'll easily notice at least a 10x or 100x speedup!

Comments

This had been working nicely, but subsequent to updating to Big Sur, can't seem to get past:

```
mount -o vers=3,udp 192.168.50.1:/System/Volumes/Data/Volumes/Oggun/Clients/CharlieMason/Elliptica/ellipticastudios.com/site /vagrant-nfs-ellip
# VAGRANT-BEGIN: 501 7842c596-12a8-4a37-960a-720cec16bbd0
ticastudios.com

Stdout from the command:

Stderr from the command:

mount.nfs: access denied by server while mounting 192.168.50.1:/System/Volumes/Data/Volumes/MyExternalDrive/path/to/site
```