π§ͺ Setting up a test environment for Linux Kernel Development
tl;dr
- Create a virtual machine (VM) with extracted kernel and initrd
QEMUto run VMslibvirtto manage VMs and to automate- Configure SSH access from the host to the VM
- Fetch the list of modules loaded in the guest kernel
Commands
launch_vm_qemu # launch a VM with qemu with the extracted kernel and initrd
create_vm_virsh # create a virsh VM with the extracted kernel and initrd
sudo systemctl start libvirtd && systemctl status libvirtd # start libvirtd and check its status
sudo virsh net-start default && sudo virsh net-list # start default network and list networks
sudo virsh console arm64 # re-attach to the console of the running vm
sudo virsh list --all # list all created VMs
sudo virsh dominfo arm64 # Show detailed information about a vm
sudo virsh start --console arm64 # start a previously created vm
sudo virsh shutdown arm64 # shutdown a vm gracefully
sudo virsh destroy arm64 # force shutdown a vm
sudo virsh undefine arm64 # remove stopped vm
Notes
To keep my activate.sh script versioned, I structured my setup as follows:
/home
βββ lk_dev
β βββ shared_arm64
β βββ vm
β βββ arm64_boot
β β βββ initrd.img-6.1.0-43-arm64
β β βββ vmlinuz-6.1.0-43-arm64
β βββ arm64_img.qcow2
β βββ base_arm64_img.qcow2
βββ pietro
βββ github
βββ open-source-development
βββ lk_dev
βββ activate.sh
The VMs had to be stored under the home directory for virsh access. Note that when creating the /home/lk_dev
directory and itβs groups, I had to restart the computer, logging out and back in wasnβt enough.
The Debian image from the guide wasnβt available anymore, so the version used was the daily version 20260225-2399.
β οΈ Remember to start
libvirtdafter restarting the computer.sudo systemctl start libvirtd systemctl status libvirtd
The Debian image used doesnβt come with SSH installed, so I had to install it manually by running the VM with virsh and then executing:
sudo apt install update
sudo apt install openssh-server
After the setup was completed, I could access the VM successfully with SSH:
ssh root@192.168.122.135
Reference
Setting up a test environment for Linux Kernel Dev using QEMU and libvirt