Ever wondered how Vagrant shared folders work in the background with NFS on a Mac host?
It's pretty straight forward, so let's dive in.
Step1. Mac Host:
- supposing that you are using VirtualBox, just add a Host-Only interface to the Ubuntu/Debian Guest VM, usually the Host-Only interface has the following gateway IP
192.168.33.1
Step2. Ubuntu/Debian Guest VM:
- Add the followings to
/etc/network/interfaces
auto eth1
iface eth1 inet static
address 192.168.33.120
netmask 255.255.255.0
- Then
cd ~
mkdir myWebApp
Step3. Host:
- First:
cd ~/Sites
mkdir myWebApp
- Then add to
/etc/exports/
:
"/Users/yourMacUser/Sites/myWebApp" 192.168.33.120 -alldirs -mapall=501:20
- Then restart nfsd with
sudo nfsd restart
Step4. Guest:
sudo mount -t nfs 192.168.33.1:"/Users/yourMacUser/Sites/myWebApp" ~/myWebApp
You should now see your Mac Host folder /Users/yourMacUser/Sites/myWebApp
content mounted into your Ubuntu/Debian Guest folder ~/myWebApp
.
Let us know what you think.