Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rkaiser0324/a31f1fbdaccb546255a718718a2a148e to your computer and use it in GitHub Desktop.
Save rkaiser0324/a31f1fbdaccb546255a718718a2a148e to your computer and use it in GitHub Desktop.
Mounting VirtualBox shared folders on an Ubuntu VM

Mounting VirtualBox shared folders on an Ubuntu guest

This guide will walk you through the steps on how to setup a VirtualBox shared folder inside an Ubuntu VM that has been exported from an AWS EC2 instance.

Prerequisites

This guide assumes that you are using the following setup:

Initial Steps

  • Open VirtualBox

    screenshot

  • Right-click your VM, then click Settings

    screenshot

  • Add an optical drive as Secondary Slave, left empty

  • Go to Shared Folders section

    screenshot

  • Add a new shared folder

    screenshot

  • On Add Share prompt, select the Folder Path in your host that you want to be accessible inside your VM. Type projects for the Folder Name. Make sure that Read-only and Auto-mount are unchecked and Mount point is blank. Then click OK.

    screenshot

  • Start your VM

    screenshot

  • Boot and wait a few minutes for all the /latest/meta-data/instance-id pings to timeout

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

    screenshot

  • Use the following command to mount the CD

    sudo mkdir /media/cdrom
    sudo mount -t iso9660 /dev/cdrom /media/cdrom
    
  • Install dependencies for VirtualBox guest additions

    sudo apt-get update
    sudo apt-get install -y build-essential linux-headers-`uname -r`
    
  • Run the installation script for the guest additions. Wait until the installation completes.

    sudo /media/cdrom/./VBoxLinuxAdditions.run
    
  • Reboot VM

    sudo shutdown -r now
    
  • Create projects directory in your home

    mkdir -p /media/projects
    
  • Mount the shared projects folder from the host

    sudo mount -t vboxsf projects /media/projects
    
  • The host folder should now be accessible inside the VM.

    ls -l /media/projects
    

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

  • Edit fstab file in /etc directory

    sudo nano /etc/fstab
    
  • Add the following to fstab

    projects	/media/projects	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

    sudo shutdown -r now
    
  • Go to your home directory and check to see if the directory is highlighted in green.

    screenshot

If it is then congratulations! You successfully linked the directory within your VM with your host folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment