VirtualBox – Mount a ‘Shared Folder’ under Linux

Wiki version:

1) Define Shared Folder

Shared folders are defined via the VirtualBox virtual machine menu: MENU: Devices -> Add Shared Folder Settings… -> BUTTON: Add / Edit.

In the appearing dialog box, specify the Folder Path pointing to the host folder to be shared with the guest, and the Folder Name as the logical device name used in the guest system for this folder.

In this example, the shared folder name is ‘vb’.

2) Virtual Box Guest Additions

The VirtualBox Guest Additions must be installed to allow sharing folders between host and guest. If not done, insert the virtual CD via MENU: Device -> Insert Guest Additions CD Image…. The drive should out-mount and you need to run the installation as root.

The VirtualBox Guest Additions tool installs a new virtual device type allowing to bridge to the host: vboxsf.

Note: If you do security research, be careful with installing the VirtualBox Guest Additions. First, this might be a security risk since the guest system is modified in order to allow bridging back to the host system, and secondly, there are good chances that malware scans for the presence of these tools to verify if it is actually running in a virtual (analysis) environment.

3) Restart

If you VM was running during step 1), you need to restart it in order for the new virtual device type to become active.

4) Mount the Shared Folder

tasha@ATREIDES ~ $ # Show the new device type
tasha@ATREIDES ~ $ ls /sbin/mount.vboxsf

tasha@ATREIDES ~ $ # List all devices of type 'vboxsf' known to the guest OS.
tasha@ATREIDES ~ $ #    -t = "of type"
tasha@ATREIDES ~ $ #    -l = list devices
tasha@ATREIDES ~ $ #    vboxsf = VirtualBox Shared Folder
tasha@ATREIDES ~ $ #
tasha@ATREIDES ~ $ # Result: 'vb' is the name of the shared folder as defined in 1)
tasha@ATREIDES ~ $ #
tasha@ATREIDES ~ $ mount -t vboxsf -l
vb on /media/sf_vb type vboxsf (gid=111,rw)

tasha@ATREIDES ~ $ # Create a mount point
tasha@ATREIDES ~ $ # This is a directory that will be redirected to the mounted device,
tasha@ATREIDES ~ $ # ie. the shared folder 
tasha@ATREIDES ~ $ sudo mkdir /vbshare 

tasha@ATREIDES ~ $ # Mount the device/folder 
tasha@ATREIDES ~ $ #   'vb' = folder name in the VirtualBox settings and device name 
tasha@ATREIDES ~ $ #   '/vbshare' = local mount point 
tasha@ATREIDES ~ $ sudo mount -t vboxsf vb /vbshare 

tasha@ATREIDES ~ $ # Access shared folder 
tasha@ATREIDES ~ $ cd /vbshare 
tasha@ATREIDES ~ $ ls /vbshare 

Note: The mount operation must be repeated at each system start, when not included in the boot scripts.

Leave a Reply

Your email address will not be published. Required fields are marked *