VMWARE + LINUX: How to share folder between host and VM
This is a quick article about a recurring question: How can I share a local directory with my VMware Virtual Machine using a Linux Distribution?
PRE-REQUISITE
To make this tutorial possible, first of all you need be sure you have installed vmtools drivers. In case you are not sure, please execute:
### UBUNTU OR DEBIAN DISTRIBUTION ###
$ sudo apt-get install open-vm-tools open-vm-tools-desktop$ sudo apt-get install build-essential module-assistant linux-headers-virtual linux-image-virtual && dpkg-reconfigure open-vm-tools### CENTOS DISTRIBUTION ###
$ sudo yum install open-vm-tools open-vm-tools-desktop$ sudo yuminstall build-essential module-assistant linux-headers-virtual linux-image-virtual && dpkg-reconfigure open-vm-tools
STEP-BY-STEP
First we need to share a local folder using your VMware. Go to VM menu, after Settings > Options > Shared Folders and click on ‘Always enabled’. After, click on ‘Add…’ button and choose your local folder to share it.
In order to confirm if your local selected folder was really shared, run the below command and check if your folder will be listed.
vmware-hgfsclient
After that, create a directory inside /mnt/hgfs. Thus, open your terminal in order to create a directory called ‘shared’ and execute the following command.
mkdir /mnt/hgfs/shared
Now, let’s share the ‘shared’ directory we just created.
sudo vmhgfs-fuse .host:/shared /mnt/hgfs/shared -o allow_other -o uid=1000
That’s it! It is sharing and you can check it by clicking on Activities > Files > Other locations > Computer or running the commands:
$ cd /mnt/hgfs/shared$ ls -lia
If you have experiencing some issues, please restart your VM and check again if the folder is shared following the above commands.
Keeping Sharing After VM Re-start
The procedure instructed above work until the next VM restart. Thus, if you want to persist this change, please follow as instructed below.
You must have administrator permission to edit /etc/fstab. In this example, we will use nano editor.
sudo nano /etc/fstab
If you do not have a section reserved to shared folders, please add this instructions at the end of the file.
# Use shared folders between VMWare guest and host
.host:/shared /mnt/hgfs/shared fuse.vmhgfs-fuse defaults,allow_other,uid=1000 0 0
After edit it, press CTRL + O simultaneously and press ENTER to confirm the changes. Next, press CTRL + X to exit nano editor.
Now you can turn your VM off or simply restart it without lose the sharing.