VirtualBox remains one of the most practical desktop hypervisors for running virtual machines on Linux workstations. Oracle recently released VirtualBox 7.1 with improved performance, better Wayland support, and an updated Qt6-based GUI. This guide walks you through a clean installation of VirtualBox 7.1 on Debian 13 (Trixie) or Debian 12 (Bookworm), including the Extension Pack, CLI-based VM creation, Guest Additions, networking modes, headless operation, and nested virtualization.
Prerequisites
Before installing VirtualBox, your system needs kernel headers and a few build tools so the vboxdrv kernel module can compile properly. Run this on a fresh or existing Debian 13/12 system.
Update your package index and install the required packages:
sudo apt update
sudo apt install -y linux-headers-$(uname -r) dkms build-essential gcc make perl curl wget gnupg2 software-properties-common apt-transport-https
Verify that the kernel headers match your running kernel:
ls /usr/src/linux-headers-$(uname -r)
If the directory exists, you are good to proceed. If not, reboot into the latest installed kernel and re-run the headers installation.
Add Oracle VirtualBox Repository and GPG Key
Oracle maintains an official APT repository for VirtualBox. We need to import the signing keys and add the repo for your Debian release.
Download and install Oracle’s GPG keys:
curl -fsSL https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --dearmor -o /usr/share/keyrings/oracle-virtualbox-2016.gpg
Now add the VirtualBox repository. For Debian 13 (Trixie):
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian trixie contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
For Debian 12 (Bookworm):
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian bookworm contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
Verify the repository file was created:
cat /etc/apt/sources.list.d/virtualbox.list
You should see the full deb line with the signed-by reference to the GPG keyring.
Install VirtualBox 7.1
With the repository in place, update the package cache and install VirtualBox 7.1:
sudo apt update
sudo apt install -y virtualbox-7.1
During installation, DKMS will compile the VirtualBox kernel modules (vboxdrv, vboxnetflt, vboxnetadp) for your running kernel. Watch the output for any errors – if the module build fails, it usually means missing kernel headers.
Confirm the kernel modules loaded successfully:
sudo systemctl status vboxdrv
The service should show as active (exited). If it failed, check the troubleshooting section at the end of this guide.
Install VirtualBox Extension Pack
The Extension Pack adds USB 2.0/3.0 passthrough, VirtualBox Remote Desktop Protocol (VRDP), PXE boot for Intel cards, and disk encryption support. It is free for personal and evaluation use.
First, find the exact VirtualBox version installed:
VB_VERSION=$(VBoxManage --version | cut -d'r' -f1)
echo $VB_VERSION
Download the Extension Pack matching your version:
wget "https://download.virtualbox.org/virtualbox/${VB_VERSION}/Oracle_VirtualBox_Extension_Pack-${VB_VERSION}.vbox-extpack" -O /tmp/Oracle_VBox_ExtPack.vbox-extpack
Install the Extension Pack (you will need to accept the license):
sudo VBoxManage extpack install --replace /tmp/Oracle_VBox_ExtPack.vbox-extpack
Verify the Extension Pack is installed:
VBoxManage list extpacks
You should see “Oracle VirtualBox Extension Pack” listed with the version number and “Usable: true”.
Add Your User to the vboxusers Group
Your regular user account needs to be in the vboxusers group to access USB devices and other host hardware from within VMs:
sudo usermod -aG vboxusers $USER
Log out and log back in for the group change to take effect. Then verify:
groups $USER
Confirm vboxusers appears in the output.
Verify VirtualBox Installation
Run a quick check to make sure everything is working:
VBoxManage --version
This should return something like 7.1.6r167084 (your exact version may differ). You can also check the kernel module status:
lsmod | grep vbox
You should see vboxdrv, vboxnetflt, and vboxnetadp in the output. If all three modules are loaded, VirtualBox is ready to use.
Create Your First VM from the Command Line
The VBoxManage CLI is a powerful way to create and manage VMs, especially on headless servers. Here is a full example creating a Debian VM.
Create and register the VM:
VBoxManage createvm --name "Debian-Test" --ostype Debian_64 --register
Configure memory, CPUs, and boot order:
VBoxManage modifyvm "Debian-Test" --memory 2048 --cpus 2 --boot1 dvd --boot2 disk --boot3 none --boot4 none
Configure the graphics controller and video memory:
VBoxManage modifyvm "Debian-Test" --graphicscontroller vmsvga --vram 128
Create a virtual hard disk (20 GB, dynamically allocated):
VBoxManage createmedium disk --filename ~/VirtualBox\ VMs/Debian-Test/Debian-Test.vdi --size 20480 --variant Standard
Add a SATA controller and attach the disk:
VBoxManage storagectl "Debian-Test" --name "SATA Controller" --add sata --controller IntelAhci
VBoxManage storageattach "Debian-Test" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium ~/VirtualBox\ VMs/Debian-Test/Debian-Test.vdi
Add an IDE controller and attach an ISO for installation:
VBoxManage storagectl "Debian-Test" --name "IDE Controller" --add ide
VBoxManage storageattach "Debian-Test" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium /path/to/debian-12-amd64-netinst.iso
Enable NAT networking (default) on the first adapter:
VBoxManage modifyvm "Debian-Test" --nic1 nat
Verify the VM configuration:
VBoxManage showvminfo "Debian-Test" | head -30
Start the VM:
VBoxManage startvm "Debian-Test"
This opens the VM in a GUI window. For headless operation, see the section below.
Install VirtualBox Guest Additions in Guest VMs
Guest Additions improve performance inside VMs by providing better video drivers, shared folders, mouse pointer integration, and time synchronization. Install them inside each guest VM.
First, install the required build tools inside the guest:
sudo apt update
sudo apt install -y linux-headers-$(uname -r) build-essential dkms perl
From the VirtualBox menu, go to Devices > Insert Guest Additions CD Image. This mounts the Guest Additions ISO inside the VM. Then run:
sudo mount /dev/cdrom /mnt
sudo /mnt/VBoxLinuxAdditions.run
Alternatively, you can mount the ISO from the host and run the installer from there:
VBoxManage storageattach "Debian-Test" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium /usr/share/virtualbox/VBoxGuestAdditions.iso
Reboot the guest after installation:
sudo reboot
After rebooting, verify Guest Additions are loaded:
lsmod | grep vboxguest
You should see vboxguest, vboxsf, and vboxvideo modules loaded.
Configure VM Networking – Bridged, NAT, and Host-Only
VirtualBox supports several networking modes. Here is how to configure the three most common ones from the CLI.
NAT (Default)
NAT gives the guest outbound internet access through the host’s connection. The guest gets a private IP and is not directly reachable from the network.
VBoxManage modifyvm "Debian-Test" --nic1 nat
To forward a port from the host to the guest (for example, SSH):
VBoxManage modifyvm "Debian-Test" --natpf1 "ssh,tcp,,2222,,22"
You can then SSH into the guest with ssh -p 2222 user@localhost.
Bridged Networking
Bridged mode places the VM directly on your physical network. The guest gets an IP from your network’s DHCP server and is reachable like any other machine on the LAN.
VBoxManage modifyvm "Debian-Test" --nic1 bridgedadapter --bridgeadapter1 enp0s3
Replace enp0s3 with your actual network interface name. Find it with ip link show.
Host-Only Networking
Host-only creates a private network between the host and VMs. The guest cannot reach the internet, but can communicate with the host and other VMs on the same host-only network.
First, create a host-only network:
VBoxManage hostonlynet add --name HostOnlyNet1 --netmask 255.255.255.0 --lower-ip 192.168.56.100 --upper-ip 192.168.56.200
VBoxManage hostonlynet modify --name HostOnlyNet1 --enable
Attach it to a VM:
VBoxManage modifyvm "Debian-Test" --nic2 hostonlyadapter --hostonlyadapter2 HostOnlyNet1
Verify the networking configuration:
VBoxManage showvminfo "Debian-Test" | grep -i "nic"
Run VMs in Headless Mode with VBoxHeadless
If you are running VirtualBox on a server without a display, or you simply want a VM running in the background, headless mode is what you need.
Start a VM in headless mode:
VBoxManage startvm "Debian-Test" --type headless
You can also use the VBoxHeadless command directly:
VBoxHeadless --startvm "Debian-Test"
To access a headless VM remotely, enable VRDP (requires the Extension Pack):
VBoxManage modifyvm "Debian-Test" --vrde on --vrdeport 3389
Then connect from any RDP client to your-host-ip:3389.
Check the status of running VMs:
VBoxManage list runningvms
To gracefully shut down a headless VM:
VBoxManage controlvm "Debian-Test" acpipowerbutton
To force power off (use only when the guest is unresponsive):
VBoxManage controlvm "Debian-Test" poweroff
Enable Nested Virtualization
Nested virtualization lets you run a hypervisor inside a VM – useful for testing KVM, Docker with VM isolation, or Kubernetes clusters. VirtualBox 7.1 supports this on AMD and Intel CPUs.
Make sure the VM is powered off, then enable nested VT-x/AMD-V:
VBoxManage modifyvm "Debian-Test" --nested-hw-virt on
Verify the setting:
VBoxManage showvminfo "Debian-Test" | grep -i "nested"
You should see Nested VT-x/AMD-V: enabled. Inside the guest, you can now confirm hardware virtualization support:
egrep -c '(vmx|svm)' /proc/cpuinfo
A non-zero result means the guest sees virtualization extensions.
Troubleshooting
Here are the most common issues you will run into and how to fix them.
vboxdrv Kernel Module Not Loaded
If you see the error WARNING: The vboxdrv kernel module is not loaded or VirtualBox refuses to start VMs, the kernel module failed to build or load.
Rebuild the kernel modules:
sudo /sbin/vboxconfig
If that fails, check that headers are installed for your running kernel:
dpkg -l | grep linux-headers-$(uname -r)
If nothing shows up, install them:
sudo apt install -y linux-headers-$(uname -r)
Then rebuild and load the modules:
sudo /sbin/vboxconfig
sudo modprobe vboxdrv
Kernel Module Build Fails After Kernel Update
After a kernel update, VirtualBox modules need to be rebuilt for the new kernel. DKMS usually handles this automatically, but if it does not:
sudo apt install -y linux-headers-$(uname -r)
sudo dpkg-reconfigure virtualbox-dkms
sudo /sbin/vboxconfig
Verify the modules are loaded:
lsmod | grep vbox
Secure Boot Blocking vboxdrv
If your system has Secure Boot enabled, unsigned kernel modules like vboxdrv will be blocked. You have two options:
Option 1 – Disable Secure Boot in your BIOS/UEFI settings. This is the simpler approach.
Option 2 – Sign the VirtualBox kernel modules with a Machine Owner Key (MOK):
sudo apt install -y mokutil
openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=VirtualBox Signing Key/"
sudo mokutil --import MOK.der
Reboot and enroll the key when prompted by the MOK manager. Then sign the modules:
sudo /usr/src/linux-headers-$(uname -r)/scripts/sign-file sha256 ./MOK.priv ./MOK.der $(modinfo -n vboxdrv)
sudo modprobe vboxdrv
NS_ERROR_FAILURE or VM Won’t Start
This generic error often means hardware virtualization (VT-x/AMD-V) is disabled in the BIOS. Enter your BIOS settings and enable Intel VT-x or AMD-V under CPU configuration.
You can check from Linux whether virtualization is available:
egrep -c '(vmx|svm)' /proc/cpuinfo
If the result is 0, hardware virtualization is not enabled.
USB Devices Not Visible in Guest
Make sure the Extension Pack is installed and your user is in the vboxusers group:
VBoxManage list extpacks
groups $USER | grep vboxusers
If vboxusers is not listed, add yourself and log out/in again:
sudo usermod -aG vboxusers $USER
Conclusion
You now have VirtualBox 7.1 running on Debian 13 or Debian 12 with the Extension Pack, proper kernel modules, and a working CLI workflow for creating and managing virtual machines. Whether you are running VMs on a desktop workstation or headless on a remote server, VBoxManage gives you full control without needing the GUI. Guest Additions improve performance inside your VMs, and the networking options give you the flexibility to set up anything from isolated test labs to production-like network topologies.































































Hi there!
I followed this steps and when I run sudo /sbin/vboxconfig it showing the following message.
And when I run command: uname -r the result is: 5.15.95-16520-g682786dc5340
Please help. Thank you
vboxdrv.sh: Stopping VirtualBox services.
libkmod: ERROR ../libkmod/libkmod-module.c:1668 kmod_module_new_from_loaded: could not open /proc/modules: No such file or directory
Error: could not get list of modules: No such file or directory
libkmod: ERROR ../libkmod/libkmod-module.c:1668 kmod_module_new_from_loaded: could not open /proc/modules: No such file or directory
Error: could not get list of modules: No such file or directory
libkmod: ERROR ../libkmod/libkmod-module.c:1668 kmod_module_new_from_loaded: could not open /proc/modules: No such file or directory
Error: could not get list of modules: No such file or directory
vboxdrv.sh: Starting VirtualBox services.
libkmod: ERROR ../libkmod/libkmod-module.c:1668 kmod_module_new_from_loaded: could not open /proc/modules: No such file or directory
Error: could not get list of modules: No such file or directory
vboxdrv.sh: Building VirtualBox kernel modules.
This system is currently not set up to build kernel modules.
Please install the Linux kernel “header” files matching the current kernel
for adding new hardware support to the system.
This system is currently not set up to build kernel modules.
Please install the Linux kernel “header” files matching the current kernel
for adding new hardware support to the system.
There were problems setting up VirtualBox. To re-start the set-up process, run
/sbin/vboxconfig
as root. If your system is using EFI Secure Boot you may need to sign the
kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load
them. Please see your Linux system’s documentation for more information.
Thank you very much for this guide !!!
I didn’t knew there was a virtualbox repository all that !
Yes very powerful!