Setting up the environment for kernel module development

Manikishan Ghantasala
2 min readNov 28, 2020

In this post, I am going to document my config and steps to setup an environment for developing kernel modules. My current system is MBP 2018 with macOS Mojave, the environment I am going to setup is for Linux kernel dev so this works for most of the OSes. Before going into the details I want to mention that the IDE, toolkit, etc., I mention are my preferences if you have any better setup please let me know in the comments. With that said, let’s dive in and get the work done.

Virtual Machine

When coming to developing kernel-related software it's always suggested to use virtual environments. Well I don’t want QEMU for this setup as I am not going to compile the kernel so I am going with my favorite and easy to use virtualization software vagrant. If you have VirtualBox you can skip the next step.

Installing vagrant and running a Linux VM. (Run the commands from vagrant up in the desired directory)

Once the VM is initialized and running you can log in to shell via vagrant ssh.

$ brew cask install vagrant 
$ vagrant init ubuntu/bionic64
$ vagrant up

Once the VM is initialized and running you can login to shell via vagrant ssh.

Linux distros provide the commands modprobe, insmod and depmod within a package.

Headers Before you can build anything you’ll need to install the header files for your kernel. On GNU/Linux:

$ sudo apt-get install build-essential kmod

On Ubuntu:

$ sudo apt-get update 
$ apt-cache search linux-headers-$(uname -r)

Once we find the required header we should install the required version.

$ sudo apt-get install kmod linux-headers-5.0.0-050000-generic

These steps are enough to get started with, If I make any more additions as I progress I will update the blog. If you want to set up the kernel dev setup with vscode check this repo. I am going to use VS CODE remote ssh for now.

Originally published at https://sh4nnu.codes.

--

--

Manikishan Ghantasala

Hello. I’m Manikishan, a CS undergrad from Amrita Vishwa Vidyapeetham , Kollam, Kerala. I am a passionate developer and an artist. I love anime and music.