Nested virtualisation is possible using LXC containers and a virtualisation tool such as VirtualBox or Virtual Machine Manager inside the container.

 

How to set-up VirtualBox in an LXC container ?

IMPORTANT
  • If you want to run Virtualbox in a LXC container, you need to ensure that all running kvms on the host are stopped first
  • If Virtualbox has been started in a LXC container, any running kvm machines will fail
     
Quickguide
  1. Install virtualbox-dkms on Host:
    Ubuntu 20.10 (Deprecated):
    Up-to-date (from Ubuntu 21.04):
  2. Install Virtualbox on Container
  3. FAQ

 

Install virtualbox-dkms on Host:

Ubuntu 20.10 (Deprecated):

curl -sL -o /tmp/virtualbox-dkms_6.1.14-dfsg-4_amd64.deb
http://archive.ubuntu.com/ubuntu/pool/multiverse/v/virtualbox/virtualbox...
&& sudo dpkg -i  /tmp/virtualbox-dkms_6.1.14-dfsg-4_amd64.deb  || sudo apt --fix-broken install -y

sudo modprobe vboxdrv
sudo modprobe vboxnetadp
sudo modprobe vboxnetflt

Up-to-date (from Ubuntu 21.04):

Ubuntu 21.04 (Kernel 5.11) cannot install virtualbox-dkms_6.1.14-dfsg ..
So we need to upgrade the Virtualbox on the dd nodes.

curl -sL -o /tmp/virtualbox-dkms_6.1.18-dfsg-5_amd64.deb
http://archive.ubuntu.com/ubuntu/pool/multiverse/v/virtualbox/virtualbox...
&& sudo dpkg -i  /tmp/virtualbox-dkms_6.1.18-dfsg-5_amd64.deb  || sudo apt --fix-broken install -y

sudo modprobe vboxdrv
sudo modprobe vboxnetadp
sudo modprobe vboxnetflt

Install VirtualBox on Container

You need to install the same version of Virtualbox as on the host.

https://www.virtualbox.org/wiki/Download_Old_Builds_6_1

 

FAQ

  • How can I create a network in Virtualbox Host Network Manager? : Run this command in terminal before opening Host Network Manager:

    nmcli conn add type bridge con-name vboxnet0 ifname vboxnet0

  • If multiple network cards are enabled for the virtual machine in Virtualbox settings, it appears in the GUI that only one can obtain the IP address. To get around this issue, edit netplan, and add the 2nd network in the config file.