Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Conversation

@vcaputo
Copy link

@vcaputo vcaputo commented Nov 25, 2015

With this changeset one can build a kernel module out-of-tree in a dev
image in the usual fashion:

 ~# cat Makefile
 obj-m := noop.o
 ~# make -C /lib/modules/4.3.0-coreos-r1/build M=$PWD
 make: Entering directory '/usr/lib64/modules/4.3.0-coreos-r1/build'
   CC [M]  /tmp/noop/noop.o
   Building modules, stage 2.
   MODPOST 1 modules
   CC      /tmp/noop/noop.mod.o
   LD [M]  /tmp/noop/noop.ko
 make: Leaving directory '/usr/lib64/modules/4.3.0-coreos-r1/build'
 ~#

/lib/modules/$(uname -r)/source is now populated with a stripped source
tree (headers, scripts, Makefiles...), prod images may build out-of-tree
modules by simply bind mounting these directories into a toolchain
container without needing kernel source.

Note that this build directory is being populated from the actual
$KBUILD_OUTPUT used in producing the kernel in the image, which has simply
been make cleaned and stripped down:

 /lib/modules/4.3.0-coreos-r1/build# ls -la
 drwxr-xr-x 5 root root   4096 Nov 25 11:56 .
 drwxr-xr-x 4 root root   4096 Nov 25 11:56 ..
 -rw-r--r-- 1 root root 108265 Nov 25 11:52 .config
 -rw-r--r-- 1 root root      2 Nov 25 11:55 .version
 -rw-r--r-- 1 root root    578 Nov 25 11:54 Makefile
 -rw-r--r-- 1 root root 617170 Nov 25 11:55 Module.symvers
 drwxr-xr-x 3 root root   4096 Nov 25 11:23 arch
 -rw-r--r-- 1 root root  23280 Nov 25 11:52 defconfig
 drwxr-xr-x 4 root root   4096 Nov 25 11:23 include
 drwxr-xr-x 6 root root   4096 Nov 25 11:56 scripts
 lrwxrwxrwx 1 root root      9 Nov 25 11:56 source -> ../source
 /lib/modules/4.3.0-coreos-r1/build#

@vcaputo
Copy link
Author

vcaputo commented Nov 25, 2015

This PR uses coreos/linux#3, so lets land that first.

@vcaputo
Copy link
Author

vcaputo commented Nov 25, 2015

@marineam @mjg59 PTAL

@crawford
Copy link
Contributor

Addresses coreos/bugs#949.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably be more readable in a function. I can't think of a need for the subshell otherwise.

With this changeset one can build a kernel module out-of-tree in a dev
image in the usual fashion:
```
 ~# cat Makefile
 obj-m := noop.o
 ~# make -C /lib/modules/4.3.0-coreos-r1/build M=$PWD
 make: Entering directory '/usr/lib64/modules/4.3.0-coreos-r1/build'
   CC [M]  /tmp/noop/noop.o
   Building modules, stage 2.
   MODPOST 1 modules
   CC      /tmp/noop/noop.mod.o
   LD [M]  /tmp/noop/noop.ko
 make: Leaving directory '/usr/lib64/modules/4.3.0-coreos-r1/build'
 ~#
```

/lib/modules/$(uname -r)/source is now populated with a stripped source
tree (headers, scripts, Makefiles...), prod images may build out-of-tree
modules by simply bind mounting these directories into a toolchain
container without needing kernel source.

Note that this build directory is being populated from the _actual_
$KBUILD_OUTPUT used in producing the kernel in the image, which has simply
been `make clean`ed and stripped down:

```
 /lib/modules/4.3.0-coreos-r1/build# ls -la
 drwxr-xr-x 5 root root   4096 Nov 25 11:56 .
 drwxr-xr-x 4 root root   4096 Nov 25 11:56 ..
 -rw-r--r-- 1 root root 108265 Nov 25 11:52 .config
 -rw-r--r-- 1 root root      2 Nov 25 11:55 .version
 -rw-r--r-- 1 root root    578 Nov 25 11:54 Makefile
 -rw-r--r-- 1 root root 617170 Nov 25 11:55 Module.symvers
 drwxr-xr-x 3 root root   4096 Nov 25 11:23 arch
 -rw-r--r-- 1 root root  23280 Nov 25 11:52 defconfig
 drwxr-xr-x 4 root root   4096 Nov 25 11:23 include
 drwxr-xr-x 6 root root   4096 Nov 25 11:56 scripts
 lrwxrwxrwx 1 root root      9 Nov 25 11:56 source -> ../source
 /lib/modules/4.3.0-coreos-r1/build#
```
@vcaputo
Copy link
Author

vcaputo commented Dec 3, 2015

@marineam think we can land this as-is or do you see other things you'd like changed?

@marineam
Copy link
Contributor

marineam commented Dec 3, 2015

LGTM

vcaputo added a commit that referenced this pull request Dec 3, 2015
coreos-kernel: populate /lib/modules/$(uname -r)/build
@vcaputo vcaputo merged commit b2120b5 into coreos:master Dec 3, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants