KVM or Kernel Virtual Machine is the virtualization solution for Linux. It is a Linux kernel module that allows the Linux kernel to act as a hypervisor program like VMware ESXi or VSphere.
Until now, it has been impossible to run KVM on the Raspberry Pi using the Raspberry Pi (aka Raspbian) operating system. This is because KVM only works on a 64-bit operating system. Raspberry Pi OS was a 32-bit operating system. Another reason was that the Raspberry Pi 3 and earlier models only had 1GB of memory, which is not enough to run KVM. Docker was a better solution for devices with 1GB of memory.
As of this writing, it is possible to run KVM on the Raspberry Pi using the Raspberry Pi operating system. Because the Raspberry Pi operating system officially comes with a 64-bit kernel and the Raspberry Pi 4 has an 8GB model (it has 8GB of memory). Unfortunately, the 64-bit kernel of the Raspberry Pi operating system is not enabled by default. You have to activate it manually.
In this article, I will show you how to enable 64-bit kernel of Raspberry Pi OS and install KVM on Raspberry Pi OS.
So let's get started!
Things you need:
To follow this article you will need the following items to set up your Raspberry Pi 4 in headless mode:
- Raspberry Pi 4 (8GB version recommended, 4GB version also works) Single board computer
- USB Type-C power adapter
- MicroSD card of 32GB or more capacity flashed with Raspberry Pi OS (with desktop environment).
- Network connection on Raspberry Pi 4
- Laptop or desktop computer for VNC remote desktop access to the Raspberry Pi 4
If you don't want to put your Raspberry Pi 4 in headless mode, you'll also need:
- Monitor
- HDMI cable or micro HDMI
- keyboard
- Maus
If you need help flashing the Raspberry Pi OS image to the MicroSD card, read my articleHow to install and use the Raspberry Pi Imager.
If you are a Raspberry Pi newbie and need help installing the Raspberry Pi OS on your Raspberry Pi 4, read my articleHow to install Raspberry Pi operating system on Raspberry Pi 4.
If you need help setting up your Raspberry Pi 4 Headless, also read my articleHow to install and configure Raspberry Pi OS on Raspberry Pi 4 without external monitor.
Raspberry Pi operating system upgrade
Before enabling the 64-bit kernel and installing KVM on the Raspberry Pi operating system, you should update all existing packages for your Raspberry Pi operating system. This updates the kernel when new kernel versions are available or fixes known bugs (if any).
Before updating any existing Raspberry Pi OS packages, let's check the kernel version.
p.soverwrite name -r
As you can see, I'm using version 5.4.51 of the kernel compiled for the ARMv7l architecture.
Now let's update all existing Raspberry Pi OS packages.
First, refresh the entire APT package repository cache with the following command:
p.ssudocorrect update
Run the following command to update all existing packages (including the kernel):
p.ssudoApt update complete
To confirm the installation, pressYand then press <Get into>.
The APT package manager will download all the required packages from the Internet, but this will take some time.
Once the download is complete, they will be installed automatically. It will take a while to finish.
At this point, all updates should be installed.
For the changes to take effect, reboot your Raspberry Pi 4 with the following command:
p.ssudostart anew
After the Raspberry Pi 4 boots up, you will see that the kernel version has been updated.
Enabling the 64-bit kernel on the Raspberry Pi operating system
In the latest version of the Raspberry Pi operating system, the 64-bit kernel ships with the 32-bit kernel by default. The 64-bit kernel is still in beta. Therefore, it is not defined as the standard kernel in the Raspberry Pi operating system.
To use the 64-bit kernel in the Raspberry Pi operating system, open theFile /boot/config.txthownanoText editor as follows:
p.snano /throw it away/config.txt
Add toarm_64bit=1not endFile /boot/config.txtas marked on the screenshot below.
When you're done, press<Strg> + Xfollowed byYmi <Get into> to save itFile /boot/config.txt.
For the changes to take effect, reboot your Raspberry Pi 4 with the following command:
p.ssudostart anew
After booting your Raspberry Pi 4, check the kernel version with the following command:
p.soverwrite name -r
You should see thatv8+at the end of the kernel release, as you can see in the highlighted section of the screenshot below. This means that we are using a 64-bit kernel.
The file/dev/kvmIt should also be available as you can see in the image below.
p.ssudo ls -lh /developer/kvm
Installing KVM/QEMU:
Once the 64-bit kernel is enabled, you can install KVM, QEMU, and Virtual Machine Manager with the following command:
p.ssudofitinstall on pcvirt-manager libvirt0 system qemu
To confirm the installation, pressYand then press <Get into>.
The APT package manager downloads all the necessary packages from the Internet. It may take a while for the process to complete.
Once the packages are downloaded, the APT package manager will install them. It may take a while for the process to complete.
At this point, all the required packages should be installed.
Now add thePiuser for thelibvirt-qemugroup with the following command:
p.ssudouser mode-aglibvirt-qemu $(Who am I)
For the changes to take effect, reboot your Raspberry Pi 4 with the following command:
p.ssudostart anew
After booting the Raspberry Pi 4, start the standard KVM network with the following command:
p.ssudonetwork boot standard virsh
Run the following command to ensure that the default KVM network starts automatically on boot:
p.ssudoVirsh Net Standard-Autostart
Download the ISO install image for Alpine Linux
In this article, I will install Alpine Linux on a KVM virtual machine to test KVM on the Raspberry Pi OS.
TO USE: At the time of writing, KVM acceleration or hardware acceleration is not available on the Raspberry Pi OS. The operating systems run in emulation mode in a KVM virtual machine. So we're not going to get much performance out of it. That's why I chose Alpine Linux for the demo. It is also a very lightweight operating system. Even if the virtual machine is running in emulation mode, we can still test it. Hopefully, KVM acceleration or hardware acceleration will be available in a future Raspberry Pi OS update. But for now, that's as far as we can go.
To download the Alpine Linux ISO install image, visit theAlpine Linux official website.
Once the page loads, clicktransfers.
After the page loads, scroll down a bit and click the buttonVIRTUAL ARCHIVE 64Download link as marked in the screenshot below.
Your browser should start downloading the Alpine AARCH ISO install image. It may take a few seconds for the process to complete.
Move the Alpine Linux ISO image to the KVM image directory:
After downloading the Alpine ISO image, you can find it in the~/DownloadsDirectory.
p.sls -lh~/transfers
Move the Alpine ISO image to the/var/lib/libvirt/imagesdirectory as follows:
p.ssudo mv -v~/transfers/alpine-virt-3.12.1-aarch64.iso/he was/publication/library/Pictures/
Creating an Alpine Linux KVM virtual machine
To create an Alpine Linux KVM virtual machine, bootVirtual machine managersinceRaspberry Pi Menü > System Tools > Virtual Machine Manager, as marked in the screenshot below.
Enter your login password and press <Get into>.
Now click on the highlighted icon (), as shown in the screenshot below.
chooseLocal installation medium (ISO image or CD-ROM)in the list and clickAdvance payment.
click onNavigate…
Select the Alpine ISO image from the list and click on itBand Elia.
Disable thoseAutomatic installation media/source detectionBox.
To searchalpineand selectLinux-Alpino 3.8(or higher if available by the time you read this article) from the list.
click onAdvance payment.
Set the desired amount of memory and number of CPU cores for this virtual machine.
When you're done, clickAdvance payment.
Set the disk size of this virtual machine and clickAdvance payment.
Enter a name for the virtual machine and clickThe end.
The virtual machine is created. It may take a few seconds for the process to complete.
Once the virtual machine is created, you need to boot from the Alpine ISO install image as you can see in the screenshot below.
After a few seconds you should see the Alpine Linux login window.
The default username isfuente🇧🇷 By default, no password is set for thefuenteSo just type root and press <Get into>.
You must be connected. You can try Alpine Linux here.
If you like Alpine Linux and want to permanently install it on the virtual machine's hard drive, run the following command:
p.sconfiguration-alpine
The Alpine Linux setup is initializing. It may take a few seconds.
You should soon see the following window.
To define a keyboard layout, enter the 2-letter keyboard layout code from the list and press <Get into>.
To define a keyboard layout variant, enter the keyboard layout variant code in the list and press <Get into>.
Enter the hostname and press <Get into>.
pressure <Get into>.
pressure <Get into>.
pressure <Get into>.
Enter the desired root login password and press <Get into>.
rewritefuenteLogin password and press <Get into>.
The setup wizard will start. It may take a few seconds.
After the following window appears, press <Get into>.
pressure <Get into>.
pressure <Get into>.
The following error may appear when installing Alpine Linux on the hard drive.
Alpine Linux sometimes fails to connect to the internet and the Alpine package repository database is not mirrored. Then you see this error. Luckily, it's easy to fix.
PressFand then press <Get into> How often do you see this error.
After viewing the mirror list, select one of the mirrors (by entering the mirror number) and press <Get into>.
You can also pressFand then press <Get into> to allow Alpine to automatically select the fastest mirror.
After selecting a mirror, you should see the following window.
pressure <Get into>.
The OpenSSH server must be installed.
Alpine should now prompt you to select a hard drive on which to install Alpine Linux.
We want to install it on the virtual disksda🇧🇷 So writesdaand pressure <Get into>.
Get intoSystemand pressure <Get into>.
Pressjand then press <Get into> to confirm the installation.
Alpine installed on the virtual disk. It may take a few minutes for the process to complete.
At this point Alpine should be installed.
Restart the virtual machine with the following command:
p.ssudostart anew
The next time you start the virtual machine, Alpine Linux will start from the virtual hard disk.
Alpine Linux boots from the virtual hard disk.
Once Alpine Linux boots up, you should see the login window.
Enter root as the login username and password you set earlier to log into Alpine Linux.
You must be logged into Alpine Linux.
After logging in, you can run any command you want.
ÖVirtual machine managerThe app should show all the KVM virtual machines you have created on the dashboard. From here you can control your virtual machines.
Conclusion
In this article, I showed you how to enable 64-bit kernel of Raspberry Pi OS and install KVM on Raspberry Pi OS. I also showed you how to install Alpine Linux as a KVM virtual machine on the Raspberry Pi operating system. Hardware acceleration for KVM virtual machines is not yet available on Raspberry Pi OS. It may be available in a future update of the Raspberry Pi operating system. However, currently you can only run light operating systems on KVM virtual machines. If you want to run hardware-accelerated KVM virtual machines on your Raspberry Pi 4 right away, use Fedora 33 as the KVM host on your Raspberry Pi 4.
FAQs
How do I enable KVM modules? ›
- To determine whether the svm or vmx CPU extensions are present, run this command: # grep -E 'svm|vmx' /proc/cpuinfo. This command generates output if the CPU is capable of hardware-virtualization. ...
- To list the loaded kernel modules and verify that the kvm modules are loaded, run this command: # lsmod | grep kvm.
...
- Step 1: Install KVM Packages. First, update the repositories: sudo apt update. ...
- Step 2: Authorize Users. ...
- Step 3: Verify the Installation.
- Shut down all running VMs and unload the kvm_probe module: sudo modprobe -r kvm_intel.
- Activate the nesting feature: sudo modprobe kvm_intel nested=1.
- Nested virtualization is enabled until the host is rebooted.
Checking Whether KVM Support is Available: You can check whether KVM support is enabled in the Linux kernel from Ubuntu using kvm-ok command which is a part of the cpu-checker package. It is not installed by default. But it is available in the official package repository of Ubuntu.
How to enable KVM in BIOS? ›Turn on the computer, and then immediately press f10 to open BIOS Setup. Use the arrow keys to select the Configuration tab, and then select Virtualization Technology. Select Enable. Press f10 to save the settings and exit BIOS Setup.
Why is KVM disabled in BIOS? ›"KVM: disabled by BIOS" error
On some hardware (e-g HP nx6320), you need to power-off/power-on the machine after enabling virtualization in the BIOS. Enabling some BIOS features may break VT support on some hardware (e-g Enabling Intel AMT on a Thinkpad T500 will prevent kvm-intel from loading with "disabled by bios")
Originally Answered: How do I clear the issue of 'Warning KVM is not available'? This may mean the KVM package is not installed, or the KVM kernel modules are not loaded. If you have an Intel processor, reboot your computer, enter the BIOS setup and make sure virtualization is enabled.
Is KVM a module in kernel? ›Kernel-based Virtual Machine (KVM) is a virtualization module in the Linux kernel that allows the kernel to function as a hypervisor. It was merged into the mainline Linux kernel in version 2.6. 20, which was released on February 5, 2007.
How do I enable KVM secure boot? ›- Install KVM, QEMU.
- Prepare the environment. Create a OVMFKeys working directory: ...
- Use QEMU to inject secure boot keys. Run qemu-system-x86_64 to launch virtual machine: ...
- Generate OVMF.fd for ACRN with the updated keys manually: cat /path/to/OVMF_VARS. ...
- Update OVMF.
- Turn off all of the computers and monitors that will be connected to the KVM switch.
- Connect the power adapter to the KVM switch.
- Connect the video cables from your monitors to the console video port on the KVM switch.
- Turn on the monitors.
How do I know if my CPU supports KVM? ›
To run KVM you need a processor that supports virtualization. For Intel processors this extension is called INTEL-VT. For AMD processors it is called AMD-V. If nothing is printed, it means that your CPU does not support hardware virtualization.
How to enable virtualization in Linux? ›- Reboot your Computer and Press the BIOS Key. ...
- Locate the section for CPU configuration. ...
- Find the Settings for Virtualization. ...
- Select the Option for Enabling Virtualization. ...
- Save the Changes You Have Made. ...
- Exit Your BIOS and Reboot Your Computer.
Now, consider some of the upside to KVM switches: No software agents are required on the client so there's no loss of productivity due to competition between applications.
What requirements KVM? ›Compute and Memory
Compute hosts should meet at least the following requirements to operate Platform9. CPU: AMD / Intel Server Class Processors. Memory: 16 GB RAM. Network: (2) 1Gbps bonded NICs (LACP) Boot disk: 20 GB.
- From the Remote Access Summary page, click Remote Control. ...
- Select the target for VNC access, using Add and Remove to move a system from the left (Available) column to the right (Selected) column.
- Click OK.
- Reboot the computer.
- While the system is restarting from a black screen, enter BIOS by pressing the hotkey. ...
- Navigate to Advanced Tab and press Enter to continue.
- Select Virtualization and Enable.
- Save changes and reboot the computer.
This allows an operating system to more effectively & efficiently utilize the CPU power in the computer so that it runs faster. This feature is also a requirement for many virtual machine software and is required to be enabled in order for them to run properly or even at all.
How do I enable CPU virtualization? ›- Reboot your computer.
- Right when the computer is coming up from the black screen, press Delete, Esc, F1, F2, or F4. ...
- In the BIOS settings, find the configuration items related to the CPU. ...
- Enable virtualization; the setting may be called VT-x, AMD-V, SVM, or Vanderpool.
KVM, Kernel-based Virtual Machine, is a hypervisor built into the Linux kernel. It is similar to Xen in purpose but much simpler to get running. Unlike native QEMU, which uses emulation, KVM is a special operating mode of QEMU that uses CPU extensions (HVM) for virtualization via a kernel module.
Is KVM enabled Linux? ›The main benefit of the KVM hypervisor is its native availability on Linux. Since KVM is part of Linux, it installs natively, enabling straightforward user experience and smooth integration.
How to enable KVM on QEMU? ›
To start QEMU in KVM mode, append -accel kvm to the additional start options. To check if KVM is enabled for a running VM, enter the #QEMU monitor and type info kvm . Note: The argument accel=kvm of the -machine option is equivalent to the -enable-kvm or the -accel kvm option.
How do I download and install KVM? ›- Step 1: Update and Upgrade Your Ubuntu 22.04 System. ...
- Step 2: Check KVM Compatibility With Your System. ...
- Step 3: Install Necessary Packages for KVM. ...
- Step 4: Enable Essential Services to Virtualize and Check Their Status. ...
- Step 5: Add Your User to the KVM and Libvirt Group.
Is QEMU required for KVM? KVM is a Linux-based full virtualization solution, so you can definitely use it without QEMU. However, if you are looking for a powerful type-1 hypervisor that provides better performance and stability, using KVM and QEMU together is your best bet.
How to add kernel modules? ›- To load a kernel module, run modprobe module_name as root . ...
- By default, modprobe attempts to load the module from /lib/modules/kernel_version/kernel/drivers/ . ...
- Some modules have dependencies, which are other kernel modules that must be loaded before the module in question can be loaded.
Kernel modules are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without the need to reboot the system. To create a kernel module, you can read The Linux Kernel Module Programming Guide. A module can be configured as built-in or loadable.
Is Virsh command set a KVM? ›Virsh command allows you to create a new KVM VM from its configuration file, which is the xml file in datastore. You can get the xml file by exporting it from KVM VM. You can also create a new VM from virtual disk image.
How do I enable Secure Boot or disable? ›- From the System Utilities screen, select System Configuration > BIOS/Platform Configuration (RBSU) > Server Security > Secure Boot Settings > Secure Boot Enforcement and press Enter.
- Select a setting and press Enter: Enabled — Enables Secure Boot. Disabled — Disables Secure Boot.
To check if Virtualization is enabled/disabled on your desktop/laptop, simply press Ctrl + Shift + Esc keys to open the Task Manager. Click on the Performance tab and under CPU, you will find information about Virtualization on your desktop/laptop. If it says Enabled, then Virtualization is turned on.
How is KVM implemented? ›In the KVM architecture, the virtual machine is implemented as regular Linux process, scheduled by the standard Linux scheduler. In fact, each virtual CPU appears as a regular Linux process. This allows KVM to benefit from all the features of the Linux kernel.
How to set up KVM on Linux? ›- Step 1: Update and Upgrade Linux Mint. Before installing KVM, it is recommended to update your system and upgrade it. ...
- Step 2: Check System Compatibility With KVM. ...
- Step 3: Install KVM. ...
- Step 4: Add Your User to the KVM and Libvirt Group.
Why is virtualization not showing in BIOS? ›
If you still can't enable virtualization in your BIOS, chances are that your PC doesn't support the feature. You'll need a new computer to try virtualization.
How do I know if my CPU supports virtualization? ›You can use the Intel® Processor Identification Utility to verify if your system is capable of Intel® Virtualization Technology. Using the tool, Select the CPU Technologies tab. See if the Intel® Virtualization Technology options are checked or not.
Does KVM allow CPU emulation? ›KVM is a kernel module which allows passing through CPU cores via host-passthrough without virtualizing them.
How do I know if virtualization is enabled in Linux? ›Method 1: Through the lscpu command
This information includes the number of processors, CPU operation mode, sockets, cores, threads, model name, and virtualization information, among much more. Navigate to the Virtualization output; the result VT-x here ensures that virtualization is indeed enabled on your system.
From the System Utilities screen, select System Configuration > BIOS/Platform Configuration (RBSU) > System Options > Virtualization Options > Virtualization Technology and press Enter. Select a setting and press Enter.
How to enable KVM in VirtualBox? ›- Step 1: List Existing VirtualBox Images. First and foremost, ensure that all the virtual machines are powered off. ...
- Step 2: Convert VDI Image to RAW Disk Format. The next step is to convert the VDI images into a RAW disk format. ...
- Step 3: Convert RAW Image Disk Format to KVM Format.
Enabling KVM
To start QEMU in KVM mode, append -accel kvm to the additional start options. To check if KVM is enabled for a running VM, enter the #QEMU monitor and type info kvm .
- Step 1: Install required packages. On your Ubuntu 20.04 execute the following command to install the required packages: $ sudo apt -y install bridge-utils cpu-checker libvirt-clients libvirt-daemon qemu qemu-kvm.
- Step 2: Check virtualisation capabilities. ...
- Step 3: Launch a VM.