In this post, I will install VirtualBox 7.2 on my laptop which is running Kubuntu 24.04 LTS using the command line. Why not install using the GUI since that is easier? I felt it would be a good learning opportunity and it turned out that I was right!
Installation
The first step is to add the VirtualBox repository. Download the signing key:
wget https://download.virtualbox.org/download/oracle_vbox_2016.asc -O ~/Downloads/oracle_vbox_2016.asc
Import the signing key:
sudo gpg --yes --output /usr/share/keyrings/oracle-virtualbox-2016.gpg --dearmor ~/Downloads/oracle_vbox_2016.asc
Create the file /etc/apt/sources.list.d/virtualbox.sources and give it the following contents:
Types: deb
URIs: https://download.virtualbox.org/virtualbox/debian
Suites: noble
Components: contrib
Architectures: amd64
Signed-By: /usr/share/keyrings/oracle-virtualbox-2016.gpg
Then update the package list and install VirtualBox:
sudo apt update
sudo apt install virtualbox-7.2
VirtualBox will conflict with the KVM modules which are included in the kernel by default. Unload the KVM modules:
sudo modprobe -r kvm_intel
sudo modprobe -r kvm
The KVM modules will load on the next reboot unless they are blacklisted. Add the following lines to the /etc/modprobe.d/blacklist.conf file and then reboot:
blacklist kvm_intel
blacklist kvm
Then install the VirtualBox extension pack to enable some additional features. Start by downloading it:
wget https://download.virtualbox.org/virtualbox/7.2.4/Oracle_VirtualBox_Extension_Pack-7.2.4.vbox-extpack
And then install it:
sudo VBoxManage extpack install ./Oracle_VirtualBox_Extension_Pack-7.2.4.vbox-extpack
Configuration
The next step is to configure a directory to store the VMs and set permissions for the user account that will run VirtualBox. Start by adding the user to the vboxusers group:
sudo usermod -aG vboxusers bunny
Then create a directory to store the VMs and make the user the owner of the directory:
sudo mkdir /vbox
sudo chown -R bunny:bunny /vbox/
I created a host only network. The host only network allows VMs to communicate with each other and with the host, but not with external networks. I will have the VMs connected to this network most of the time and only connect them to the external network to download updates or packages as necessary. This is probably not the best setup, but it works well for my current needs.
Creating the network:
VBoxManage hostonlyif create
The network name will be vboxnet0 by default and have a DHCP server enabled. Both values can also be changed by specifying different values in the command.
Create VMs
I created a script to create VMs. It will be available on GitHub. The script contents are shown below:
#!/bin/bash
# Author: Duncan (www.linuxbunny.com)
# Date: 2025-11-22
# Free for personal/non-commercial use
# Modify the variables below as appropriate for your environment
# Begin Variables
VMNAME="Rocky_91"
ISO="/home/duncan/Downloads/ISO/Rocky-9.6-x86_64-dvd.iso"
BASEFOLDER="/vbox"
OSTYPE="RedHat_64"
DISKSIZEMB=128000
MEMORYMB=1024
CPUS=1
CPUEXECUTIONCAP=100
ADAPTER="vboxnet0"
GRAPHICSCONTROLLER="vmsvga"
USB="off"
# Change PAE to off if your CPU does not support Physical Address Extension
PAE="on"
# Change HWVIRTEX and NESTEDPAGING to off if your CPU does not support VT-d/VT-x hardware virtualization
HWVIRTEX="on"
NESTEDPAGING="on"
# Change IOAPIC to off if your VM OS is 32-bit and uses a single virtual CPU
IOAPIC="on"
# Turn ACCELERATE3D on and set VRAM to at least 128 if your VM will use a GUI
ACCELERATE3D="off"
VRAM=16
# End Variables
echo "Creating the "$VMNAME" VM."
VBoxManage createhd --filename "$BASEFOLDER"/"$VMNAME"/"$VMNAME".vdi --size "$DISKSIZEMB"
VBoxManage createvm --register --name "$VMNAME" --basefolder "$BASEFOLDER" --ostype "$OSTYPE"
VBoxManage storagectl "$VMNAME" --name "SATA Controller" --add sata --controller IntelAHCI
VBoxManage storageattach "$VMNAME" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$BASEFOLDER"/"$VMNAME"/"$VMNAME".vdi
VBoxManage storagectl "$VMNAME" --name "IDE Controller" --add ide
VBoxManage storageattach "$VMNAME" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium "$ISO"
VBoxManage modifyvm "$VMNAME" --memory "$MEMORYMB"
VBoxManage modifyvm "$VMNAME" --boot1 dvd --boot2 disk --boot3 none --boot4 none
VBoxManage modifyvm "$VMNAME" --chipset piix3
VBoxManage modifyvm "$VMNAME" --ioapic "$IOAPIC"
VBoxManage modifyvm "$VMNAME" --mouse ps2
VBoxManage modifyvm "$VMNAME" --cpus "$CPUS" --cpuexecutioncap "$CPUEXECUTIONCAP" --pae "$PAE"
VBoxManage modifyvm "$VMNAME" --hwvirtex "$HWVIRTEX" --nestedpaging "$NESTEDPAGING"
VBoxManage modifyvm "$VMNAME" --nic1 hostonly --hostonlyadapter1 "$ADAPTER"
VBoxManage modifyvm "$VMNAME" --vram "$VRAM"
VBoxManage modifyvm "$VMNAME" --graphicscontroller "$GRAPHICSCONTROLLER"
VBoxManage modifyvm "$VMNAME" --accelerate3d "$ACCELERATE3D"
VBoxManage modifyvm "$VMNAME" --audio-driver none
VBoxManage modifyvm "$VMNAME" --snapshotfolder "$BASEFOLDER"/"$VMNAME"/Snapshots
VBoxManage modifyvm "$VMNAME" --clipboard bidirectional
VBoxManage modifyvm "$VMNAME" --usb "$USB"
echo "VM "$VMNAME" created."
exit 0
Installing Guest Additions in VMs
The final step is to install the VirtualBox Guest Additions within the created VMs. The Guest Additions improve VM performance and add additional features. All commands below should be run within the VM. I used a Rocky Linux 9.6 VM here.
Start by updating the packages:
sudo dnf update
Reboot the VM in case the updates included a kernel update. Then install prerequisite packages:
sudo dnf install kernel-headers kernel-devel gcc make perl bzip2 elfutils-libelf-devel -y
Next, in the VM’s VirtualBox window, select Devices > Insert Guest Additions CD Image. Then mount the CD:
sudo mkdir /mnt/vboxadditions
sudo mount /dev/cdrom /mnt/vboxadditions
cd /mnt/vboxadditions
Run the installation script:
sudo ./VBoxLinuxAdditions.run
Finish by unmounting the CD and rebooting:
cd /
sudo umount /mnt/vboxadditions
sudo rmdir /mnt/vboxadditions
sudo reboot now

Leave a Reply