How to Configure a Guest Operating System in a Virtual Machine on Debian 12 Bookworm
Categories:
6 minute read
Virtualization has become a cornerstone of modern computing, enabling users to run multiple operating systems on a single hardware platform. Whether you’re testing software, running legacy systems, or setting up isolated development environments, virtualization provides flexibility, efficiency, and security. Debian 12 “Bookworm”, known for its stability and robustness, offers a solid foundation for setting up virtual machines (VMs) using various tools.
This guide walks you through how to configure a guest operating system in a virtual machine on a Debian 12 system, covering both the setup of the virtualization environment and the installation of the guest OS
1. Introduction to Virtualization on Debian 12
Virtualization allows you to create and run virtual machines on a host operating system, isolating applications, operating systems, and user environments. Debian supports multiple virtualization technologies, but KVM (Kernel-based Virtual Machine) is one of the most commonly used and well-supported on Debian systems.
KVM, combined with QEMU (Quick Emulator), provides a powerful, open-source virtualization solution. Tools like virt-manager
(Virtual Machine Manager) offer a GUI for managing VMs, while virsh
and virt-install
cater to command-line users.
2. Choosing a Virtualization Technology
Before proceeding, you should choose a virtualization approach based on your needs:
- KVM + QEMU: Best for full virtualization with excellent performance.
- VirtualBox: Easier to set up for beginners, but with slightly lower performance.
- VMware Workstation: Proprietary and requires a license, but has good hardware compatibility.
This article will focus on KVM/QEMU, as it is fully open-source and integrates well with Debian 12.
3. Installing Required Packages
First, update your system and install the necessary packages.
Step 1: Update System
sudo apt update && sudo apt upgrade -y
Step 2: Install Virtualization Packages
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager -y
This will install:
qemu-kvm
: The QEMU full system emulator with KVM supportlibvirt-daemon-system
andlibvirt-clients
: For managing VMsbridge-utils
: For advanced network configurationvirt-manager
: GUI interface for VM management
Step 3: Add User to libvirt Group
sudo usermod -aG libvirt $(whoami)
Then, log out and log back in for the changes to take effect.
Step 4: Check if KVM is Supported
egrep -c '(vmx|svm)' /proc/cpuinfo
A value greater than 0 means that your CPU supports hardware virtualization.
4. Creating and Managing Virtual Machines with virt-manager
Step 1: Launch Virtual Machine Manager
Open Virtual Machine Manager from the application menu or by running:
virt-manager
It will prompt for your root password to access the libvirt service.
Step 2: Create a New Virtual Machine
Click on the “Create a new virtual machine” icon. A wizard will guide you through the following:
a. Choose Installation Method
You can install the guest OS from:
- Local ISO image
- Network installation
- PXE boot
- Existing disk image
Choose Local install media (ISO image or CDROM) and click Forward.
b. Choose Installation Media
Browse and select the ISO file of the operating system you want to install (e.g., Ubuntu, Fedora, or another instance of Debian).
Virt-manager may attempt to automatically detect the OS from the ISO. If not, you can specify it manually.
c. Assign Memory and CPU
Allocate the desired amount of RAM and number of CPUs. For example:
- Memory: 2048 MB
- CPUs: 2
These values depend on your host system’s resources.
d. Create Virtual Disk
You will be prompted to create a virtual disk. Choose a size that matches your needs (e.g., 20 GB for a minimal install). This will be created in QCOW2 format by default, which is space-efficient.
e. Configure Network
The default “NAT” network is usually sufficient for internet access. You can later change this to a bridged or host-only adapter if needed.
f. Final Step
Give your virtual machine a name and click Finish. The guest OS will now boot from the ISO, and you can proceed with the installation.
5. Installing a Guest Operating System
After launching the VM, you’ll go through the standard installation process of the selected guest operating system.
For example, if you’re installing Debian 12 as the guest OS:
- Select Install or Graphical Install
- Choose your language, locale, and keyboard layout
- Configure the network (typically DHCP via NAT)
- Partition the virtual disk (guided partitioning is fine for most users)
- Set up users and passwords
- Install the base system and select desired software packages
- Install the GRUB bootloader
- Finish installation and reboot the VM
After installation, the guest OS will boot into its own environment.
6. Post-Installation Configuration of the Guest OS
a. Install Guest Additions / QEMU Agent
For enhanced integration (like clipboard sharing, window resizing, and better performance), you can install qemu-guest-agent
inside the guest OS:
On Debian/Ubuntu guest:
sudo apt install qemu-guest-agent -y
Then, enable and start the service:
sudo systemctl enable --now qemu-guest-agent
b. Network Configuration
If the default NAT networking does not suit your needs, you can change the network interface settings in virt-manager
to use a Bridged Adapter. This allows the guest OS to get an IP on the same network as the host.
To configure this:
- Shut down the VM
- Open VM Details → NIC
- Set “Network source” to Bridge br0 (if configured on host)
- Apply and reboot the VM
You may also need to configure bridge networking on the host using bridge-utils
.
c. Enable Shared Clipboard and Drag-Drop (Optional)
Some features like shared clipboard and drag-and-drop may require installing spice-vdagent:
sudo apt install spice-vdagent -y
Make sure the display is using SPICE in virt-manager
.
d. Resize the VM’s Disk (Optional)
If you find the disk size too small, you can resize it using:
qemu-img resize /var/lib/libvirt/images/your-vm.qcow2 +10G
Then, extend the partition from within the guest OS using gparted
or parted
.
7. Common Troubleshooting Tips
1. Virtual machine won’t start?
Ensure the virtualization module is loaded:
lsmod | grep kvm
If not, try:
sudo modprobe kvm_intel # For Intel CPUs
sudo modprobe kvm_amd # For AMD CPUs
2. Cannot open virt-manager as a regular user?
Make sure your user is in the libvirt
group and relogin.
3. Guest has no internet access?
Check if libvirtd
service is running:
sudo systemctl status libvirtd
4. Clipboard and display features not working?
Ensure SPICE and spice-vdagent
are installed on the guest, and the display is set to SPICE.
8. Conclusion
Virtual machines are an indispensable tool for developers, system administrators, and hobbyists alike. On Debian 12 Bookworm, setting up a guest operating system using KVM and QEMU is not only efficient but also well-supported with graphical and command-line tools. From installing required packages to configuring post-install features like shared folders and networking, the process is manageable even for users with intermediate Linux experience.
Once configured, your guest OS runs almost like a separate physical machine, enabling testing, development, and exploration without altering your main system.
Whether you’re hosting another Linux distro, Windows, or BSD, Debian 12 makes a great host system for all your virtualization 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.