After installing a Linux distro into a VirtualBox virtual machine, you may be wondering how to share files between the host operating syste and the virtual machine itself. One of the easiest and most convenient ways to provide this function is by setting up a VirtualBox shared folder.
Essentially this means that a folder on your host machine can be mounted on the virtual machine, where both systems will be able to access files or drop them in the folder. It doesn't matter what host operating system you're using, as the instructions will be the same across Linux, Windows, etc.
In this guide, we'll go through the step by step instructions to configure a shared VirtualBox folder. We'll also show you how to mount the shared folder on your Linux system, allowing you to easily share files back and forth.In this tutorial you will learn:
- How to configure a shared VirtualBox folder on Linux
- How to mount a VirtualBox shared folder
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Software||VirtualBox, VirtualBox Guest Additions|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
Prerequisites for VirtualBox shared folder
Before we get started, there are a couple of prerequisites to consider. First, we're assuming in this guide that your guest operating system (the one installed in the virtual machine) is Linux. The host operating system is mostly irrelevant, but in this guide, our host system is Ubuntu. You can follow along just fine even if you are running a different distro.
The second thing to keep in mind is that you must have VirtualBox Guest Additions installed in the virtual machine. This is pretty trivial to install, and you can check out our guide on installing VirtualBox Guest Additions if you need some help.
Configure VirtualBox shared folder
Follow the step by step instructions below to configure a VirtualBox shared folder.
- Before your start your guest operating system, you need to change its settings. Specifically, we need to define the location of the shared folder first. Open the VM Settings and go to Shared Folders on your host operating system.
- Click on the Add button (plus sign) and specify a directory you wish to share with the guest operating system. Next you would need to define a name of this folder. The name will be used by a mount command later when mounting shared folder. You'll also need to choose where to mount the folder on the guest system. For the sake of convenience, it's recommended that you also check the "auto mount" option. In this example we will use the following settings:
- Once you have saved these settings, boot into the virtual machine. You should find that your shared directly was automatically mounted and that you can now share files with the host operating system. If you did not choose the auto mount option, we'll show you how to manually mount the VirtualBox share. Open a terminal and create a directory where you wish to mount your VirtualBox shared folder. If we want to, for example, mount VirtualBox shared folder into
/home/linuxconfig/sharewe need to first create this directory.
$ mkdir /home/linuxconfig/shareNow that mount directory is ready we can mount VirtualBox shared folder.
$ sudo mount -t vboxsf share /home/linuxconfig/shareNote that "share" is the name you have defined when creating a VirtualBox shared folder in the previous steps. Now simply navigate to your home directory and your
/home/linuxconfig/sharefolder and you should see your shared across.
Mount VirtualBox Shared Folder permanently
Once you restart your guest operating system to get access to your VirtualBox shared folder again you need to mount it again with the above command. To make this mount permanent add the following line into your
/etc/fstab file, while changing the directory path to reflect your own configuration:
share /home/myusername/share vboxsf uid=1000,gid=1000 0 0
uid=1000,gid=1000 will make you an owner of all files within the VirtualBox shared folder. Moreover, you can use mount options for more settings such as read-only and so on.
In this guide, we saw how to configure a VirtualBox shared folder, which makes it easy and convenient to share files between a host operating system and virtual machine. We also saw how to automatically mount the shared folder, or manually mount it and to make the mount persistent across reboots. You've just extended the functionality of your VirtualBox virtual machine in a few short steps.