User Mode Linux - Installing a module error - linux-kernel

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.

Related

How to rename a built-in linux kernel module?

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.

Cross Compile Linux Kernel Module

I am looking into cross compiling a kernel module for an ARM linux. I have my toolchain installed.
But there's something I am not quite getting from various how-tos.
The module I want to build is gadgetfs.
The kernel version on my host is 3.5.0-34-generic while
on the target it's 3.6.9-0.1
Now what kernel sources or headers do I actually need to download and install, and where?
I downloaded linux-3.6.9.tar.bz2 from kernel.org and extracted it.
In drivers/usb/gadget/ there's a Makefile and according to this site I need to append these lines to it, then run make:
KDIR := /lib/modules/`uname -r`/build
PWD := `pwd`
obj-m := dummy_hcd.o gadgetfs.o
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
But what do i have to replace uname -r with? Cause this would give me my host's kernel version. But my target version is different. Where is the /lib/modules/3.6.9 folder?
CROSS_COMPILE and ARCH is both set.
You need to cross compile (or download pre-compiled) matching version of Linux for your target on your host machine with right configuration since Linux doesn't have a stable binary API. Host's kernel version is not relevant.
After having target build available on your host you can build a module via
make -C kernel_build_dir M=`pwd` ARCH=arm CROSS_COMPILE=<...> modules
under that module's directory.

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)

The same Makefile succeeded in Ubuntu 10.04 LTS but failed in Angstrom on Beagle Board

I tried to compile chardev.c from this tutorial using the following Makefile:
obj-m := chardev.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default :
$(MAKE) -C $(KDIR) M=$(PWD) modules
I got the correct output and it is working fine while I make in Ubuntu 10.04 LTC:
make -C /lib/modules/2.6.32-33-generic-pae/build M=/home/noge/Desktop/driver- tutorial/IOCTL_example/ioctl_eclipse modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-33-generic-pae'
Building modules, stage 2.
MODPOST 1 modules
LD [M] /home/noge/Desktop/driver-tutorial/IOCTL_example/ioctl_eclipse/chardev.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-33-generic-pae'
However, when I transfer the same files to BeagleBoard that is running Angstrom, and did a make CROSS_COMPILE=arm-angstrom-linux-gnueabi-, I got the following error:
root#beagleboard:~/Desktop/noge/C-tutorials/hello_world# make CROSS_COMPILE=
arm-angstrom-linux-gnueabi-
make -C /lib/modules/2.6.32/build M=/home/root/Desktop/noge/C-tutorials/hels
make[1]: Entering directory `/usr/src/linux-2.6.32/2.6_kernel'
Makefile:1448: *** mixed implicit and normal rules. Stop.
make[1]: Leaving directory `/usr/src/linux-2.6.32/2.6_kernel'
make: *** [default] Error 2
I'm not sure if this is the cause, but I noticed the version of make is different for the Ubuntu and Angstrom:
Angstrom's version:
GNU Make 3.82
Built for arm-angstrom-linux-gnueabi
Ubuntu's version:
GNU Make 3.81
This program built for i486-pc-linux-gnu
In short, why the error while doing make in Beagle Board running Anstrom?
Thanks for any help..!
Update:
The content of the Makefile near line 1448:
1447 # Modules
1448 / %/: prepare scripts FORCE
1449 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1450 $(build)=$(build-dir)
1451 %.ko: prepare scripts FORCE
1452 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1453 $(build)=$(build-dir) $(#:.ko=.o)
1454 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
I did a check on my kernel version and I got:Linux beagleboard 2.6.32 #3 PREEMPT Thu Jun 23 09:56:19 CEST 2011 armv7l GNU/Linux, but the kernel source I got from here is of version 2.6.22.18.
Is it possible for getting the wrong kernel source code that is causing this ?
I'm fairly sure your Makefile is not at fault here, but there might be a rule name collision. What is at line 1448 of /usr/src/linux-2.6.32/2.6_kernel/Makefile ?

Resources