1. Home
  2. Linux
  3. Share files in virtualbox machine on linux

How To Share Files In A VirtualBox Machine On Linux

Setting up a virtual machine in Oracle VM VirtualBox is easy, but sharing files with it? Not so much. It is because of how annoying and difficult file sharing between guest and host machines is (especially on Linux) that we’re going to cover it today. We’ll go over how to share files in VirtualBox from a host machine to a guest machine over USB, the Network and straight from the host PC to the Guest PC, but first we’ll need to install the Guest Additions.

Guest Additions

Be sure that you’ve got a Virtual Machine already installed and setup under Linux. Not sure how to do that? Check out our guide all about using VirtualBox on Linux. Once you’ve got a machine up and running, look for the “Device” menu and click on it. Inside the input menu, find “insert guest additions”. This will tell VirtualBox to go out, download and insert the latest version of “guest additions”, something that allows Host machines to more easily interact with Guest machines.

Follow the auto-run prompt dialog, and install the Guest Additions to your Virtual Machine. This is critical because without the Guest Additions, interacting between the host machine and guest machine become very difficult.

When the installation is complete, reboot the virtual machine.

Share Files In VirtualBox

The easiest and fastest way to share files from the PC hosting the VM to the VM itself is to just expose the VM to the file system that it is running from. To do this, first, make sure that the VM is turned off. This isn’t required, but doing so makes it easier to modify settings.

In the main VirtualBox window, right-click on the VM, and select “Settings”.  Look at the bottom of the VBox settings window for “Shared Folders” and select it. Under the shared folders window, it is possible to create shared folders for the Guest VM to read. Click the blue folder with the green + icon on it to make a new share.

First, go to “Folder Path” and click the arrow. This exposes a drop-down menu, with “Other”. Select it to bring up a file browser, and use it to navigate to the folder location on your Linux PC you’d like to share.

Check the “Auto-mount” button to have the VM automatically mount the share at boot. Additionally, select the “Read-only” box if you’d like to prevent the Guest VM from changing any files or folders on the share.

To access the shared folder in the file manager, go to /media/sharename

For example, to access Personal, you’d do: /media/Personal, and etc.

Want to access it in the terminal? Use CD and navigate to /media/sharename.

Even though VirtualBox automatically mounts shared folders at startup, your files may not be there. The best way to make sure that they are is to run:

sudo mount -t vboxsf -o uid=$UID,gid=$(id -g) share-name /home/username/vbox/desired/share/mount/folder

Sharing Files Via USB

In addition to sharing files directly from the Host PC to the Guest virtual PC, it is possible to transfer files via connected USB devices. To enable support for this feature, first go to the VirtualBox official website, and download the extension pack. This pack, when installed, adds support for USB devices, as well as RDP, disk encryption, support for NVMe SSDs, and etc.

On the downloads page, scroll down and look for “Oracle VM VirtualBox Extension Pack”. VirtualBox doesn’t distribute this extension pack specific to an operating-system, so it can be installed on Linux, as well as any other operating system that VirtualBox can run on.

To install the package, open up the file manager and double-click on the file. Doing so will instantly launch an install dialog inside of VirtualBox. Follow the instructions that appear to finish installing the package. When done, right-click on the VM you’d like to add USB devices onto and select the “settings” button.

Under the settings window, select the “USB” icon, to move to the USB controller settings. In the USB settings area, it is possible to give the virtual machine direct access to the USB controller. Select from “USB 1.0, 2.0 or 3.0” depending on the USB hub on your PC, and then move on down to the blue USB icon with the green + sign to manually add a USB device.

Adding Devices On The Fly

Often times, it’s faster to plug in USB devices, then manually add each one of them to the system. It makes it easier to access them right away. However, if you’re constantly hot-swapping USB storage devices with the guest virtual machine, it may be better to add devices another way.

First, start up the guest virtual machine, and boot it up normally. From here, plug in any USB devices you’d like to connect to the system. Then, look to the bottom right of the VM window for a USB icon. Right-click the icon to reveal any connected USB devices. Click on any device that appears in the menu to connect it to the machine.

When the device is directly connected to the Guest machine, everything should be usable. Access files via the file manager (or Explorer window if you’re running a version of Windows).

1 Comment