The demo kernel module

This guide has the target to show the proper requirements and steps to build third party kernel modules for UEK; in this guide I will use a dummy kernel module to just show the requirements and build steps.

  • Here the code of the dummy kernel module (saved into /root/uekdemo.c):
#include <linux/module.h>    // included for all kernel modules
#include <linux/kernel.h>    // included for KERN_INFO
#include <linux/init.h>      // included for __init and __exit macros

MODULE_LICENSE("UPL");
MODULE_DESCRIPTION("UEK demo");

static int __init hello_init(void)
{
    printk(KERN_INFO "UEK demo module is here\n");
    return 0;    // Non-zero return means that the module couldn't be loaded.
}

static void __exit hello_cleanup(void)
{
    printk(KERN_INFO "Cleaning up module.\n");
}

module_init(hello_init);
module_exit(hello_cleanup);
  • Here the Makefile for uekdemo.c (save into /root/Makefile):
obj-m += uekdemo.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
  • Loading this demo kernel module (by insmod) will show (by dmesg):

UEK demo module is here

  • Unloading this demo kernel module (by rmmod) will show (by dmesg):

Cleaning up UEK demo module

Oracle Linux 8

Build kernel module for UEK Release 6

Requirements

  • Get the Oracle Linux system up-to-date, with latest UEK6 kernel installed.

# dnf update -y

# reboot

  • Install pre-requisities to build a kernel module for UEK6

# dnf install kernel-uek-devel make -y

Build the Kernel module

  • The example below shows how to build the demo kernel module; for other kernel modules you should refer to their build instructions.

# make -C /lib/modules/`uname -r`/build M=/root modules

nb: “/root” is the path where my uekdemo.c and Makefile files are present.

Build kernel modules for UEK Release 7

Requirements

  • Get the Oracle Linux system up-to-date, with latest UEK7 kernel installed.

# dnf update -y

# reboot

  • Install pre-requisities to build a kernel module for UEK7

# dnf install kernel-uek-devel make gcc-toolset-11 -y

  • Enable gcc-11 release to work with UEK7 (UEK7 is built with gcc-toolset-11)

# scl enable gcc-toolset-11 /bin/bash

  • Verify proper “gcc” compiler release is leveraged

# which gcc

The output has to be “/opt/rh/gcc-toolset-11/root/usr/bin/gcc“.

Build the Kernel module

  • The example below shows how to build the demo kernel module; for other kernel modules you should refer to their build instructions.

# make -C /lib/modules/`uname -r`/build M=/root modules

nb: “/root” is the path where my uekdemo.c and Makefile files are present.

Oracle Linux 9

Build kernel modules for UEK Release 7

Requirements

  • Get the Oracle Linux system up-to-date, with latest UEK7 kernel installed.

# dnf update -y

# reboot

  • Install pre-requisities to build a kernel module for UEK7

# dnf install kernel-uek-devel make -y

Build the Kernel module

  • The example below shows how to build the demo kernel module; for other kernel modules you should refer to their build instructions.

# make -C /lib/modules/`uname -r`/build M=/root modules

nb: “/root” is the path where my uekdemo.c and Makefile files are present.

 

For any feedback feel free to get in-touch on twitter or linkedin.