Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save viper25/86c0f6fc0d35f4277cdeba259820c1d8 to your computer and use it in GitHub Desktop.
Save viper25/86c0f6fc0d35f4277cdeba259820c1d8 to your computer and use it in GitHub Desktop.
Mounting VirtualBox shared folders on Ubuntu

Mounting VirtualBox shared folders on ubuntu-18.10-desktop-amd64

This guide will walk you through steps on how to setup a VirtualBox shared folder inside your Ubuntu Server guest. Tested on ubuntu-18.10-desktop-amd64

Steps:

  1. Open VirtualBox

  2. Right-click your VM, then click Settings

  3. Go to Shared Folders section

  4. Add a new shared folder

  5. On Add Share prompt, select the Folder Path in your host that you want to be accessible inside your VM.

  6. In the Folder Name field, type shared

  7. Uncheck Read-only and Auto-mount, and check Make Permanent

  8. Start your VM

  9. Once your VM is up and running, go to Devices menu -> Insert Guest Additions CD image menu

  10. Use the following command to mount the CD:

sudo mount /dev/cdrom /media/cdrom
  1. Install dependencies for VirtualBox guest additions:
sudo apt-get update
sudo apt-get install build-essential linux-headers-`uname -r`
  1. Run installation script for the guest additions.
sudo /media/cdrom/./VBoxLinuxAdditions.run

If this isn't the first time, it may have already been mounted. If so, you should see an icon on the Desktop. Open that location in a terminal:

cd /media/<username>/VBox_GAs_6.0.4
sudo ./VBoxLinuxAdditions.run
  1. Reboot VM
sudo shutdown -r now
  1. Create "shared" directory in your home
mkdir ~/shared
  1. Mount the shared folder from the host (named as VM_shared_folder) to your ~/shared directory
sudo mount -t vboxsf VM_shared_folder ~/shared
  1. The host folder should now be accessible inside the VM.
cd ~/shared

Make the mount folder persistent

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

  1. Edit fstab file in /etc directory
sudo nano /etc/fstab
  1. Add the following line to fstab (separated by tabs) and press Ctrl+O to Save.
shared	/home/<username>/shared	vboxsf	defaults	0	0
  1. Edit modules
sudo nano /etc/modules
  1. Add the following line to /etc/modules and save
vboxsf
  1. Reboot the vm and log-in again
shutdown -r now
  1. 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.

Bonus:

How to point apache's web directory to our folder in the host.

  1. Remove apache's old html directory (WARNING! Backup your data if necessary)
sudo rm -rf /var/www/html	
  1. Add a symbolic link in its place
sudo ln -s ~/shared /var/www/html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment