$linuxjunkies
>

Install Linux in a Virtual Machine

Install Linux in VirtualBox or KVM (GNOME Boxes/virt-manager), configure guest additions for clipboard and display, and take snapshots for safe experimentation.

BeginnerUbuntuDebianFedoraArch9 min readUpdated June 7, 2026

Before you start

  • 64-bit host CPU with Intel VT-x or AMD-V enabled in UEFI/BIOS
  • At least 8 GB host RAM and 20 GB free disk space
  • A downloaded ISO of the Linux distro you want to install
  • sudo / administrator access on the host system

Running Linux inside a virtual machine is the safest way to experiment, learn, or test software without touching your main system. This guide covers two practical paths: VirtualBox (cross-platform, feature-rich) and GNOME Boxes / virt-manager (native Linux, KVM-backed, faster). Both get you to a working guest, guest additions, and snapshots.

Choose Your Virtualisation Stack

Before installing anything, pick the right tool for your situation:

  • VirtualBox — runs on Windows, macOS, and Linux. Good if your host is Windows or you want a GUI-first experience with wide tutorial coverage. Uses its own hypervisor.
  • GNOME Boxes — dead-simple frontend to QEMU/KVM. Ships by default on GNOME desktops. Best for quick Linux-on-Linux setups.
  • virt-manager — full-featured KVM/QEMU GUI. More control than Boxes; supports virtual networks, PCIe passthrough, and complex storage layouts. The right choice once you outgrow Boxes.

KVM (GNOME Boxes / virt-manager) runs closer to bare metal than VirtualBox because it uses hardware virtualisation directly through the Linux kernel. For serious workloads on a Linux host, prefer KVM.

Prerequisites

  • A 64-bit host with hardware virtualisation enabled in UEFI/BIOS (Intel VT-x or AMD-V). Check with: grep -Eoc '(vmx|svm)' /proc/cpuinfo — any number above 0 means you're good.
  • At least 8 GB RAM on the host (4 GB is workable but tight).
  • 20 GB free disk space minimum per guest.
  • An ISO of the Linux distro you want to install. Ubuntu 24.04 LTS is used in examples below.

Path A: VirtualBox

1. Install VirtualBox

On a Linux host, install from your distro's repository or the official Oracle repo. The distro package is easiest but may lag behind upstream.

Debian / Ubuntu:

sudo apt update && sudo apt install virtualbox virtualbox-ext-pack

Fedora / RHEL / Rocky — enable the RPM Fusion free repo first:

sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install VirtualBox

Arch:

sudo pacman -S virtualbox virtualbox-host-modules-arch

On Arch, load the kernel module now and on every boot:

sudo modprobe vboxdrv
sudo systemctl enable --now vboxdrv.service

Add your user to the vboxusers group, then log out and back in:

sudo usermod -aG vboxusers $USER

2. Create a New Virtual Machine

Launch VirtualBox and click New. Walk through the wizard:

  • Name your VM (e.g., Ubuntu 24.04).
  • Set Type: Linux, Version: Ubuntu (64-bit).
  • RAM: allocate at least 2048 MB; 4096 MB is comfortable for a desktop guest.
  • Create a new virtual hard disk — VDI format, dynamically allocated, 25 GB minimum.

Before starting, open Settings → Storage, click the empty optical drive, and attach your ISO. Under Settings → Display, raise Video Memory to 128 MB and enable 3D Acceleration.

3. Install the Guest OS

Start the VM. It boots from the ISO. Follow the standard installer for your chosen distro — nothing VM-specific is needed here. When installation finishes, the VM will prompt you to remove the installation medium; VirtualBox usually handles this automatically. Reboot the guest.

4. Install VirtualBox Guest Additions

Guest Additions provide clipboard sharing, drag-and-drop, auto-resize, and significantly better display performance. Inside the running guest, from the VirtualBox menu bar choose Devices → Insert Guest Additions CD image…

Then in the guest terminal:

sudo apt update && sudo apt install -y build-essential dkms linux-headers-$(uname -r)
sudo mount /dev/cdrom /mnt
sudo /mnt/VBoxLinuxAdditions.run

Reboot the guest after the script completes. You should immediately see the window auto-resize when you drag the VirtualBox window border.

Note: On Fedora/RHEL guests, replace the apt line with:

sudo dnf install -y gcc kernel-devel kernel-headers dkms make bzip2 perl

Path B: GNOME Boxes (Quick KVM)

1. Install GNOME Boxes

Debian / Ubuntu:

sudo apt install gnome-boxes

Fedora (often pre-installed):

sudo dnf install gnome-boxes

Arch:

sudo pacman -S gnome-boxes

2. Create a VM in Boxes

Open Boxes and click the + button. You can let Boxes download an ISO directly (it lists popular distros), or choose Use a file and point it at a local ISO. Set RAM and disk on the next screen — Boxes picks sensible defaults. Click Create and the VM starts immediately, booting your ISO. Install the OS normally.

Boxes installs spice-vdagent and qemu-guest-agent automatically in recognised guest distros, so clipboard integration and display scaling work out of the box after installation. If auto-install didn't trigger, install manually inside the guest:

# Debian/Ubuntu guest
sudo apt install spice-vdagent qemu-guest-agent
sudo systemctl enable --now spice-vdagentd qemu-guest-agent

Path C: virt-manager (Full KVM Control)

1. Install KVM and virt-manager

Debian / Ubuntu:

sudo apt install qemu-kvm libvirt-daemon-system virt-manager
sudo usermod -aG libvirt,kvm $USER

Fedora:

sudo dnf install @virtualization
sudo usermod -aG libvirt $USER

Arch:

sudo pacman -S qemu-desktop libvirt virt-manager dnsmasq
sudo usermod -aG libvirt $USER

Enable and start the libvirt daemon, then re-login so group membership takes effect:

sudo systemctl enable --now libvirtd

2. Create a VM in virt-manager

Open virt-manager, double-click the local QEMU/KVM connection, and choose File → New Virtual Machine. Select Local install media, browse to your ISO, set RAM (2–4 GiB), and create a disk image (25 GiB+). On the final screen, tick Customize configuration before install if you want to change firmware to UEFI. Click Begin Installation.

For guest integration (clipboard, resolution scaling), install the same spice and guest-agent packages shown in Path B inside the guest.

Taking and Restoring Snapshots

Snapshots let you capture the VM state before a risky change and roll back instantly if something breaks.

Snapshots in VirtualBox

With the VM powered off or paused, open the Snapshots panel (top-right icon in the VM list). Click Take, give the snapshot a meaningful name (e.g., Clean install), and click OK. To restore, select the snapshot and click Restore.

You can also snapshot from the command line:

VBoxManage snapshot "Ubuntu 24.04" take "Clean install" --description "Fresh OS, no extra packages"

Snapshots with virsh (KVM)

# Create a snapshot (VM can be running)
virsh snapshot-create-as --domain ubuntu2404 \
  --name "clean-install" \
  --description "Fresh install" \
  --atomic

# List snapshots
virsh snapshot-list ubuntu2404

# Revert
virsh snapshot-revert ubuntu2404 clean-install

Important: External snapshots work on any storage format; internal snapshots require qcow2. Always use qcow2 virtual disks with KVM for full snapshot support.

Verify Everything Works

Inside your running guest, confirm hardware acceleration is active:

systemd-detect-virt

Expected output: oracle for VirtualBox, kvm for GNOME Boxes or virt-manager. If it returns none, hardware virtualisation may not be enabled in your UEFI settings.

Check that the SPICE/VirtualBox display agent is running (KVM path):

systemctl is-active spice-vdagentd

Troubleshooting

  • "VT-x is disabled in BIOS" — Reboot the host, enter UEFI setup, and enable Intel VT-x or AMD-V (sometimes labelled SVM). On some laptops, Hyper-V on Windows must also be disabled before VirtualBox can access VT-x.
  • Guest Additions compilation fails — Kernel headers are missing or mismatched. Confirm with uname -r and make sure linux-headers-$(uname -r) (Debian/Ubuntu) or kernel-devel-$(uname -r) (Fedora) is installed.
  • Low display resolution in KVM guest and can't resize — spice-vdagent isn't running. Install and enable it as shown above. Also verify the VM display type is set to Virtio or QXL, not VGA, in virt-manager's display settings.
  • libvirtd fails to start / no default network — Run sudo virsh net-autostart default && sudo virsh net-start default to bring up the default NAT bridge.
  • Clipboard sharing not working in VirtualBox — Go to Settings → General → Advanced and set Shared Clipboard to Bidirectional. Requires Guest Additions to be installed.
tested on:Ubuntu 24.04Fedora 40Arch 2024.05Debian 12

Frequently asked questions

Which is faster, VirtualBox or KVM?
KVM (used by GNOME Boxes and virt-manager) is generally faster on a Linux host because it runs as a kernel module, removing one hypervisor layer. VirtualBox is more portable and easier to use cross-platform, but for Linux-on-Linux workloads KVM wins on performance.
How much RAM should I give the virtual machine?
2 GiB is the minimum for a functional Linux desktop guest; 4 GiB is comfortable. Never assign more than half your host's physical RAM, or both the host and guest will start swapping heavily.
Can I run a VM while Secure Boot is enabled on the host?
Yes for KVM on most distros — the kernel modules are signed. VirtualBox may fail to load kernel modules with Secure Boot unless you enroll the VirtualBox MOK (Machine Owner Key) during installation or disable Secure Boot. Follow your distro's specific VirtualBox Secure Boot instructions.
Do snapshots use a lot of disk space?
Each snapshot stores only the changes (delta) from the previous state, so an initial snapshot of a fresh install is small. Snapshots grow as you write more data to the VM. Delete old snapshots you no longer need to reclaim space.
Can I copy files between the host and the guest?
Yes. With VirtualBox Guest Additions installed, you can set up a shared folder under Settings → Shared Folders. With KVM/SPICE, drag-and-drop and clipboard work after installing spice-vdagent. Alternatively, use SSH or scp if the guest has a network connection.

Related guides