1

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.

osgx
  • 90,338
  • 53
  • 357
  • 513
Zach
  • 343
  • 1
  • 3
  • 9

2 Answers2

1

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

osgx
  • 90,338
  • 53
  • 357
  • 513
  • Thanks. I'd like to compile in the main system and I have the full source tree in a directory in the main system that I 'make' and boot into for the UML instance. How do you use the UML's headers and build scripts from within the main system? Thanks again! – Zach Mar 22 '10 at 01:23
  • @Zach, just open a manual of creating linux kernel modules, and take a look in Makefiles and compilation options. Change the pathes to kernel. – osgx Mar 22 '10 at 01:43
  • @osgx, Thanks. For instance, the above makefile targets /lib/modules/2.6.28/build. If I were to compile this on my host, it would look at the host /lib/modules/2.6.28/build directory. How would I get it to look into the source tree that UML will be compiled from? I can't find the correlating directory to an uncompiled source that relates to /lib/modules/.......Know what I mean? I may not be making myself clear enough in my description. – Zach Mar 22 '10 at 03:35
  • change KDIR from `KDIR := /lib/modules/$(shell uname -r)/build` to `KDIR := /home/Zach/kernels/uml/uml-2.6.36` – osgx Mar 22 '10 at 10:35
  • and add to make string `arch=um` – osgx Mar 22 '10 at 10:36
0

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.

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
  • I do. I build and install linux 2.6.28 in UML. I then run ./linux to enter the UML instance and try to compile a module that I built for the UML instance. In my UML instance, I have no directory for lib/modules/.... and no directory for /usr/src/.... so the makefile above fails with the error above. – Zach Mar 21 '10 at 21:00
  • Hmm, not really familiar with UML. You probably can convince the kernel build to install into whatever directory the UML mounts. – Nikolai Fetissov Mar 21 '10 at 21:10