Jun10ng / ebpf-docker-for-desktop

Build a docker at MacOS/Windows for eBPF learning.
36 stars 16 forks source link

Error : Seeing error while running the hello.py #2

Open iamshreeram opened 1 year ago

iamshreeram commented 1 year ago

Hi @Jun10ng , Im trying to run the docker image in macOS. Seeing below error while running the hello.py

<built-in>:1:10: fatal error: './include/linux/kconfig.h' file not found
#include "./include/linux/kconfig.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Traceback (most recent call last):
  File "/root/example/./hello.py", line 6, in <module>
    b = BPF(src_file="hello.c")
  File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 364, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module b'hello.c'
Jun10ng commented 1 year ago

I remembered that I've encountered this error too. U can have try run /root/linuxkit-complier.sh

iamshreeram commented 1 year ago

@Jun10ng , Thanks for responding.

Yes, I ran /root/linuxkit-complier.sh, Still no luck. Im seeing same error.

I have few questions -

My /lib/modules/$(uname -r)/ - both build and source are empty directories - is this expected?

image

This is causing, /usr/src/$(uname -r)/ to be empty

My uname -r is 6.4.16-linuxkit - is this valid? I think it must be 5.10.76-linuxkit;

For some reason, The setup is pulling 6.4.16-linuxkit.tar.gz and it doesnt have any data (0 bytes) in it;

It would be good to modify the script /root/linuxkit-complier.sh to throw error if the build and source path are empty.

Appreciate your support. Thanks!

Jun10ng commented 1 year ago

uname -r should be 5.10.76-linuxkit, bcs I built this image on v5.10.76. Have u ever saw any errors been thrown by linuxkit-complier.sh

iamshreeram commented 1 year ago

@Jun10ng , Thats interesting. My uname -r is 6.4.16-linuxkit; So, when linuxkit-dl.sh runs, this writes the linux-5.10.76.tar.gz file with name of 6.4.16-linuxkit.tar.gz. Is there anyway to find why the uname-r is pointing to 6.4.16-linuxkit?

Below is the output of linuxkit-complier.sh

coping file to source/
coping file to build/
creating config file
make: *** No rule to make target 'menuconfig'.  Stop.
make: *** No rule to make target 'defconfig'.  Stop.
preparing
make: *** No rule to make target 'prepare'.  Stop.

The actual kernel-dev.tar from dockerfile contains same linuxkit i believe?

COPY --from=ksrc /kernel-dev.tar /

Any reason for having both kernel-kit?

Thanks!

iamshreeram commented 1 year ago

The source code is available inside /usr/src/6.4.16-linuxkit/linux-5.10.76 and /usr/src/linux-headers-5.10.76-linuxkit :

image
Jun10ng commented 1 year ago

https://github.com/Jun10ng/ebpf-docker-for-desktop/blob/507173e82ce9020d94072e61754f00986c790aa5/linuxkit-dl.sh#L5C1-L6C1

Seems my script "bug". It uses uname -r as download file name. But I have no idea why your docker image built on 6.4.16 Below is my dockfile. https://github.com/Jun10ng/ebpf-docker-for-desktop/blob/507173e82ce9020d94072e61754f00986c790aa5/Dockerfile#L1C50-L1C50

iamshreeram commented 1 year ago

While untar'ing the linuxkit, I get the linux-5.10.76 & linux-5.10.76-headers-linuxkit inside /usr/src/6.4.16-linuxkit.

image

Also, Do I run the below make commands inside /usr/src/$(uname -r)?

make -r menuconfig   
make -r defconfig

Below is the list of directories, after fixing the code, the Below is the location of linux-5.10.76 and linux-headers-5.10.76-linuxkit

image

Would you be able to share the directory and file structure; So, I can configure the docker image accordingly;

iamshreeram commented 1 year ago

@Jun10ng , Could you please help me with below questions -

  1. How is the uname -r determined in this docker image?
  2. I see you are downloading the kernel file as ksrc; Do we still need the linux-5.10.76?
  3. Could you please share the directory structure of /lib/modules/ and /usr/src (tree should be able to help);

Appreciate your help. thanks!

iamshreeram commented 1 year ago
1. How is the `uname -r` determined in this docker image?

This is determined by the linuxkit my docker-desktop uses. Since I use the latest version of docker-desktop, my uname -r seems to be 6.4.16-linuxkit. Source - Opeoonikute

Jun10ng commented 1 year ago

@iamshreeram Sorry, My office network seems block some sources, and I will try it on weekend~

Jun10ng commented 1 year ago

@iamshreeram It's wired. I can't build this image since I encounter a problem below, it seems ubuntu's version had not supported. Did u solved it before?

#13 5.381   404  Not Found [IP: 198.18.0.117 80]
#13 6.058 Err:6 http://archive.ubuntu.com/ubuntu -updates Release
#13 6.058   404  Not Found [IP: 198.18.0.117 80]
#13 6.793 Err:7 http://archive.ubuntu.com/ubuntu -security Release
#13 6.793   404  Not Found [IP: 198.18.0.117 80]
#13 7.810 Err:8 http://archive.ubuntu.com/ubuntu -backports Release
#13 7.810   404  Not Found [IP: 198.18.0.117 80]

I tried to replace sources.list and it still not works.

iamshreeram commented 1 year ago

@Jun10ng , Yes; I was seeing same error. Two solution -

  1. It worked when I use latest version of ubuntu;
    FROM ubuntu:latest
  2. I resolved it by providing the old source list of ubuntu

As Ubuntu 21.04 went on EoL, We are seeing this error;