This is mainly for my own reference, but here it goes.
1. Share a folder on the host OS
- In VirtualBox, click your OS on the left and click on Settings.
- Click on the Shared Folders tab.
- Click on the folder with the plus on the right.
- Browse to a folder of your choice in the folder path.
- Enter a folder name with no spaces e.g. “Share”.
- Check Auto-mount and Make Permanent, if available.
- Click on OK.
2. Mount the folder in the guest OS
- Create a folder in your guest OS that you want to share.
- Open up Terminal.
- Type in
id
and press ENTER— remember that ID. - Switch to the
root
user usingsudo su
and enter your password. - Browse to the
etc
folder usingcd /etc
. - Edit the
rc.local
file usingvi rc.local
. - Move your cursor right above
exit 0
and press the letter “i” on your keyboard to insert text. - Type in the following:
sudo mount -t vboxsf -o uid=1000,gid=1000 Share /home/username/Documents/Share
- 1000 should match the ID you noted down earlier.
- Share should match the folder name from step 1.
- username should match your Linux username.
- /Documents/Share should be the absolute path of the new folder you created.
- Now hit “ESC”, type
:wq
and hit ENTER to save and quit the file editing.
After you restart the guest OS, your shared folder will be automatically mounted.