Score:1

Compile LKM Raspberry Pi - Permission denied

uz flag

I'm following the first example of a Hello World LKM and now I need to compile it.

According to the book, the Makefile needs to be like this:

obj-m+=hello_world.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

And then you need to run make (and it says that you souldn't run sudo make or you'll recompile all Linux kernel headers).

By running this it outputs:

make -C /lib/modules/5.10.63+/build/ M= modules
make[1]: Entering directory '/usr/src/rpi-5.10.y'
/bin/sh: 1: cannot create include/generated/uapi/linux/.version.h.tmp: Permission denied
  UPD     include/generated/uapi/linux/version.h
mv: cannot stat 'include/generated/uapi/linux/.version.h.tmp': No such file or directory
make[1]: *** [Makefile:1277: include/generated/uapi/linux/version.h] Error 1
make[1]: Leaving directory '/usr/src/rpi-5.10.y'
make: *** [Makefile:4: all] Error 2

And if I run sudo make or change the Makefile commands by sudo make -C ... it never ends (>2h and still waiting).

I couldn't run sudo apt install linux-headers-'uname -r' (ignore the ', they are ` but I can't place it here) because the kernel it's the last one (5.10.63+), but I have followed all the steps on the book that tells how to manually compile all Linux kernel headers, so I should have them.

Any idea? If you need some extra information just tell me what command I need to run and I'll attach the output.

Thanks!

galexite avatar
pk flag
The value for `M=` is empty. This chooses the directory in which the module you are building is found. When empty, it will try and build the `Makefile` in your `/lib/modules` directory, which you do not have write access to. Hence, when `make` tries to create a file, it fails.
hr flag
+1 ... it likely should be `M=$(PWD)` not `M=$(pwd)`
Roger Miranda Perez avatar
uz flag
You're right, I should've used M=$(PWD)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.