How to rename a built-in linux kernel module? - makefile

I am trying to extend the built-in xfs module of linux kernel. Following this SO post, I am now able to compile it locally. But to avoid conflict with the existing kernel xfs module, I would like to rename my extension to, say xxfs, without changing the name of the source files.
I've found a related post, following which I changed the relevant lines in Makefile to:
obj-$(CONFIG_XFS_FS) += xxfs.o
xxfs-objs := xfs.o
But I got an error saying
make[1]: *** No rule to make target '/home/dev/tmp/xxfs/xfs.o', needed by '/home/dev/tmp/xxfs/xxfs.o'. Stop.
Makefile:1403: recipe for target '_module_/home/dev/tmp/xxfs' failed
make: *** [_module_/home/dev/tmp/xxfs] Error 2
make: Leaving directory '/usr/src/linux-headers-4.4.0-28-generic'
Environment:
Ubuntu 16.04 with kernel 4.4.0-28-generic.
EDIT
I got the xfs kernel module source file by
installing the linux kernel source with apt-get source linux-source-4.4.0
copy the linux-4.4.0/fs/xfs to another directory (merely for easy maintenance), currently /home/dev/tmp/xxfs
To compile the module, I run the command make -C /lib/modules/$(uname -r)/build M=$(pwd) modules from the /home/dev/tmp/xxfs directory, after which a xfs.ko will be generated in the same directory.
However after I change the following line in Makefile
obj-$(CONFIG_XFS_FS) += xfs.o
to
obj-$(CONFIG_XFS_FS) += xxfs.o
xxfs-objs := xfs.o
Everything else is not touched, but I am no longer able to compile the module with the same command.

Related

Linux kernel out-of-tree module, installation of uapi headers issue

I have an external out-of-tree linux kernel module, say foo. Therein, I have a directory include/uapi/ that should, I assume, contain Kbuild file defining inclusion rules and/or headers to export. The directory include/uapi/ on its turn contains one more directory linux having the target user-API headers in, say three files foo.h bar.h baz.h
Ok, I have defined this Kbuild file inside include/uapi and it contains:
header-y += linux/
Then, inside include/uapi/linux directory I've defined one more KBuild and it has the content:
header-y += foo.h bar.h baz.h
Now I am expecting that upon running the command
make -C /lib/modules/5.4.48-dannftk/build M=/home/dannftk/foo INSTALL_HDR_PATH=/home/dannftk/my_exported_headers/ headers_install
I will get the headers installed in the /home/dannftk/my_exported_headers/ directory, instead, I am getting the error saying:
make: *** No rule to make target 'headers_install'. Stop.
/home/dannftk/foo - the path the out-of-tree module discussed is located by
/lib/modules/5.4.48-dannftk/build - the build directory of the kernel, it points to /usr/src/linux-5.4.48 containing the source code of the kernel, actually, I am on Gentoo Linux
May someone give me a hint what I am doing wrongly? Am I incorrectly setting rules for Kbuild? Or maybe I am locating them in unexpected for the kernel build system directories?
Thank you in advance
I personally consider this issue as a bad Kbuild error message. It's too confusing.
The answer is in linux documentation:
--- 2.3 Targets
When building an external module, only a subset of the "make"
targets are available.
make -C $KDIR M=$PWD [target]
The default will build the module(s) located in the current
directory, so a target does not need to be specified. All
output files will also be generated in this directory. No
attempts are made to update the kernel source, and it is a
precondition that a successful "make" has been executed for the
kernel.
modules
The default target for external modules. It has the
same functionality as if no target was specified. See
description above.
modules_install
Install the external module(s). The default location is
/lib/modules/<kernel_release>/extra/, but a prefix may
be added with INSTALL_MOD_PATH (discussed in section 5).
clean
Remove all generated files in the module directory only.
help
List the available targets for external modules.
There were some hacks available in older kernel versions, as adding header-y += ... into Kbuild file, but, as you see, it's not the official approach.
Looks like developers of out-of-tree modules should take care of headers installation manually, without reusing of linux kernel make rules.

kernel compile and menuconfig

I am a newer in linux and using ubuntu(4.4.0-64-generic) in vmware fusion. I am learning how to compile kernel. So, I downloaded the kernel(linux-4.4.52.tar.xz) from the kernel.org. But when I input make menuconfig, there are some errors.
root#ubuntu:/usr/src/linux-4.4.52# make menuconfig
HOSTCC scripts/basic/fixdep
In file included from /usr/include/x86_64-linux-gnu/bits/posix1_lim.h:160:0,
from /usr/include/limits.h:143,
from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h:168,
from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h:7,
from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h:34,
from scripts/basic/fixdep.c:114:
/usr/include/x86_64-linux-gnu/bits/local_lim.h:38:26: fatal error: linux/limits.h: No such file or directory
compilation terminated.
scripts/Makefile.host:91: recipe for target 'scripts/basic/fixdep' failed
make[1]: * [scripts/basic/fixdep] Error 1
Makefile:444: recipe for target 'scripts_basic' failed
make: * [scripts_basic] Error 2
I have installed headers files and done everything I can do. Someone can help me solve this problem?
You symbolic link is wrong; /usr/src/linux-4.4.0-64-generic/include/linux is the wrong directory and must not be linked to /usr/include/linux.
The kernel has two sets of headers: kernel-internal headers, and user API headers. The latter are inside the uapi directory, and they are what user-space program should see.
When you are compiling your own kernel, you can install the user-space headers of that kernel with make headers_install.
When you are using your distribution's kernel, you can just (re-)install the appropriate package (in your case, linux-headers-generic), and that will do the right thing as long as you do not muck around with those files afterwards.

Trouble Making Spooles

I am trying to make Spooles 2.2-9 on Mint Maya linux distro and I get the following error.
aaron#atown ~/Downloads/spooles $ sudo make global
cd A2/src ; make -f makeGlobalLib
make[1]: Entering directory `/home/aaron/Downloads/spooles/A2/src'
makeGlobalLib:19: warning: overriding commands for target `.c.o'
../../Make.inc:90: warning: ignoring old commands for target `.c.o'
/usr/lang-4.0/bin/cc -c -O basics.c -o A2_basics.o
make[1]: /usr/lang-4.0/bin/cc: Command not found
make[1]: *** [basics.o] Error 127
make[1]: Leaving directory `/home/aaron/Downloads/spooles/A2/src'
make: *** [global] Error 2
I am new to linux so any help would be most useful.Thanks
Have you tried installing it from your software package manager? I know that package is provided by Ubuntu and Debian, and Mint is a derivative so it should have it available for installation. No need to build it yourself.
If you do want to compile it yourself, first note you should never build software as root (don't prefix the make command with sudo). It's possible that if there's an install step you'll need to run that as root, but generally not the build.
Second it looks like by default this package is configured to build on OSX (I think /usr/lang-4.0/bin/cc is an OSX path... maybe?). In any event, that's not where the compiler lives on Linux: try this to override the compiler:
make CC=gcc global
It's also possible that your system does not have a compiler installed. If you get an error from the above then use your software package manager to install the gcc package.

make error: No such file or directory

I am new to kernel module development. So I started with simple hello world kernel module
I am using "The Linux Kernel Module Programming Guide" book for the reference (it is addressing to kernel 2.6).
I installed kernel-devel and kenel headers with yum. I am using fedora 17.
I found that a symlink
/lib/modules/3.3.4-5.fc17.x86_64/build -> /usr/src/kernels/3.3.4-5.fc17.x86_64
Now, I have one hello-1.c (the simple kernel module and a Makefile in my working directory)
The Makefile is:
obj-m += hello-1.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
when in $make i get error:
make -C /lib/modules/3.3.4-5.fc17.x86_64/build M=/root/kerneldev modules
make: *** /lib/modules/3.3.4-5.fc17.x86_64/build: No such file or directory. Stop.
make: *** [all] Error 2
I make same program on Centos-5.x it run successfully , because the /lib/modules/3.3.4-5.fc17.x86_64/build was containing the actual module (not a symlink).
What should be problem ? why such difference?
The message
make: *** /lib/modules/3.3.4-5.fc17.x86_64/build: No such file or directory. Stop.
Is telling you that the directory path after the *** does not exist. Make issues this exact format of error when the -C directory doesn't exist. Other non-existent path situations will result in more words. For example, if the /lib/modules/3.3.4-5.fc17.x86_64/build directory does exist but it contains no makefile, make will specifically say no makefile found.
So the other answers are giving you ideas to help you create that directory with its proper contents.
And this answer is intended to also help people who have the above form of error message and for whom installing 'kernel-devel' will not help, by explaining the message itself.
I have few doubts like, where your issuing the make command.
Your current directory seems to be
M=/root/kerneldev
whether your hello-1.c is in /root/kerneldev folder.
try "yum install kernel-devel"(for kernel headers)

User Mode Linux - Installing a module error

I am trying to run 'make' on a module in User Mode Linux to install a simple makefile. Here is my make file:
obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
When I run this in User Mode Linux I get the following error:
make[1]: Entering directory `/lib/modules/2.6.28/build'
make[1]: *** No rule to make target `modules'. Stop.
make[1]: Leaving directory `/lib/modules/2.6.28/build'
make: *** [default] Error 2
The problem is that no files are present under /lib/modules/. There's no directory for 2.6.28 or build. From what I've read, these should be symlinks to /usr/src, but under /usr/src, I don't see any files under that either.
Sources and headers of your UML kernel must be used to compile module for it.
You can compile it either inside UML or just in main system, but you must to use UML's kernel's headers and build scripts
You need to build and install the version of the kernel you are compiling for. Get the source from kernel.org, configure (I think make menuconfig picks the config up from the running kernel), build, and install it. You can do the build in your home directory under regular user, then of course you would need root to install it.
Edit:
Just in case you missed this - here's User Mode Linux HOWTO. It contains specific items for building and installing kernel and modules. Hope this helps.

Resources