How to Set Up a Virtual Machine Using VirtualBox on Debian 12 Bookworm
Categories:
5 minute read
Virtualization is a powerful tool that allows users to run multiple operating systems on a single physical machine. Whether you’re a system administrator, software developer, or enthusiast, using virtual machines (VMs) can greatly enhance your flexibility, security, and experimentation capabilities. One of the most accessible and widely-used virtualization tools is VirtualBox, an open-source hypervisor developed by Oracle.
In this article, we’ll guide you step-by-step on how to set up a virtual machine using VirtualBox on a Debian 12 Bookworm system. By the end, you’ll be able to install VirtualBox, configure a VM, and run an operating system inside it.
Table of Contents
- Introduction to VirtualBox
- Prerequisites
- Installing VirtualBox on Debian 12
- Setting Up a Virtual Machine
- Installing an Operating System in the Virtual Machine
- Post-Installation Configuration
- Tips and Best Practices
- Conclusion
1. Introduction to VirtualBox
VirtualBox is a cross-platform virtualization application that supports various guest operating systems including Linux, Windows, macOS, BSD, and others. It’s especially useful for:
- Running test environments
- Isolating applications
- Learning new operating systems
- Creating repeatable development setups
VirtualBox allows you to simulate hardware components (CPU, memory, disk, network, USB, etc.) and provides snapshots, shared folders, and other advanced features.
2. Prerequisites
Before we begin, ensure that your system meets the following prerequisites:
- Operating System: Debian 12 Bookworm (up-to-date)
- User Privileges: A user with
sudo
privileges - Hardware: A processor that supports virtualization (VT-x for Intel or AMD-V for AMD)
- RAM: At least 4GB (8GB or more recommended for running VMs smoothly)
- Disk Space: Sufficient free disk space (at least 20GB recommended)
You should also enable virtualization support in your system BIOS/UEFI if it’s not already enabled.
3. Installing VirtualBox on Debian 12
Step 1: Update Your System
Always begin by updating your package list:
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Dependencies
Install essential packages required by VirtualBox:
sudo apt install -y build-essential dkms linux-headers-$(uname -r)
Step 3: Add VirtualBox Repository
Oracle provides an official repository for VirtualBox. Let’s add it.
First, download and add Oracle’s public key:
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo gpg --dearmor -o /usr/share/keyrings/oracle_vbox.gpg
Now add the repository to your sources list:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle_vbox.gpg] https://download.virtualbox.org/virtualbox/debian bookworm contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
Step 4: Install VirtualBox
Update the package index and install VirtualBox:
sudo apt update
sudo apt install -y virtualbox-7.0
Check if the installation succeeded:
vboxmanage --version
You should see the version output, confirming that VirtualBox is installed correctly.
4. Setting Up a Virtual Machine
Once VirtualBox is installed, you can create and configure a new virtual machine.
Step 1: Launch VirtualBox
You can launch VirtualBox from the application menu or run:
virtualbox
Step 2: Create a New Virtual Machine
- Click “New” to begin the VM creation process.
- Name your virtual machine (e.g., “UbuntuTest”).
- Type: Choose Linux (or another OS if needed).
- Version: Select the appropriate version, e.g., “Ubuntu (64-bit)” for Ubuntu.
- Memory Size: Allocate RAM (at least 2048 MB for basic Linux use).
- Hard Disk:
- Choose “Create a virtual hard disk now”.
- Click “Create”.
Step 3: Configure the Virtual Hard Disk
Choose the disk file type:
- VDI (VirtualBox Disk Image) is the default and generally fine.
Storage on physical hard disk:
- Dynamically allocated allows the disk to grow as needed.
- Fixed size reserves the full size upfront but may offer better performance.
Set the size of the virtual disk (e.g., 20GB), then click Create.
5. Installing an Operating System in the Virtual Machine
Step 1: Insert ISO Image
With your VM created, you now need to install an OS using an ISO file.
- Select the VM and click Settings → Storage.
- Under Controller: IDE, click the empty CD icon, then click the disk icon on the right → “Choose a disk file”.
- Select your ISO image (e.g., Ubuntu ISO) and click OK.
Step 2: Start the VM
Click Start. The VM should boot from the ISO and begin the OS installation process, just like it would on a real machine.
Step 3: Follow the Installation Instructions
Install the OS inside the VM as you would on a physical machine. Once installation is complete, you may need to:
- Remove the ISO from the virtual CD/DVD drive (Settings → Storage).
- Restart the VM to boot from the virtual disk.
6. Post-Installation Configuration
Install Guest Additions
To improve performance and integration (e.g., shared clipboard, better display resolution), install VirtualBox Guest Additions.
- Start the VM and log into the guest OS.
- Click Devices → Insert Guest Additions CD Image from the VM window menu.
- Run the installer in the guest system. For example, in a Linux guest:
sudo mkdir /media/cdrom
sudo mount /dev/cdrom /media/cdrom
cd /media/cdrom
sudo ./VBoxLinuxAdditions.run
Restart the guest OS once the installation completes.
Enable Shared Clipboard and Drag’n’Drop
From the VM window:
- Go to Devices → Shared Clipboard → set to Bidirectional
- Go to Devices → Drag and Drop → set to Bidirectional
Configure Network Settings
VirtualBox offers several network modes:
- NAT (default): Good for most use cases.
- Bridged Adapter: Allows the VM to be on the same LAN as the host.
- Host-only Adapter: For isolated testing environments.
To change network settings, go to Settings → Network for the VM.
7. Tips and Best Practices
Use Snapshots
Snapshots allow you to save the state of a VM. You can revert to a snapshot if something breaks:
- Go to Machine → Take Snapshot
Manage Disk Usage
Use dynamically allocated disks to save space, but monitor VM sizes with:
du -sh ~/VirtualBox\ VMs
Keep Guest Additions Updated
Update Guest Additions if you upgrade VirtualBox to maintain functionality.
Backup Your VMs
Regularly back up VM folders (~/VirtualBox VMs
) or export them via File → Export Appliance.
8. Conclusion
Setting up a virtual machine using VirtualBox on Debian 12 Bookworm is straightforward and efficient. It empowers users to explore different operating systems, create isolated development environments, or test software securely without the risk of harming the host system.
To recap, we covered:
- Installing VirtualBox on Debian 12
- Creating a virtual machine
- Installing a guest operating system
- Configuring guest features and network
- Best practices for efficient use
VirtualBox remains a dependable and user-friendly choice for desktop virtualization. Whether you’re experimenting with Linux distributions, setting up test labs, or running older applications, VirtualBox has the flexibility to meet your needs.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.