I wrote this small article as a quick reference because I always forget what the requirements are for the installation of VirtualBox’s Guest Additions under a Linux virtual machine.
Dependencies
The installation of the guest additions consists in building and installing the corresponding kernel modules.
Therefore, building tools and Linux headers are needed.
# As root
apt update && apt install build-essential dkms gcc linux-headers-`uname -r`
Installation
First, make sure the VM has an optical disk reader in the Storage
section of the Configuration
window.
Then use the Devices
menu and Insert GuestAdditions CD Image
.
Depending on the operating system and the desktop environment, the disk might be mounted automatically in a directory under /media/<user>
. Otherwise, it is usually available as /dev/cdrom
or /dev/sr0
and need to be mounted manually. In this example I mount it in /media/vboxadds
.
# As root
mkdir -p /media/vboxadds
mount /dev/cdrom /media/vboxadds
And finally run the building script
# As root
sh /media/vboxadds/VBoxLinuxAdditions.run
Do not forget to cleanup after you
# As root
umount /media/vboxadds
rm -r /media/vboxadds
And eject the CD image from the reader!
Shared folders
VirtualBox allows to share some folders between the host and the virtual machine. By default users in the virtual machine are not allowed to access these folders.
In order to allow a user to access a shared folder, you must add him to the vboxsf
(VirtualBox Shared Folders) group with this command:
# as root
usermod -aG vboxsf user
Be carefull to not overwrite all groups for the user: do not forget the -a
flag to “add” the group to the existing ones.
Note: The new rights will be available only after logout-login, or reboot.
Reboot & enjoy
The Guest Additions will be available at the next reboot of the virtual machine.
You need to repeat this process anytime VirtualBox is updated, since the Guest Addtions are also updated for compatibility.