50

I have been struggling to install VirtualBox Guest Additions in a Debian Virtual Machine (Debian 7, Debian 8 and Debian 9).

67

The TL;DR version for Debian 9 is, as root:

echo deb http://ftp.debian.org/debian stretch-backports main contrib > /etc/apt/sources.list.d/stretch-backports.list
apt update
apt install virtualbox-guest-dkms virtualbox-guest-x11 linux-headers-$(uname -r)

That’s it, the VirtualBox Guest Additions are installed.

VirtualBox is not available in Debian 10, and won’t be made available in buster-backports either. Lucas Nussbaum has an unofficial set of packages; if you want to use them, you should follow his instructions (linked only — if the link stops being valid, the packages are presumably not available either, so copying the instructions here is pointless).

In more detail, here's the solution for Debian 7, 8, and 9, using Debian packages:

  • for Debian 7 and 8, enable the contrib repositories; e.g. for Debian 8, make sure your /etc/apt/sources.list contains something like

    deb http://ftp.debian.org/debian jessie main contrib
    
  • for Debian 9, enable backports with contrib; to do so, add a line like

    deb http://ftp.debian.org/debian stretch-backports main contrib
    

    to /etc/apt/sources.list (or better yet, a stretch-backports.list file in /etc/apt/sources.list.d);

  • install virtualbox-guest-dkms, kernel headers, and, optionally, virtualbox-guest-x11 (for the graphical guest utilities):

    sudo apt update
    sudo apt install virtualbox-guest-dkms virtualbox-guest-x11 linux-headers-$(uname -r)
    

    (with -t stretch-backports after install in the second line if you’re using Debian 9).

That’s all that’s needed — you don’t need to mount the guest additions in your VM, or run the installer. You can add the three lines of shell invocations to your Vagrantfile (or whatever you use to provision your VMs) and forget about them.

Installing the virtualbox-guest-dkms package will ensure that the appropriate kernel modules are automatically built (and rebuilt when the kernel is upgraded), and install the guest additions.

(Note that this will install the version of the guest additions available in whichever version of Debian you're using in the VM, which may not match the version of Virtual Box running the VM — but the guest additions should still work fine.)

|improve this answer|||||
  • 1
    Confirmed working for Debian 8.3 - 3.16.0-4-amd64 - 3.16.51-3 (2017-12-13) You can install the "server only" addition without adding X-11 with apt-get install --no-install-recommends virtualbox-guest-utils virtualbox-guest-dkms linux-headers-$(uname -r) – Marco Rossi Jan 29 '18 at 0:47
  • Really valuable information on an efficient install! I opted to use vagrant-vbguest as suggested by Richard at superuser.com/a/1025183/187346 because I kept running into vagrant errors with shared folders because guest additions were not installed but the folders were specified. – Colin May 15 '18 at 11:37
  • Just want to confirm the part about Debian 10. The regular vbox addition script doesn't fix shared clipboard. First apt-get install dkms then I wget the two .deb files "virtualbox-guest-dkms..." and " virtualbox-guest-utils..." from the listed website above (link. Install with dpkg -i and now shared clipboard works. – tolos Nov 27 '19 at 1:11
  • instructions worked for me on virtualbox 6 and debian 10 (except cdrom appeared as cdrom1), and the shared clipboard and window resizing is working – ChaseMoskal Jan 6 at 22:49
60

Follow these steps to install the VirtualBox Guest Additions on your Linux Debian virtual machine:

  1. Open terminal and become root (su); if you have sudo enabled, you may also do for example sudo -i; see man sudo for all options):

    su
    

enter root password and press enter

alternatively you can use sudo -s if you have it installed and the user where you are logged in has the necessary rights...

  1. Update APT cache:

    apt-get update
    
  2. Install the latest security updates:

    This step will upgrade all your packages, so be wise about it. Try the following steps first and they might be enough to work if not, then perform upgrade and retry.

    apt-get upgrade
    
  3. Install these required packages:

    Packages build-essential and module-assistant are both required to be able to compile the kernel modules and so when installing the VirtualBox Linux Guest Additions you must have them. So, this command will get the headers and packages (compilers and libraries) required to work. Notice, that after installing your VirtualBox Linux Guest Additions you will leave behind some packages as well as Linux headers, which you might delete afterwards or not. In my case they didn't hurt, but for the sake of system tidiness, you might want to pick up after playing.

    apt-get install build-essential module-assistant
    
  4. Configure your system for building kernel modules:

    m-a prepare
    
  5. Insert Guest Additions ISO:

    Expand menu Devices and click on Insert Guest Additions CD image...

  6. It should mount automatically, but if for any reason it doesn't:

    mount /media/cdrom
    
  7. Run the following script:

    sh /media/cdrom/VBoxLinuxAdditions.run
    
  8. Restart the system:

    reboot
    
|improve this answer|||||
  • 3
    This works for Debian 9. – Ortomala Lokni Jul 9 '17 at 12:49
  • 1
    On Debian 9, this gave an error message saying "unable to find the sources of your current Linux kernel." – user2800708 Sep 28 '17 at 14:03
  • 2
    You are missing the Kernel Headers, please try sudo apt-get update && sudo apt-get install linux-headers-`uname -r` – ximbal Sep 28 '17 at 17:41
  • 2
    The command m-a prepare should pull the linux-headers package, all the instructions work fine in a Debian 9 install. – alemani Apr 23 '18 at 9:54
  • 1
    @ximbal A true linux wizard – Soutzikevich Feb 13 at 16:42
5

An alternative to installing VirtualBox guest addons from the Debian repository is to use sources from the vendor. The repository is expected to provide older and more stable code while sources from vendor are going to have the latest features and security updates.

I have successfully tried the ensuing instructions on Debian 9.4 guest running Linux kernel 4.9.0-4 using VirtualBox 5.0.30 and OS X 10.11.6. First, attach the guest addons ISO image to the virtual machine and then start it. After bootup, the contents of the image would be available in /media/cdrom0/. First, there are two packages and their dependencies that have to be installed:

$ sudo apt-get install linux-headers-$(uname -r) build-essential

Then, run the vendor provided script that builds and installs the necessary kernel modules:

$ cd /media/cdrom0/
$ sudo sh VBoxLinuxAdditions.run

Reboot the virtual machine and enjoy!

|improve this answer|||||
4

In Debian 9, the virtualbox-guest-dkms package is in the unstable (sid) repository.

  • Add this to /etc/apt/sources.list:

    deb http://http.us.debian.org/debian sid main non-free contrib
    
  • Update repositories and install package

    sudo apt-get update
    sudo apt-get install virtualbox-guest-dkms
    
  • Optionally: disable the sid repository, because it has updates for packages that you might not want.

|improve this answer|||||
  • This appeared to work up until the point when I rebooted the virtual machine; after it came back up, it still "rsync"d instead of mounting the current host directory into /vagrant on the VM. Since that mount was the entire reason that I wanted the guest additions, it's still effectively broken. – offby1 Jun 18 '17 at 16:27
  • Isn't stretch-backports usually preferable to using sid? – Karl Bartel Feb 11 '18 at 20:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.