From d00996062e973d60accf35604317501fe91c8569 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Fri, 14 Jan 2022 01:54:13 -0500 Subject: [PATCH] Build and install module with DKMS --- build.sh | 23 +++++++++++++++++++---- dkms.conf | 5 +++++ helloworld.conf | 3 +++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 dkms.conf create mode 100644 helloworld.conf diff --git a/build.sh b/build.sh index 594558d..c2ebe8e 100644 --- a/build.sh +++ b/build.sh @@ -1,13 +1,28 @@ #!/bin/bash +VERSION="0.1" + +# Install build prerequisites export DEBIAN_FRONTEND=noninteractive apt-get update -apt-get install build-essential linux-headers-$(uname -r) -y +apt-get install -y dkms build-essential linux-headers-$(uname -r) +# Place source and configuration files on the system cd /vagrant -make -modinfo helloworld.ko -insmod helloworld.ko +mkdir /usr/src/helloworld-$VERSION +cp Makefile /usr/src/helloworld-$VERSION/Makefile +cp helloworld.c /usr/src/helloworld-$VERSION/helloworld.c +cp dkms.conf /usr/src/helloworld-$VERSION/dkms.conf +cp helloworld.conf /etc/modules-load.d/helloworld.conf + +# Build and install kernel module with DKMS +dkms add -m helloworld -v $VERSION +dkms build -m helloworld -v $VERSION +dkms install -m helloworld -v $VERSION + +# Load module and show details about it +modprobe helloworld +modinfo helloworld cat /proc/modules | grep helloworld rmmod helloworld cat /var/log/messages | grep helloworld diff --git a/dkms.conf b/dkms.conf new file mode 100644 index 0000000..6fa67ad --- /dev/null +++ b/dkms.conf @@ -0,0 +1,5 @@ +PACKAGE_NAME="helloworld" +PACKAGE_VERSION="0.1" +BUILT_MODULE_NAME[0]="helloworld" +DEST_MODULE_LOCATION[0]="/kernel/drivers/helloworld/" +AUTOINSTALL="yes" diff --git a/helloworld.conf b/helloworld.conf new file mode 100644 index 0000000..1946156 --- /dev/null +++ b/helloworld.conf @@ -0,0 +1,3 @@ +# A kernel module that should be loaded at boot time +# /etc/modules-load.d/helloworld.conf +helloworld