Re: A question about build Linux kernel directory


Brendan Gregg
 

G'Day Nan,

On Sun, Oct 16, 2016 at 7:58 PM, Nan Xiao via iovisor-dev <iovisor-dev@...> wrote:
Hi all,

Greetings from me!

I install the newest Linux kernel 4.8.1 on CentOS 7, and want to try BPF feature. When I execute bcc/examples/hello_world.py,
the following error is generated:  

# ./hello_world.py
chdir(/lib/modules/4.8.1/build): No such file or directory
Traceback (most recent call last):
  File "./hello_world.py", line 11, in <module>
    BPF(text='int kprobe__sys_clone(void *ctx) { bpf_trace_printk("Hello, World!\\n"); return 0; }').trace_print()
  File "/usr/lib/python2.7/site-packages/bcc/__init__.py", line 205, in __init__
    raise Exception("Failed to compile BPF module %s" % src_file)
Exception: Failed to compile BPF module

I check the /lib/modules/4.8.1/ directory:  
lrwxrwxrwx.  1 root root     17 Oct 14 11:29 build -> /root/linux-4.8.1
lrwxrwxrwx.  1 root root     17 Oct 14 11:29 source -> /root/linux-4.8.1

The  /root/linux-4.8.1 is the folder which is used to build 4.8.1 kernel, since it occupies too much space, I delete it after installing. 
So to compile BPF module, does it mean I need to recover the linux-4.8.1 source code and build it again?

I think it's messed up because you deleted the source, and now the build symlink is broken.

Here's an Ubuntu system that does not have kernel source, and yet bcc works fine:

# ls -l /lib/modules/4.4.0-31-generic/build
lrwxrwxrwx 1 root root 39 Jul 13 02:08 /lib/modules/4.4.0-31-generic/build -> /usr/src/linux-headers-4.4.0-31-generic

... did you run "make install_headers" after the kernel build? I wonder if that A) puts headers in /usr/src, and B) changes the symlink.

Brendan

Join iovisor-dev@lists.iovisor.org to automatically receive all group messages.