My work machine runs Windows (go ahead and laugh. I’ll wait). While I’ve been able to tweak the machine and get a moderately acceptable setup, there are times when I’d really like to use Linux for something, so I spin up a virtual machine with VirtualBox. While that works, I don’t really like having source code — especially with changes in flight — on the VM, as it makes it a bit more dangerous/difficlt to destroy the VM should I need the disk space (which happens more often than I’d like). I set out, then to get shared folders working so I can keep the source on my host machine, and just do the work in the VM. Unfortunately, it doesn’t seem to be as simple as adding a shared folder to the VirtualBox config. This post, then, will detail the steps I took to make things work for me.
The zeroth step, clearly, is to set up the VM. I’ll not cover that here (though perhaps I can in another post if there’s interest, but it seems to be a well-covered topic already). Once you have a working VM, we need to make our configuration changes.
Step 1 (which I did with the VM shut down, though that’s not strictly necessary), is to configure the shared folders. From the VirtualBox Manager window, we need to select the VM we want to modify, and select the Shared Folders tab:
From here, we need to click the Add a folder button on the right, and specify the host directory (Folder Path) and the… device name (Folder Name) by which the folder is exposed to the guest:
Once we’ve configured that, we can boot the VM if it’s not already running. From a command prompt, we need to make some system changes. The most important thing is to verify that the VirtualBox guest additions are installed. Like setting up the VM, this is well documented elsewhere, so I’ll leave that as an exercise for the reader, but I will offer these simple commands that installed the GA for me on my Fedora VM:
I can then mount the shard folder via mount -a. If you get a message about a protocol error, verify that the device name/label given in column 1 in the fstab entry matches the Folder Name given in the VirtualBox configuration.
At this point, you should be ready to start using the shared folder like any other local directory. I typically reboot the VM to verify that I have all the bits in the right places while the effort is still fresh in my mind, but that’s totally optional.
Have I overlooked anything? Is there a simpler approach? Feel free to sound off in the comments!