Setting up the kernel development environment - VM
This article describes how to setup a virtual machine for your kernel development environment.
Overview
For testing and debugging new kernel features a virtual machine is a very quick way to evaluate and debug new kernel functionality. Compared to installing a new Linux kernel on a test machine, booting the new kernel in the test machine, a virtual machine is a lot quicker. Once the new kernel has been compiled, the kernel can be started in a matter of seconds.
BIOS Settings
The development machine needs to be setup to be able to run the virtualiztion software. This setting is generally made in the BIOS of the computer. When the computer gets started, the BIOS settings can be invoked by pressing the hotkey. The hotkey depends on the manufacturer of the machine / BIOS. Generally its a key like F7 or F10. Its best to consult your computer manual.
You can check on the machine if virtualization has been enabled with the following command:
|
|
If virtualization is enabled for the CPU, it should contain the value vmx or svm in the flags display.
Installation
This guide uses QEMU to start a kernel. The software can virtualize different architectures. In this guide we assume we want to execute on a virtualize x86_64 architecture. The software can be installed with the following command:
|
|
This will install the exeutable qemu-system-x86_64 and some additional python libraries which are required in the next step. qemu can be used directly, but this requires to setup a complete system. An easier way is to use the development system, but start it virtualized with a new kernel. To do this we need to install the virtme software.
|
|
The software was originally developed by https://github.com/amluto/virtme.git. However the software doesn’t seem to get updated anymore. This causes problems with newer versions of the qemu software as some flags / options have been renamed. A fork that gets updated is maintained here https://github.com/arighi/virtme.git. This fork also works with newer versions. This is especially important if qemu is newer than 7.2
Preparing the kernel
To be able to start the kernel in a virtualized environment, it needs to be configured for it. This is described in the above github repository. The easiest way is to execute the following command in the kernel repository:
|
|
Afterwards recompile the kernel with the new configuration.
Start the kernel in the virtualized environment
From the kernel repository can now be started with a command like the following:
|
|
After a couple of seconds this greets you with root prompt in the virtualized kernel. The virtualized kernel environment can be stopped by pressing Ctrl-A X.