Because testing kernel modules on your host machine is extremely dangerous (a single mistake causes a system-wide kernel panic), we use a QEMU Virtual Machine as a sandbox.
This guide walks you through:
- Setting up an Arch Linux VM using
virt-manager(GUI). - Transferring the
kphd.komodule to the VM. - Safely testing the module.
Since you've already installed the qemu / libvirt packages on your Arch host, the easiest way to provision the VM is via the graphical interface.
- Launch Virtual Machine Manager:
- Open your desktop application menu and search for Virtual Machine Manager, OR run
virt-managerin your terminal.
- Open your desktop application menu and search for Virtual Machine Manager, OR run
- Download an Arch Linux ISO:
- Go to archlinux.org/download and download the latest
.isofile.
- Go to archlinux.org/download and download the latest
- Create the VM in virt-manager:
- Click the "Create a new virtual machine" icon (monitor with a shining star).
- Choose "Local install media" and select the Arch Linux
.isoyou downloaded. - Assign RAM and CPU (e.g., 2048 MB RAM, 2 CPUs is plenty).
- Create a disk image (e.g., 10 GB to 20 GB).
- Name it
K-PHD-Test-Box(or similar) and click Finish.
- Install Arch Linux inside the VM:
- The VM console will boot to the Arch installer.
- Run the arch installation script:
archinstall. - Follow the prompts to set up a basic system (make sure to set a password for
rootor a regular user, and install a network profile so the VM has internet/SSH access).
- Install SSH inside the VM:
- Once installed and rebooted, log into the VM console.
- Install SSH:
pacman -S openssh - Enable and start SSH:
systemctl enable --now sshd
- Find the VM's IP address:
- Inside the VM, run
ip aand look for theeth0orenp1s0interface IP (usually looks like192.168.122.x).
- Inside the VM, run
Now that the VM is running and accessible via SSH, you must send the compiled kernel module from your Host to the VM.
-
On your HOST machine (your Arch Linux PC): Ensure you are in the directory where
kphd.kowas compiled:cd ~/Desktop/K-PHD/kernel
-
Secure Copy (SCP) the file to the VM: (Replace
<user>and<vm_ip>with the username and IP address from Part 1)scp kphd.ko <user>@<vm_ip>:~/
We will now insert the kernel module into the VM's kernel safely.
-
SSH into the VM:
ssh <user>@<vm_ip>
-
Clear the kernel message log (optional, makes it easier to read):
sudo dmesg -c
-
Insert the K-PHD module (
insmod):sudo insmod kphd.ko
-
Verify it loaded correctly:
sudo dmesg | tail -n 5✅ You should see:
K-PHD: Module loaded successfully. -
List running modules to prove it's loaded:
lsmod | grep kphd -
Remove the K-PHD module (
rmmod):sudo rmmod kphd
-
Verify it unloaded correctly:
sudo dmesg | tail -n 5✅ You should see:
K-PHD: Module unloaded successfully.
Congratulations! Phase 1 is officially complete once you verify the
dmesglogs. We have successfully proven that our build system works and the basic C scaffolding does not crash the kernel.