Sharing a folder between a Linux host and Sabayon Linux as the guest OS in a VirtualBox VM

You probably know that you need to install the VirtualBox Guest Additions in the guest OS in order share a folder between a host OS and a guest OS in a VirtualBox VM. However, of late I have found that shared folders do not work when the guest OS is any of the Sabayon Linux spins, even though I had installed the Entropy package app-emulation/virtualbox-guest-additions and ensured the user in the guest OS is a member of the vboxsf group. Fortunately, it is not difficult to fix this, and below is the procedure I use to get a Sabayon Linux guest to share folders with a Linux host.

Let us say that your username in the host OS is ‘brian‘ and you have created a directory named /home/brian/Shared-brian/ that you want to share with the guest OS (Sabayon Linux), and the username in the guest OS is ‘fitzcarraldo‘.

1. In the VM VirtualBox Manager window, select ‘Settings’ > ‘Shared Folders’ for the VM. Click on ‘Machine Folders’ in the Folders List and then on the ‘Add New Shared Folder’ icon. Specify the folder path /home/brian/Shared-brian, and tick ‘Auto-mount’ and ‘Make Permanent’.

2. Start the VM, login as user fitzcarraldo and open a terminal window. If /boot is on a separate partition, make sure it is mounted.

3. Use the usual Entropy package manager commands to bring the guest OS installation up to date and to install the latest Sabayon Linux kernel image (see one of my earlier posts), then reboot the VM. If /boot is on a separate partition, make sure it is mounted.

4. If the VirtualBox Guest Additions package from the Sabayon Linux Entropy repository is currently installed in the guest OS, uninstall it. If the package has not yet been installed, install it and then uninstall it.

fitzcarraldo@sabayon ~ $ sudo equo remove virtualbox-guest-additions

5. Check if you are in the ‘vboxsf’ and ‘vboxguest’ groups:

fitzcarraldo@sabayon ~ $ groups

If you are not, add the user to the two groups:

fitzcarraldo@sabayon ~ $ sudo usermod -a -G vboxsf,vboxguest fitzcarraldo

6. Check if the latest GNU compiler collection and kernel sources have been installed. If not, install them:

fitzcarraldo@sabayon ~ $ sudo equo install sabayon-sources gcc

7. Check if the Linux kernel headers have been installed. If not, install that package too:

fitzcarraldo@sabayon ~ $ sudo install linux-headers

8. In the menu bar of the VM’s window, select ‘Devices’ > ‘Insert Guest Additions CD Image…’. If you are asked if you want to download the disk image file from the Internet, click on ‘Download’.

9. Use the guest OS’s File Manager to check that the Guest Additions virtual CD is mounted. If it is not, use the File Manager to mount it.

10. Install the VirtualBox Guest Additions from the virtual CD:

fitzcarraldo@sabayon ~ $ sudo /run/media/fitzcarraldo/VBOXADDITIONS_5.1.34_121010/

Ignore any warning message about the remnants of an existing version of the Guest Addtions still being installed. Answer ‘yes‘ to the prompt ‘Do you wish to continue [yes or no]‘. There should be no error messages in the terminal output if the GCC, kernel sources and linux kernel headers have already been installed (see the earlier steps above).

11. Reboot the VM and login.

12. In the directory /media/sf_Shared-brian/ in the guest OS you should now see the files that are in the shared folder /home/brian/Shared-brian/ in the host OS. VirtualBox automatically adds the ‘sf_‘ suffix to the directory name in the guest OS, and it stands for ‘shared folder’.

13. In file managers such as GNOME’s Nautilus, MATE’s Caja, LXDE/LXQt’s PCManFM and Xfce’s Thunar you should see the folder /media/sf_Shared-brian listed in the left panel. In KDE’s Dolphin you can right-click in the left panel and add an entry for /media/sf_Shared-brian or, optionally, right-click in the main window and select ‘Create New’ > ‘Basic link to file or directory…’ and create a link in your home directory to /media/sf_Shared-brian/.

I have used the above procedure with recent spins of Sabayon Linux (KDE, GNOME, MATE, Xfce and LXQt), and it works consistently.

How to stop the clock in a VirtualBox virtual machine from drifting

I found that the clock in a VirtualBox virtual machine was drifting significantly from real time. As shown below, it is possible to synchronise the clock in a virtual machine to the clock in the host machine. Note that you must have VirtualBox Guest Additions installed in the virtual machine, so, if you have not already done that, do it first.

Issue the commands on the host machine. In the example commands shown below, the virtual machine name is ‘TestVM’. Obviously change the name in the command to whatever it is you have named your virtual machine. The grep commands are simply to check that the required change to the .vbox XML file has occurred.

The setextradata command forces the virtual machine to get its time of day from the host machine by setting GetHostTimeDisabled to zero (0 = enabled, 1 = disabled). The command stores the parameter in the .vbox XML file of the virtual machine, ensuring that it is set every time the virtual machine boots.

The guestproperty command forces the virtual machine to re-synchronise its clock to the host machine every ten seconds (ten thousand milliseconds). The command also stores the parameter in the .vbox XML file of the virtual machine.

user $ VBoxManage setextradata "TestVM"
"VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 0
user $ grep GetHostTimeDisabled $HOME/VirtualBox-VMs/TestVM/TestVM.vbox

user $ VBoxManage guestproperty set "TestVM" "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold" 10000
user $ grep timesync $HOME/VirtualBox-VMs/TestVM/TestVM.vbox