I have been struggling to install VirtualBox Guest Additions in a Debian Virtual Machine (Debian 7, Debian 8 and Debian 9).
4 Answers
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.
For Debian 10 and 11, the VirtualBox packages are being made available in the new Fast Track service (see also the VirtualBox page on the Debian wiki). Thus for Debian 11:
echo deb http://ftp.debian.org/debian bullseye-backports main contrib > /etc/apt/sources.list.d/bullseye-backports.list
apt update
apt install fasttrack-archive-keyring
echo deb https://fasttrack.debian.net/debian-fasttrack/ bullseye-fasttrack main contrib > /etc/apt/sources.list.d/bullseye-fasttrack.list
echo deb https://fasttrack.debian.net/debian-fasttrack/ bullseye-backports-staging main contrib >> /etc/apt/sources.list.d/bullseye-fasttrack.list
apt update
apt install virtualbox-guest-x11
The guest kernel modules are included in the Debian 11 kernel. For Debian 10, follow the instructions above, replacing bullseye with buster, and install the same packages as in Debian 9:
apt install virtualbox-guest-dkms virtualbox-guest-x11 linux-headers-$(uname -r)
In more detail, here's the solution for Debian 7, 8, and 9, using Debian packages:
for Debian 7 and 8, enable the
contribrepositories; e.g. for Debian 8, make sure your/etc/apt/sources.listcontains something likedeb http://ftp.debian.org/debian jessie main contribfor Debian 9, enable backports with
contrib; to do so, add a line likedeb http://ftp.debian.org/debian stretch-backports main contribto
/etc/apt/sources.list(or better yet, astretch-backports.listfile 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-backportsafterinstallin 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.)
- 411,918
- 54
- 1,065
- 1,164
-
Really valuable information on an efficient install! I opted to use vagrant-vbguest as suggested by Richard at https://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](https://people.debian.org/~lucas/virtualbox-buster/). Install with `dpkg -i` and now shared clipboard works. – tolos Nov 27 '19 at 01: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 06 '20 at 22:49
-
on debian10: Unable to locate virtualbox-guest-dkms virtualbox-guest-x11 – Vincent Alex Aug 24 '21 at 09:05
-
@VincentAlex you missed the paragraph specifically about Debian 10 (starting with “VirtualBox is not available in Debian 10”) — it explains what to do. – Stephen Kitt Aug 24 '21 at 09:09
-
Oh yeah sorry, the easiest way to get around it is to use puttty which has perfect clipboard. – Vincent Alex Aug 24 '21 at 10:09
-
As of version [6.1.22-dfsg-3](https://salsa.debian.org/rosh/virtualbox/-/commit/9d807a3f92b0def3fba9192bfdb3856c6f2e90cf) the package virtualbox-guest-dkms has been made obsolete. Thus no need to install it with Debian Bullseye or newer. The same also applies for the virtualbox-guest-source package. – sampi Sep 26 '21 at 11:01
Follow these steps to install the Guest Additions on your Debian virtual machine:
- Login as root;
- Update your APT database with
apt-get update;
Install the latest security updates with
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 UPGRADE and Retry.
apt-get upgrade;
- Install required packages
apt-get install build-essential module-assistant;
2 packages (build-essential and module-assistant), both required for being able to recompile the kernel modules when installing the virtualbox linux additions package, so this command will get the headers and packages (compilers and libraries) required to work, notice that after installing your virtualbox linux additions package you will leave behind some packages as well as linux headers which you might or not delete afterwards, in my case they didn't hurt but for the sake of system tidyness you might want to pick up after playing ;)
- Configure your system for building kernel modules by running in a terminal:
m-a prepare;
- On virtualbox menu and with the VM running!, click on Install Guest Additions… from the Devices menu, virtualbox should mount the iso copy but if for any reason it wouldn't just in a terminal run:
mount /media/cdrom.
Finally in a terminal Run:
sh /media/cdrom/VBoxLinuxAdditions.run
follow the instructions on screen, and REBOOT.
Hope this helps.
EN
- 1,952
- 2
- 16
- 19
-
3
-
1On 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
-
2You 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
-
-
This is the best answer for sure but I agree, it's missing the linux headers, also I would suggest updating to the use of apt instead of of apt-get with the following `# apt install build-essential module-assistant linux-headers-$(uname -r)` – Helio Mar 15 '18 at 18:54
-
2The 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 09:54
-
1`sh /media/cdrom/VBoxLinuxAdditions.run` -> `sudo sh /media/cdrom/VBoxLinuxAdditions.run` – JustWe Jan 18 '20 at 04:40
-
Yeah, that sell execution will not always work if you do not have the linux headers installed and have them prepared for compilation. – ximbal Jan 19 '20 at 16:21
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!
- 707
- 7
- 8
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 contribUpdate repositories and install package
sudo apt-get update sudo apt-get install virtualbox-guest-dkmsOptionally: disable the sid repository, because it has updates for packages that you might not want.
- 181
- 3
-
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
-