VirtualBox is an outstanding solution for anyone needing to deploy virtual machines of all types and for nearly all use cases. You can deploy them as standard servers, a Kubernetes cluster, desktop machines, developer workstations, and more.

VirtualBox includes all of the features you’d need to get your work done. One such feature is shared folders. What this allows you to do is share a folder between a host (the machine running VirtualBox) and a guest (the virtual machine). By creating shared folders between guests and hosts, it’s significantly easier to pass data between the machine and the virtual machine. This setup would allow you to share a single data folder, on a host, between all of your guests.

I want to show you how easy it is to create a shared folder between a host and a guest. I’ll be demonstrating on a Pop!_OS host and a Linux Mint guest, but the process will be similar on any combination of Linux or Windows.

SEE: Incident response policy (TechRepublic Premium)

What you’ll need

To create shared folders with VirtualBox, you’ll need a running instance of VirtualBox and at least one guest up and running.

How to install the Guest Additions

If your guest includes a desktop, installing the Guest Additions is as simple as clicking Devices | Insert Guest Additions CD Image. Once the CD image is mounted, open it in your desktop file manager and double-click the VBoxLinuxAdditions.run (or the equivalent on Windows). If your desktop refuses to run the file, right-click the file and click Open With and select Terminal. If that doesn’t work, right-click on a blank spot within the file manager and click Open In Terminal. When the terminal opens, you can run the file with the command:

sudo ./VBoxLinuxAdditions.run

When the command completes, reboot the guest OS.

If your guest is a GUI-less server, check out my how to for guest additions, How to install VirtualBox Guest Additions on a GUI-less Ubuntu server host.

How to create the shared folder

On your host OS, decide what folder you want to share. You can either select one that’s already present, or create a new folder. You’ll want to make sure the user that runs VirtualBox has both read and write permission for the folder.

Say, for example, you create a data folder with the command:

sudo mkdir /data

Change the ownership of that folder to the same user running VirtualBox with the command:

sudo chown -R $USER:$USER /data

Next, give the user write permission with the command:

chmod -R ug+w /data

How to share the folder with a guest

Now we can create the shared folder within the guest. To do that, log in to your guest, open a terminal window, and issue the command:

sudo usermod -aG vboxsf $USER

Close the terminal, shut down the guest, and then open the Settings window associated with that guest.

In the Settings window, click Shared Folders. In the Shared Folders section, click the + button in the right sidebar (Figure A).

Figure A

The Shared Folders section of the guest Settings window.

In the Add Share popup, type the full path to the shared folder in the Folder Path section. For our example, we’d type:

/data

Check the box for Auto-Mount and then type the path for the location you want the shared folder to be found in the guest. Say you want the host /data folder to be mounted in the Documents folder of your user. For that you’d type:

/home/USER/Documents

Where USER is the actual username on the guest. If you decide to create a new directory on the guest, you’ll need to create that directory before adding the share, making sure to give the new directory proper permissions.

When this is complete, click OK to save the shared folder.

Start the guest and log in. Open your file manager and you should see all files and subfolders that reside on the host, in the mounted guest folder.

And that’s all there is to sharing a folder between a VirtualBox host and guest. This should make your virtual machine work considerably easier.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.


Image: Jack Wallen

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays