Unix & Linux: Unable to load module: Disagrees about version of symbol module_layout
Channel: Roel Van de Paar
Date: 2020-08-16

Unix & Linux: Unable to load module: Disagrees about version of symbol module_layout


The Question: Following http://www.opensourceforu.com/2010/12/writing-your-first-linux-
driver/ to write my first driver.
The Makefile is:
# Makefile - makefile of our first driver

# if KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq (${KERNELRELEASE},)
 obj-m := ofd.o
# Otherwise we were called directly from the command line.
# Invoke the kernel build system.
else
 KERNEL_SOURCE := /usr/src/linux 3.8
 PWD := $(shell pwd)
default:
 ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules

clean:
 ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
endif
And the driver code is :
* ofd.c - Our First Driver code */
#include ＜linux/module.h＞
#include ＜linux/version.h＞
#include ＜linux/kernel.h＞

static int __init ofd_init(void) /* Constructor */
{
 printk(KERN_INFO "Namaskar: ofd registered");
 return 0;
}

static void __exit ofd_exit(void) /* Destructor */
{
 printk(KERN_INFO "Alvida: ofd unregistered");
}

module_init(ofd_init);
module_exit(ofd_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Anil Kumar Pugalia ＜email_at_sarika-pugs_dot_com＞");
MODULE_DESCRIPTION("Our First Driver");
There is no error during make. But when I use insmod ofd.ko I'm unable to load
it. In dmesg it says:
 disagrees about version of symbol module_layout
 * uname -r returns '3.8.0-38-generic' and the kernel source also 3.8.
 * modprobe -f ofd.ko also fails
Also:
#56~precise1-Ubuntu SMP Thu Mar 13 16:23:47 UTC 2014
... (Please watch the video for the full question)

Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful

With thanks & praise to God, and with thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user user2799508 (https://unix.stackexchange.com/users/55826), user Serjik (https://unix.stackexchange.com/users/79766), user Gilles 'SO- stop being evil' (https://unix.stackexchange.com/users/885), and the Stack Exchange Network (http://unix.stackexchange.com/questions/125624). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything is amiss at Roel D.OT VandePaar A.T gmail.com.