bcc icon indicating copy to clipboard operation
bcc copied to clipboard

Issue with bcc tools execution

Open sherpaurgen opened this issue 3 years ago • 4 comments

Ubuntu Server 20.04.3 LTS, Kernel 5.4.0-84-generic This is similar to 3386 i have tried both package installer and build from source method but get this error

~# tcplife-bpfcc 
modprobe: FATAL: Module kheaders not found in directory /lib/modules/5.4.0-84-generic
Unable to find kernel headers. Try rebuilding kernel with CONFIG_IKHEADERS=m (module)
chdir(/lib/modules/5.4.0-84-generic/build): No such file or directory
Traceback (most recent call last):
  File "/usr/sbin/tcplife-bpfcc", line 456, in <module>
    b = BPF(text=bpf_text)
  File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 347, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

I think the CONFIG_IKHEADERS=m option is enabled in the kernel build

root@server1:/# cat /usr/src/linux-headers-5.4.0-84-generic/.config | grep CONFIG_IKHEADERS
CONFIG_IKHEADERS=m

# dpkg --get-selections | grep linux
binutils-x86-64-linux-gnu			install
console-setup-linux				install
libselinux1:amd64				install
linux-base					install
linux-firmware					install
linux-generic					install
linux-headers-5.4.0-84				install
linux-headers-5.4.0-84-generic			install
linux-headers-5.4.0-89				install
linux-headers-5.4.0-89-generic			install
linux-headers-generic				install
linux-image-5.4.0-81-generic			deinstall
linux-image-5.4.0-84-generic			install
linux-image-5.4.0-89-generic			install
linux-image-generic				install
linux-libc-dev:amd64				install
linux-modules-5.4.0-81-generic			deinstall
linux-modules-5.4.0-84-generic			install
linux-modules-5.4.0-89-generic			install
linux-modules-extra-5.4.0-81-generic		deinstall
linux-modules-extra-5.4.0-84-generic		install
linux-modules-extra-5.4.0-89-generic		install
util-linux					install

# uname -r
5.4.0-84-generic

sherpaurgen avatar Nov 03 '21 05:11 sherpaurgen

If you have tried build from source, try:

$ cd tools
$ sudo ./tcplife.py

chenhengqi avatar Nov 03 '21 06:11 chenhengqi

@chenhengqi , it returned same error

root@server1:/check/bcc# ./tools/execsnoop.py 
modprobe: FATAL: Module kheaders not found in directory /lib/modules/5.4.0-84-generic
Unable to find kernel headers. Try rebuilding kernel with CONFIG_IKHEADERS=m (module) or installing the kernel development package for your running kernel version.
chdir(/lib/modules/5.4.0-84-generic/build): No such file or directory
Traceback (most recent call last):
  File "./tools/execsnoop.py", line 227, in <module>
    b = BPF(text=bpf_text)
  File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 479, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

root@server1:/check/bcc# ./tools/tcplife.py 
modprobe: FATAL: Module kheaders not found in directory /lib/modules/5.4.0-84-generic
Unable to find kernel headers. Try rebuilding kernel with CONFIG_IKHEADERS=m (module) or installing the kernel development package for your running kernel version.
chdir(/lib/modules/5.4.0-84-generic/build): No such file or directory
Traceback (most recent call last):
  File "./tools/tcplife.py", line 474, in <module>
    b = BPF(text=bpf_text)
  File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 479, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

root@server1:/check/bcc# pwd /check/bcc

root@server1:/check/bcc# ls 
build  CMakeLists.txt  CONTRIBUTING-SCRIPTS.md  Dockerfile.debian  Dockerfile.ubuntu  examples  images      introspection  LICENSE.txt  man            README.md  snap   src    tools
cmake  CODEOWNERS      debian                   Dockerfile.tests   docs               FAQ.txt   INSTALL.md  libbpf-tools   LINKS.md     QUICKSTART.md  scripts    SPECS  tests

sherpaurgen avatar Nov 03 '21 10:11 sherpaurgen

When installing BCC both package installer and build from source method , the two libbpf packages could cause conflicts. Try compiling and installing the release version of BCC tools in a pure clean environment at https://github.com/iovisor/bcc/releases/tag/v0.15.0. Good luck!

RiskVirusPro avatar Nov 30 '21 06:11 RiskVirusPro

The problem of software package version mismatch can be solved by keeping the linux-xxx-5.4.0-84-generic version and uninstalling other versions.

yanyan2015 avatar Apr 30 '24 05:04 yanyan2015