Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mounting VirtualBox shared folders on Ubuntu Server 18.04 LTS (Bionic Beaver)

Mounting VirtualBox shared folders on Ubuntu Server 18.04 LTS (Bionic Beaver)

This guide will walk you through the steps on how to setup a VirtualBox shared folder inside your Ubuntu Server guest.

Prerequisites

This guide assumes that you are using the following setup:

You could still make this guide work with other setups (possibly with some modifications to the commands and whatnot). But if you want to do it the way I did then please feel free to use my setup above.

Initial Steps

  • Open VirtualBox

    screenshot

  • Right-click your VM, then click Settings

    screenshot

  • 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 shared 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

  • 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 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
    

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 line to fstab (separated by tabs). Make sure to replace <username> with your username. Save the file.

    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

    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.

Bonus: Using shared folders as Apache root directory

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
    

Note: This setup works fine with Windows hosts. But if you are using Linux or Mac as the host then you may have to set appropriate file permissions on your host directory with chmod in order to make it work.

Still not working?

If you've followed the steps above and it still doesn't work, please let me know by posting a comment below. Please use the following format and be sure to be as detailed as possible so that I can have enough information to help you out.

VirtualBox version: <insert VirtualBox version here>
Host: <OS name> <version>
Guest: <OS name> <version>
Description: <detailed description of the problem>

Do note that I'm mostly a Windows user and I'm not that well versed with Linux but I will do my best to help you out.

@ds-motivo

This comment has been minimized.

Copy link

ds-motivo commented Sep 6, 2019

VirtualBox version: 5.2.6
Host: Win10
Guest: Ubuntu 16.04
Description: sudo mount -t vboxsf shared ~/shared works but "Make the mount folder persistent" instructions do not.

@rsyqvthv

This comment has been minimized.

Copy link

rsyqvthv commented Sep 11, 2019

VirtualBox version: 5.2.32
Host: Win10
Guest: Ubuntu server 18.04
Description: did exactly same with this instruction, but when I mount to shared folder, it won't give me the write permission, it shows purple, not highlighted with green in my console.

before mount :

drwxrwxr-x 2 john john 4096 Sep 11 07:14 shared

after mount:

dr-xr-xr-x 1 root root 65536 Sep 10 19:18 shared

I can't even chmod or chown.

any advice? thanks.

=======================
solved, upgrade virtualbox to 6.0.12, then it works without any adjustment.
so it's more likely having problem in old version of guest additions pack

@Lucetia

This comment has been minimized.

Copy link

Lucetia commented Oct 20, 2019

VirtualBox version: 6.0.12 r133076
Host: Windows 10
Guest: Ubuntu 18.04.3
Description:

I'm having issue with it being permanently mounted.

When I do the following:

shared /home/<username>/shared vboxsf defaults 0 0
I have replaced with lucetia and then on boot it says unable to mount /home/lucetia/shared . Then I have to comment out the line I added for Ubuntu to boot up. I even checked in the terminal and /home/lucetia/shared is accessible. Not sure if there's an additional step or something. I even tried replacing /shared with /vboxsf

If it helps I have my shared folder named: "shared" and my shared folder on virtualbox called "vboxsf" and I'm able to get it to mount temporarily, just not permanently.

@estorgio

This comment has been minimized.

Copy link
Owner Author

estorgio commented Oct 20, 2019

@Lucetia
Did you installed the Guest additions as instructed in the first section? Or it could be that you forgot to add the vboxsf line in /etc/modules.

@Lucetia

This comment has been minimized.

Copy link

Lucetia commented Oct 20, 2019

@Lucetia
Did you installed the Guest additions as instructed in the first section? Or it could be that you forgot to add the vboxsf line in /etc/modules.

Yup, followed everything in the guide and everything works. Just that one particular line causes it to error out on rebooting and commenting it out let's reboot fine and remount.

I do have the other line in the /etc/modules part

@estorgio

This comment has been minimized.

Copy link
Owner Author

estorgio commented Oct 20, 2019

@Lucetia
Can you post (preferably) the log of the boot process here? Or maybe just the screenshot of the error message during the boot process? Maybe we could get a clue from there.

@Lucetia

This comment has been minimized.

Copy link

Lucetia commented Oct 20, 2019

@estorgio

I was going to try to grab a copy of the log, but every time I try all I can get is when it boots correctly (after fixing the fstab thing). Granted my Ubuntu knowledge is like 0.00001% so I'm probably missing the obvious. When the error pops up during boot it's too fast to screenshot and it's just an error line saying can't mount and then everything else checks off [ OK ]

@estorgio

This comment has been minimized.

Copy link
Owner Author

estorgio commented Oct 20, 2019

@Lucetia
Try this to get a copy of a boot log: journalctl -b
https://askubuntu.com/a/821801

@Lucetia

This comment has been minimized.

Copy link

Lucetia commented Oct 20, 2019

@estorgio

Yeah I tried that earlier and it wasn't showing me the information, now it is ><

Here's the main snippet

Oct 19 23:46:27 lucetia-VirtualBox systemd[1060]: Started GNOME Terminal Server.
Oct 19 23:46:33 lucetia-VirtualBox sudo[1989]: lucetia : TTY=pts/0 ; PWD=/home/lucetia ; USER=root ; COMMAND=/bin/mount -t vboxsf vboxsf /home/lucetia/shared
Oct 19 23:46:33 lucetia-VirtualBox sudo[1989]: pam_unix(sudo:session): session opened for user root by (uid=0)
Oct 19 23:46:33 lucetia-VirtualBox kernel: vboxsf: SHFL_FN_MAP_FOLDER failed for '/home/lucetia/vboxsf': share not found
Oct 19 23:46:33 lucetia-VirtualBox kernel: vbsf_read_super_aux err=-6
Oct 19 23:46:33 lucetia-VirtualBox sudo[1989]: pam_unix(sudo:session): session closed for user root

The bold line is roughly what shows up in boot. Here's the pastebin of the whole log (since github doesn't support anything but image attachments).

https://pastebin.com/n0R4mWfC

@estorgio

This comment has been minimized.

Copy link
Owner Author

estorgio commented Oct 20, 2019

@Lucetia
From what I can understand from the logs it seems that the vboxsf module that comes with Guest Additions works just fine.

Oct 19 23:43:16 lucetia-VirtualBox kernel: vboxsf: g_fHostFeatures=0x8000000f g_fSfFeatures=0x1 g_uSfLastFunction=29
Oct 19 23:43:16 lucetia-VirtualBox kernel: vboxsf: Successfully loaded version 6.0.12
Oct 19 23:43:16 lucetia-VirtualBox kernel: vboxsf: Successfully loaded version 6.0.12 on 5.0.0-31-generic SMP mod_unload

The only problem is that it tries to look for a shared folder named shared in the VM but couldn't find it.

Oct 19 23:43:16 lucetia-VirtualBox kernel: Adding 2097148k swap on /swapfile.  Priority:-2 extents:6 across:2260988k FS
Oct 19 23:43:16 lucetia-VirtualBox kernel: vboxsf: SHFL_FN_MAP_FOLDER failed for 'shared': share not found

In Add Share step, did you used shared too?

sample

I think the first column in /etc/fstab should match what you've supplied in Folder Name field in Add Share prompt (bolded below).

shared /home/<username>/shared vboxsf defaults 0 0

@Lucetia

This comment has been minimized.

Copy link

Lucetia commented Oct 20, 2019

@estorgio

Changing the first shared to match the name of the folder worked perfectly. I knew somewhere shared had to be changed to match, but I never thought that spot as I thought it was part of some call command for that line.

@estorgio

This comment has been minimized.

Copy link
Owner Author

estorgio commented Oct 20, 2019

@Lucetia
Glad that worked out well for you.

@wargodz009

This comment has been minimized.

Copy link

wargodz009 commented Oct 22, 2019

works great. thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.