[HowTo] VirtualBox installation, USB devices and shared folders

virtualbox
#1

HOST Installation and preparation

Packages to be installed

  • VirtualBox Host Modules
  • VirtualBox Guest ISO
  • Oracle VirtualBox Extension Pack

Install VirtualBox, host modules and guest iso

Your kernel is found using the uname command

$ uname -r
4.19.0-1-MANJARO

Another way to get the version directly usable in an install command is this excellent snippet by @tbg

$ echo linux$(uname -r| grep -o -E '[0-9]+' | head -n 2 | sed 'N;s/\n//')

The correct packages can then be installed using these commands in a terminal

$ KERNEL=linux$(uname -r| grep -o -E '[0-9]+' | head -n 2 | sed 'N;s/\n//')`
$ pamac install virtualbox $KERNEL-virtualbox-host-modules virtualbox-guest-iso

Install extension pack

The extension pack is a proprietary set of extensions providing useful functionality to VirtualBox. To mention a few like graphics drivers for VirtualBox, USB2 and USB3 passthrough. The extension pack's PKGBUILD is provided from AUR so we use Pamac to build and install it.

$ pamac build virtualbox-ext-oracle

Load kernel modules

If the kernel modules is not loaded VirtualBox will throw an error stating you need to run the command /sbin/vboxconfig though on Arch based system this does not exist. The correct command to load the modules without restarting is

$ sudo vboxreload

Preparation

Your host user must be member of the group vboxusers

$ sudo gpasswd -a $USER vboxusers

Log off to make the change registered.


USB devices

Access the DevicesUSB menu in VirtualBox Machine Window or USB menu item in the status bar. Select the USB device to mount in the virtual machine.

You may need to configure your USB to USB-3 if you have such controller. This is done in the USB Settings menu item.

:no_entry: Don't transfer your mouse or keyboard.
:no_entry: Don't add filters for your USB devices.


Shared folders

Shared folders require a litte more configuration to work both on the host and in the guest. What needs to be done in the guest is a little different depending on the guest operation system.

VirtualBox HOST

Setup the shared folder(s)

On the host locate the Settings section in VirtualBox GUI.

Make the folders Permanent and Automount.

:information_source: Set the folders to Read-only if you plan to use Windows and want to browse insecure websites and other insecure activities. Doing so will prevent an eventual malware/ransomware from spreading to your host.

VirtualBox GUEST requirements

  • guest utilities

Start the guest

Continue with the appropriate guest section

MANJARO GUEST

Packages to be installed

  • VirtualBox kernel modules
  • VirtualBox guest utilities

The kernel modules and utilities is installed from the official repos. We will use the same snippet as above to ensure we have modules for the current running kernel

$ KERNEL=linux$(uname -r| grep -o -E '[0-9]+' | head -n 2 | sed 'N;s/\n//')
$ pamac install virtualbox-guest-utils $KERNEL-virtualbox-guest-modules

Based on comments below and other threads it seems that having the shared folders to work as expected it may be needed to run the guest additions installer by following the section OTHER LINUX GUEST below.

OTHER LINUX GUEST

For best results, Linux as well as Windows guests needs the guest utilities installed.

Prefer to use the ISO image provided as other Linux distributions might not have the most recent version of the utilities.

When you have installed the packages continue with Linux Guest Configuration or Windows Guest Configuration.

From the Devices menu of the VirtualBox Guest Window choose Insert Guest Additions CD Image...

On some Linux systems it is required to open a terminal and execute the installer from CLI. Open a file manager, browse to the mounted ISO, use the file manager to launch a terminal then start the installer.

$ ./runasroot.sh

LINUX GUEST Configuration

In the running guest - add the guest user to the group vboxsf.

$ sudo gpasswd -a $USER vboxsf

Enable vboxservice

$ sudo systemctl enable --now vboxservice

Mounting the shared folders

On most Linux guests you need to create the mount folder manually

$ sudo mkdir /media

After reboot your shared folders is now available on the guest in the path

/media/sf_$your_shared_folder_name

Mount in guest user's home

If you prefer your folders mounted in the guest users home folder you can do so by means of this script. Run the script on the guest after login.

Linux guest script for shared folders

Create folders to mimic your shared folder names.

Create a file in your home folder:

$ touch ~/vboxmount.sh
$ chmod +x ~/vboxmount.sh

Edit the file and add the following content and save it.

#!/bin/sh
#-----------------------------------------------------------------------------
# Discover VirtualBox shared folders and mount them if it makes sense
# Folders with the same name must exist in the $USER home folder
#-----------------------------------------------------------------------------

if  !  type  VBoxControl  > /dev/null;  then
  echo  "VirtualBox Guest Additions NOT found"  > /dev/stderr
  exit 1
fi

MY_UID="$(id -u)"
MY_GID="$(id -g)"

( set -x;  sudo  VBoxControl  sharedfolder  list; )  |  \
grep      '^ *[0-9][0-9]* *- *'                      |  \
sed  -e 's/^ *[0-9][0-9]* *- *//'                    |  \
while  read  SHARED_FOLDER
do
  MOUNT_POINT="$HOME/$SHARED_FOLDER"
  if  [ -d "$MOUNT_POINT" ];  then
    MOUNTED="$(mount  |  grep  "$MOUNT_POINT")"
    if  [ "$MOUNTED" ];  then
      echo  "Already mounted :  $MOUNTED"
    else
      (
        set -x
        sudo  mount  -t vboxsf  -o "nosuid,uid=$MY_UID,gid=$MY_GID"  "$SHARED_FOLDER"  "$MOUNT_POINT"
      )
    fi
  fi
done

WINDOWS GUEST Configuration

Start the Windows guest.

From the Devices menu of the VirtualBox Guest Window choose Insert Guest Additions CD Image...

Insert the guest additions and run the installer in your Windows system.

Restart the guest to make the shared folders available using the Windows Explorer.

14 Likes
VirtualBox: Drag and Drop Windows 10 to Manjaro
[SOLVED] Virtualbox - USB <no devices available>
Virtualbox shared folders bug?
Virtualbox with Archlinux on Manjaro
Manjaro as a Virtualbox Guest: additions from ISO or packages?
Virtualbox not automounting shared folder in guest (Manjaro KDE v18.0.2)
Help with configuring Oracle Virtualbox in Mate
Error in VirtualBox
virtualbox usb support
Widespread VirtualBox Shared Folders breakage with [Stable Update] 2019-01-17
[SOLVED] My wlp2s0 device is missing
Failed to start kernel module
Question about dual-booting
Widespread VirtualBox Shared Folders breakage with [Stable Update] 2019-01-17
Network fails in VirtualBox.
How to resolve VirtualBox "Kernel Driver Not Installed" using desktop environment....
[solved] Virtualbox shared folder is empty (mount failed)
Virtual Box; Host: Windows 10 Guest: Manjaro 18
Oracle VM Virtual Box and USB [Solved]
Virtulbox - Host W10 / Guest Manjaro KDE - Share Folders
Virtulbox - Host W10 / Guest Manjaro KDE - Share Folders
#4

Thank you so much. Was very useful.

#5

Just wanted to note that I had the same issues at @Lorthirk in their thread about Guest Additions.

I don't know what the problem is but I followed the tutorial twice and still couldn't get full guest functionality on a Manjaro KDE install.

And similar to @Lorthirk I used the Guest Additions ISO successfully.

#6

The tutorial is on using VirtualBox on Manjaro host.

Should your reply to this HowTo be understood that installing the virtualbox-guest-utils could not provide the needed funtionality but using the Guest Additions ISO did provide the functionality?

If this is the correct understanding it seems the guest utils package maybe missing something?

Since the virtualbox-guest-utils is package imported from the Arch repositories the $KERNEL-virtualbox-guest-modules maybe missing something?

#7

mhwd-kernel is better IMHO.

$ mhwd-kernel -li
Currently running: 5.1.0-1-MANJARO (linux51)
The following kernels are installed in your system:
   * linux419
   * linux50
   * linux51
#8

Yes, that was my post's intention. Sorry for not being clear!

I spent some more time testing and have been unable to successfully install the guest additions through virtualbox-guest-utils and the appropriate kernel modules.

I tried two different computers (both Manjaro hosts) with both the Xfce and KDE ISOs.

Mainly, I thought it was weird that something so (seemingly) straightforward was giving users a problem. Also I often recommend people try out Manjaro in a VM and obviously want it to work well for them! :grinning:

I couldn't find any mention of the issue on the Arch forum, so maybe there is just a user error somewhere.