Update 28 July 2019: An updated version of this guide for Ubuntu Server 18.04 LTS is now available. Feel free to check it out.
Update 23 May 2020: This guide is ALREADY OUTDATED and might no longer work with new versions of Ubuntu and VirtualBox. Please consider switching to the updated guide instead. I will no longer respond to the replies to this gist. Thank you.
This guide will walk you through steps on how to setup a VirtualBox shared folder inside your Ubuntu Server guest. Tested on Ubuntu Server 16.04.3 LTS (Xenial Xerus)
-
Open VirtualBox
-
Right-click your VM, then click Settings
-
Go to Shared Folders section
-
Add a new shared folder
-
On Add Share prompt, select the Folder Path in your host that you want to be accessible inside your VM.
-
In the Folder Name field, type
shared
-
Uncheck Read-only and Auto-mount, and check Make Permanent
-
Start your VM
-
Once your VM is up and running, go to Devices menu -> Insert Guest Additions CD image menu
-
Use the following command to mount the CD:
sudo mount /dev/cdrom /media/cdrom
- Install dependencies for VirtualBox guest additions:
sudo apt-get update
sudo apt-get install build-essential linux-headers-`uname -r`
- Run installation script for the guest additions:
sudo /media/cdrom/./VBoxLinuxAdditions.run
- Reboot VM
sudo shutdown -r now
- Create "shared" directory in your home
mkdir ~/shared
- Mount the shared folder from the host to your ~/shared directory
sudo mount -t vboxsf shared ~/shared
- The host folder should now be accessible inside the VM.
cd ~/shared
This directory mount we just made is temporary and it will disappear on next reboot. To make this permanent, we'll set it so that it will mount our ~/shared
directory on system startup
- Edit fstab file in /etc directory
sudo nano /etc/fstab
- Add the following line to fstab (separated by tabs) and press Ctrl+O to Save.
shared /home/<username>/shared vboxsf defaults 0 0
- Edit modules
sudo nano /etc/modules
- Add the following line to
/etc/modules
and save
vboxsf
- Reboot the vm and log-in again
shutdown -r now
- Go to your home directory and check to see if the file is highlighted in green.
cd ~
ls
If it is then congratulations! You successfully linked the directory within your vm with your host folder.
How to point apache's web directory to our folder in the host.
- Remove apache's old
html
directory (WARNING! Backup your data if necessary)
sudo rm -rf /var/www/html
- Add a symbolic link in its place
sudo ln -s ~/shared /var/www/html
I am using VertualBox 6 and Ubuntu 18.04. I do not see a checkbox that says "Make Permanent" as stated in step 7. On step 10 I get "mount: /media/cdrom: mount point does not exist." error, and on step 15 I get "/sbin/mount.vboxsf: mounting failed with the error: Protocol error" error. Let me know if anyone knows what went wrong. Thanks!