Skip to Content

Virtualbox on Debian Stretch

Posted on

Virtualbox is virtualization software that allows a Linux user to host multiple guest operating systems as virtual machines (VMs). It is a cool tool for playing with different Linux distros and experimenting with configurations.

Let’s go!

In this HOWTO I install Virtualbox on a Debian stable (stretch) HOST and create a Debian GUEST virtual machine.

0. Install VirtualBox on HOST

Kernel modules for Virtualbox are built via Dynamic Kernel Module Support (DKMS). After installing Virtualbox the vbox modules should be auto-built and -loaded. Install a few tools …

$ sudo apt install dkms module-assistant linux-headers-$(uname -r)

Virtualbox packages for the Debian stable release are available in stretch-backports. Add the repository to /etc/apt/sources.list

deb stretch-backports main contrib non-free
deb-src stretch-backports main contrib non-free

Refresh package listings, install Virtualbox, and assign username to vboxusers group …

$ sudo apt update && sudo apt --target-release stretch-backports install virtualbox
$ sudo adduser foo vboxusers

Alternative install method: Retrieve Virtualbox directly from Oracle and their third-party Debian package repository.

Create the virtualbox.list file in /etc/apt/sources.list.d

$ sudo sh -c 'echo "deb stretch contrib" > /etc/apt/sources.list.d/virtualbox.list'

Add Oracle’s Virtualbox public key …

$ wget
$ sudo mv oracle_vbox_2016.asc /etc/apt/trusted.gpg.d
$ apt-key list
    pub   rsa4096 2016-04-22 [SC]
    B9F8 D658 297A F3EF C18D  5CDF A2F6 83C5 2980 AECF
    uid           [ unknown] Oracle Corporation (VirtualBox archive signing key) <>
    sub   rsa4096 2016-04-22 [E]

Install Virtualbox, and assign username to vboxusers group …

$ sudo apt update && sudo apt install virtualbox-*
$ sudo adduser foo vboxusers

1. Create a Debian GUEST VM

Default Machine Folder where Virtual Machine (VM) images are stored is ~/Virtualbox VMs (this can be modified in File->Preferences->General).

See the User Manual for creating a GUEST VM. I use the Debian netinst installer to create a new virtual machine with a minimal system configuration.

2. Guest additions

Enable extra features such as the ability to tweak display settings and add a shared folder between HOST and GUEST machines.

Launch the new Debian GUEST and install …

$ sudo apt update && apt install build-essential module-assistant linux-headers-$(uname -r) dkms
$ sudo m-a prepare

Download the VBoxGuestAdditions_VERSION.iso

$ wget -c

In the GUEST window menu, select Devices > Insert Guest Additions CD image to make the image accessible to the VM. Inside the VM: mount the image; run the install script; add user to the vboxsf group; reboot the VM, and as root …

mount /media/cdrom
sh /media/cdrom/
adduser USERNAME vboxsf

If the virtualbox modules need to be rebuilt for any reason for the running kernel …

uname -r | sudo xargs -n1 /usr/lib/dkms/dkms_autoinstaller start

3. Display

Tweak display settings by going to the Virtualbox Machine->Settings...->Display setting and move the slider to add more video memory and enable 3D acceleration.

Display settings

With VirtualBox guest additions the display and resolution can be changed when running a graphical environment. If the GUEST VM does not use a graphical login manager to launch its desktop, then modify ~/.xinitrc to start VBoxClient services …

VBoxClient --clipboard &
VBoxClient --display &
VBoxClient --seamless &

4. Console

Debian GUEST in console mode defaults to a small 80x40 window. Resize by rebooting the GUEST and configuring Grub

  • Grub boot screen: hit c to enter command mode
  • At the prompt grub>: run vbeinfo to display supported resolutions (example: 1152x864)
  • Modify the config /etc/default/grub: add …
    • GRUB_GFXMODE=1152x864
    • GRUB_GFXPAYLOAD_LINUX=keep (Helpful!)
  • Save changes: run sudo update-grub and reboot

5. Shared folder

Create a shared folder on HOST. Make it accessible to GUEST by going to Machine->Settings...->Shared Folders and click Add Shared Folder and Auto-Mount.

Shared folder settings

6. SSH from HOST to GUEST

Host-only networking with Virtualbox was a big help getting this properly configured.

Scenario: I want to SSH from my HOST to GUEST. Default configuration supplies GUEST with a NAT interface for internet access but no HOST<->GUEST connectivity. A solution for local access is creating a host-only adapter.


Navigate to Virtualbox’s File->Preferences->Network, select Host-only Networks, click Adds new host-only network to create vboxnet0. Default setup is interface address with DHCP enabled.

Select the GUEST VM and in Machine->Settings->Network click on Adapter 2, enable network adapter attached to Host-only Adapter, and select vboxnet0.


Boot the VM and confirm the new interface has been created. Add the interface to /etc/network/interfaces (example: enp0s8) …

# Host-only interface
auto enp0s8                                                                          
iface enp0s8 inet dhcp                                                               

Install the SSH server …

$ sudo apt install openssh-server                                                         

Reboot GUEST. The second interface has been assigned address by DHCP and can now be accessed from HOST via SSH.

Optional: Assign GUEST a static address outside the range of the Virtualbox DHCP server (101-254 by default) …

# Host-only interface
auto enp0s8
    iface enp0s8 inet static

Modify /etc/hosts on HOST by adding the VM static address.

Happy hacking!