As expected, first we need to install VirtualBox.
Terminalsudo wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
echo "deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian focal contrib" \
| sudo tee /etc/apt/sources.list.d/virtualbox.list
sudo apt update
sudo apt-get install --yes virtualbox-6.1
sudo systemctl status vboxdrv
sudo usermod -aG vboxusers $USER
Since our server is headless, we will need a remote acces. This means installing Oracle's extension pack with RDP support. You should be good installing this on your home system but you will need license for production deployments.
TerminalVBOXVER=`vboxmanage -v | cut -dr -f1`
wget -P /tmp \
https://download.virtualbox.org/virtualbox/$VBOXVER/Oracle_VM_VirtualBox_Extension_Pack-$VBOXVER.vbox-extpack
vboxmanage extpack install /tmp/Oracle_VM_VirtualBox_Extension_Pack-$VBOXVER.vbox-extpack
With installation ready, we can approach creating VM. I'll give an example of the Ubuntu Desktop but really anything goes.
Terminalmkdir -p /srv/virtualbox
vboxmanage createvm \
--ostype Ubuntu_64 \
--basefolder "/srv/virtualbox" \
--register \
--name "Test"
vboxmanage modifyvm "Test" \
--memory 1024 \
--nic1 nat \
--vrde on --vrdeport 33890
vboxmanage createhd \
--filename "/srv/virtualbox/Test/Test.vdi" \
--format VDI --size 10240
vboxmanage storagectl "Test" \
--name "SATA" \
--add sata
vboxmanage storageattach "Test" \
--storagectl SATA --port 0 --type hdd \
--medium "/srv/virtualbox/Test/Test.vdi"
vboxmanage storageattach "Test" \
--storagectl SATA --port 15 --type dvddrive \
--medium /tmp/ubuntu-20.04-desktop-amd64.iso
If you are using firewall, make sure to allow port through. For example, iptables
would need the following adjustment.
Terminaliptables -A INPUT -p tcp --dport 33890 -j ACCEPT
With this, we're finally ready to start the virtual machine.
Terminalvboxmanage startvm "Test" --type headless
To connect to it just use any Remote Desktop application.
PS: Authentication for RDP is highly recommended and you should probably check documentation to see what works best for you.
missing sudo before “vboxmanage extpack install…”
Is it possible to connect from remote host to my guest-from-this-tutorial-host?
You can also just install Ubuntu Server, then start it headless with access via SSH.