Debian headless installation on Virtualbox

By /robex/, December 2018. Back to Articles and Guides

Virtualbox setup

In order to install VirtualBox under Debian-based systems, append to /etc/apt/sources.list:

deb https://download.virtualbox.org/virtualbox/debian [distrocodename] contrib

Afterwards, add the repository key from Oracle:

wget https://www.virtualbox.org/download/oracle_vbox_2016.asc
sudo apt-key add oracle_vbox_2016.asc

Install VirtualBox and the extension pack:

sudo apt update
sudo apt install virtualbox-5.2
wget https://download.virtualbox.org/virtualbox/5.2.22/Oracle_VM_VirtualBox_Extension_Pack-5.2.22.vbox-extpack
sudo vboxmanage extpack install Oracle_VM_VirtualBox_Extension_Pack-5.2.22.vbox-extpack

If you want, change the default VM directory now before creating any VMs (by default ~/Virtualbox\ VMs):

vboxmanage setproperty machinefolder /path/to/dir

Debian VM setup

We will install Debian netinst amd64, but the process should be the same for any normal distro. First, create the vm and set basic hardware in Virtualbox:

vboxmanage createvm --name "debsrv" --register
vboxmanage modifyvm debsrv --memory 1024 --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 [youriface] --ostype Debian
Note: for Windows machines, add --chipset ich9 or they won't boot. Also change network card to an Intel one and add >18MB VRAM.

Here, [youriface] is the interface where you have an Internet connection on the host. In my case, it is enp2s0f0 (thank you systemd).

Then, create the disk file for the VM, add the disk and dvd controllers and attach the proper media (the image for the distro and the HDD file):

vboxmanage createvdi --filename disk01.vdi --size 4000
vboxmanage storagectl debsrv --name "IDE Controller" --add ide
vboxmanage storageattach debsrv --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium disk01.vdi
vboxmanage storageattach debsrv --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium debian-9.6.0-amd64-netinst.iso

RDP authentication for first installation

We will use the Remote Desktop Protocol in order to perform the initial installation. First, open port 3389 (both TCP and UDP) and set authentication on Virtualbox:

vboxmanage setproperty vrdeauthlibrary "VBoxAuthSimple"
vboxmanage modifyvm debsrv --vrdeauthtype external

As a side note, you should block access to anyone but yourself to port 3389 with a firewall. DON'T leave it open to the Internet or you will eventually get pwned.

Then, create a password hash and add it to your VM:

vboxmanage internalcommands passwordhash "verysecurepw"
# this will return a hash (e.g. cdebc192e0ae1f5df753018a8d284b9eacf2042d55fb712f7a89260c3fc3668d)
vboxmanage setextradata debsrv "VBoxAuthSimple/users/vm" cdebc192e0ae1f5df753018a8d284b9eacf2042d55fb712f7a89260c3fc3668d

Start the machine (and VRDE server):

vboxheadless --startvm debsrv --vrde on&

You can now connect through any RDP client like remmina on Linux or mstsc.exe on Windows (you have to check "Allow me to save credentials" or it will fail for some esoteric reason) and proceed with the usual Debian installation. In order to shut down the machine, you can use:

vboxmanage controlvm debsrv poweroff

Once it is installed, setup the ssh daemon so that you can then login normally through ssh, and disable VRDP if you don't need a graphical session.


/robex/ - Last edited: 2018-12-08 04:49:15