sodcalculator

10 Tech How-To

Run a Virtual Machine in Linux: Step-by-Step

Guide 10-9746 · Updated · Step by step

Running a virtual machine (VM) on Linux lets you install and use another operating system inside a window, without rebooting or affecting your main system. This guide shows you how to create a VM using the KVM/QEMU stack with the Virtual Machine Manager GUI, which is fast, free, and built into most Linux distributions. You’ll need a Linux machine with a 64-bit CPU that supports virtualization (Intel VT-x or AMD-V), at least 4 GB of RAM (8 GB recommended), and about 20 GB of free disk space for the guest OS.

What You’ll Need

  • A Linux distribution (Ubuntu, Fedora, Debian, etc.) with a graphical desktop.
  • An ISO image of the operating system you want to install (e.g., Windows, another Linux distro, or a BSD).
  • Root or sudo access to install packages and create the VM.
  • Virtualization enabled in your BIOS/UEFI (check with egrep -c '(vmx|svm)' /proc/cpuinfo; a number greater than 0 means it’s on).

Step-by-Step

  1. Check virtualization support. Open a terminal and run egrep -c '(vmx|svm)' /proc/cpuinfo. If the output is 0, you need to enable virtualization in your BIOS/UEFI settings (look for “Intel VT-x” or “AMD-V”) and reboot.
  2. Install the required packages. On Debian/Ubuntu, run sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager. On Fedora, use sudo dnf install @virtualization. On Arch, sudo pacman -S qemu libvirt virt-manager. These commands install the KVM hypervisor, the libvirt management library, and the graphical manager.
  3. Start and enable the libvirt service. Run sudo systemctl enable --now libvirtd. Then add your user to the libvirt group so you can manage VMs without root: sudo usermod -aG libvirt $USER. Log out and back in for the group change to take effect.
  4. Launch Virtual Machine Manager. Open it from your application menu (search for “Virtual Machine Manager”) or run virt-manager in a terminal. It will show a window with a list of VMs (initially empty) and a toolbar.
  5. Create a new VM. Click the “Create a new virtual machine” button (the icon with a monitor and a plus sign). The wizard starts.
  6. Choose installation method. Select “Local install media (ISO image or CDROM)” and click Forward.
  7. Browse for the ISO. Click “Browse…”, then “Browse Local” in the popup, and select your ISO file. After selecting, Virtual Machine Manager usually auto-detects the OS type and version. If not, pick them from the dropdowns manually. Click Forward.
  8. Set RAM and CPU. Allocate at least 2 GB RAM (2048 MB) and 2 CPU cores for a modern OS. For a lightweight Linux, 1 GB and 1 core is fine. Click Forward.
  9. Create a virtual disk. Choose “Enable storage for this virtual machine” and set a disk size (e.g., 20 GB). Leave “Allocate entire disk now” unchecked for a sparse file that grows as needed, or check it for better performance. Click Forward.
  10. Name and finalize. Give the VM a name (e.g., “Windows10”). Before clicking Finish, check “Customize configuration before install” if you want to tweak hardware like network or sound. Otherwise, click Finish.
  11. Install the OS. The VM window opens and boots from the ISO. Follow the normal installation steps for your guest OS. When it asks for a disk, select the virtual disk (usually /dev/vda).
  12. Install guest drivers (optional but recommended). After the OS is installed, install the virtio drivers for better performance. For Windows, download the virtio-win ISO and mount it. For Linux, the drivers are usually already included.

Common Mistakes

  • Forgetting to enable virtualization in BIOS. This is the most common reason KVM fails. The CPU check in step 1 is essential.
  • Not adding your user to the libvirt group. Without this, you’ll get “permission denied” errors when trying to create or start a VM.
  • Allocating too little RAM. A Windows 10/11 VM needs at least 2 GB, but 4 GB is much smoother. If your host has 8 GB, give the VM 4 GB.
  • Choosing the wrong disk type. If you see “Cannot access storage file” or the guest can’t find the disk, make sure you used the default virtio disk, not an IDE one (unless you’re installing Windows without virtio drivers).
  • Ignoring the ISO path. If the ISO is on a network drive or a location with spaces, the wizard may fail. Copy it to a local folder like ~/Downloads first.

Tips

  • Use a sparse disk image (unchecked “Allocate entire disk now”) to save space; it only uses what the guest actually writes.
  • Enable KVM hardware acceleration by making sure the VM’s CPU model is set to “host-passthrough” in the VM’s CPU settings. This gives near-native performance.
  • Take snapshots before major updates or risky changes in the guest. In Virtual Machine Manager, right-click the VM and choose “Snapshot” to save the current state.
  • To share files between host and guest, set up a shared folder using virtiofs (for Linux guests) or Samba (for Windows).
  • If you’re running a headless server, you can use virt-install from the command line instead of the GUI.

Troubleshooting

  • “KVM is not available” error when starting the VM. Check that virtualization is enabled in BIOS and that the kvm module is loaded (lsmod | grep kvm). If not, run sudo modprobe kvm_intel or sudo modprobe kvm_amd.
  • VM starts but shows a black screen. This often happens with Windows guests when the virtio video driver isn’t installed. Switch the display to “VGA” in the VM’s video settings, or install the virtio-win drivers.
  • Cannot connect to the network in the guest. The default NAT network should work. If not, ensure the default network is active: sudo virsh net-start default and sudo virsh net-autostart default.
  • Permission denied when running virt-manager. Log out and back in after adding yourself to the libvirt group, or run newgrp libvirt in the terminal.
  • The VM is very slow. Increase RAM and CPU, and make sure KVM acceleration is active (check the VM’s “Overview” tab; it should say “Hypervisor: KVM”). If it says QEMU, the VM is emulating, not using hardware acceleration.

Frequently Asked Questions

Can I run VirtualBox on Linux instead of KVM?

Yes, VirtualBox works on Linux and is easier for beginners, but KVM is faster and more integrated with the Linux kernel. If you prefer VirtualBox, install it from your package manager and follow its own wizard.

How much RAM should I give a VM?

For a Windows 10/11 guest, at least 4 GB. For a lightweight Linux desktop, 2 GB is enough. Never allocate more than half of your host’s RAM, or the host will start swapping.

Can I run a 32-bit OS in a VM?

Yes, KVM supports 32-bit guests, but you may need to enable 32-bit CPU features in the VM’s CPU settings. Most modern Linux distros are 64-bit, so check your ISO.

How do I copy files between host and guest?

Use a shared folder via virtiofs (Linux guests) or Samba (Windows). Alternatively, use a USB drive attached to the VM, or set up an SSH server in the guest and connect from the host.

Can I run a VM without a GUI?

Yes, you can use virt-install and virsh from the command line. The VM will run headless, and you can connect to it via VNC or SPICE.

Is it safe to delete the VM when I’m done?

Yes, but make sure you don’t need any data inside it. Deleting the VM in Virtual Machine Manager removes the disk image, which permanently erases the guest OS and its files.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →