Virtualization is becoming more common nowadays. The ability to take your existing machine and provision multiple virtual machines helps tremendously with things like education, testing and experimentation, and productivity. Linux being as popular and powerful as it is, is a great place to start building a virtualization server or workstation for your own personal use. Covered here is how to create a Linux virtualization workstation from scratch.
Virtualization Hardware Compatibility
Before you start installing any packages, you’ll want to make sure your CPU supports hardware virtualization. Many modern laptop and desktop CPUs do, but it’s good to check. The commands below will check your “/proc/cpuinfo” file for the necessary technology. If you’re not sure what you have in your system, try both – it won’t hurt anything.
grep vmx /proc/cpuinfo # for Intel CPUs grep svm /proc/cpuinfo # for AMD CPUs
My system has an Intel CPU, so my output looks like the following image.
If you don’t get any output on either of those commands, you can also just look at the output of lscpu
and find the “Virtualization” section. Mine looks like the next image.
We know that my system is set up to handle virtualization. I’d also recommend at least 8 GB of RAM in your system. For the best experience, I’d recommend 16, 32 or even 64 GB RAM. That will give you plenty of room to set up and run multiple VMs without worrying about running out of RAM, and you could create full client/server networks or workstation fleets all on one system.
Installing KVM
KVM stands for Kernel-based Virtual Machine, and it’s the best Linux-native hypervisor out there. Performance is excellent, and there are multiple ways for you to manage your KVM virtual machines. QEMU often goes along with KVM as a way to emulate hardware.
To install everything you’ll need for your server, run the following commands:
For Fedora:
sudo dnf -y groupinstall "Virtualization Host"; sudo dnf -y install virt-install
For Ubuntu/Ubuntu-based distro:
sudo apt -y install qemu-kvm libvirt-daemon-system libvirt-daemon virtinst bridge-utils libosinfo-bin libguestfs-tools virt-top
Once you have KVM installed, make sure you check that the kernel module is loaded with this command:
lsmod | grep kvm
And that you start and enable the daemon for KVM with the command below:
sudo systemctl start libvirtd sudo systemctl enable libvirtd sudo systemctl status libvirtd
Your output should look like the following image.
Many other guides will now have you set up a bridge for all your VMs to access the outside network. I won’t cover that here, but here’s a link out to the Arch Wiki that teaches you a bunch of different ways to do it. This will be helpful if you want your VMs to provide services to your broader network, but if you’re just using it for testing and sandboxing, the default network options are just fine.
Installing and Managing KVM VMs with a GUI
There are several ways you can manage your KVM virtual machines. If you’re using a graphical desktop for your Linux workstation or server, you can use Virtual Machine Manager or GNOME Boxes*, or if you’re running a CLI-only server and are looking for a GUI interface for it, you can use Cockpit and manage your VMS by installing the “Machines” application in the “Applications” menu in the interface. All of these GUI tools will also allow you to install KVM VMs.
*GNOME Boxes is easily the simplest way to deal with KVM virtual machines, but you don’t get anywhere near the same control that you get with the other offerings in terms of networking, storage, and hardware configuration.
Installing KVM VMs from the Terminal
You can also use CLI tools that come with the packages installed by the commands above. virt-install
is a great tool to install KVM virtual machines without having to mess around with XML definitions. There are many different options available to use with virt-install
. However, I’ve had the most success with the following template:
sudo virt-install \ --connect qemu:///system \ --name <NAME> \ --memory <MEMORY_IN_MB> \ --vcpus <CPUs> \ --disk size=<SIZE> \ --cdrom /PATH/TO/ISO/FILE
This should define all the aspects you’ll need for the system. You can also install over the network, import images, and specify the location of the disk by specifying “path=/PATH/TO/DIR/DISKNAME.qcow2” after the size
option separated by a comma. Here’s a link to Red Hat’s documentation on virt-install
.
This will open Remote Viewer (also called virt-viewer
) and allow you to go through the OS install process normally. You’ll need access to a GUI, so if your server is headless, I’d recommend using Cockpit as mentioned above. You can also use kickstart files to install RHEL-based distros with virt-install
.
Managing KVM VMs from the Terminal
The primary command you’ll be using to manage KVM VMs is virsh
. It’s available as either a command or as an interactive shell, so entering it is as simple as typing sudo virsh
and pressing Enter.
For a couple examples, you can now list all your domains with list --all
, start domains with start
, and shut down domains with shutdown
.
There are a huge number of virsh
options, so I encourage you to check out the man
pages and dig into all the great things you can manage from the terminal about your machines.
You can also SSH into your VMs using their IP Address. They get IPs from the virbr0
interface, and the VMs’ interfaces are open to SSH access by default.
Now that you have a virtualization workstation on your Linux system, make sure you learn how to easily speed up your virtual machines and access your Linux VMs using VNC.
Our latest tutorials delivered straight to your inbox