Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

WSL + eBPF: modprobe: FATAL: Module kheaders not found in directory

다음과 같은 오류가 발생한다면?

$ sudo bpftrace -e 'BEGIN { printf("hello\n"); }'
modprobe: FATAL: Module kheaders not found in directory /lib/modules/5.15.153.1-microsoft-standard-WSL2
Attaching 1 probe...
hello

실제로 WSL의 경우 /lib/modules 디렉터리는 텅 비어 있습니다. 검색해 보니까, 해결책이 나오는데요, ^^

Enable CONFIG_IKHEADERS=m in WSL kernel #5526
; https://github.com/microsoft/WSL/issues/5526

cd /path/to/WSL2-Linux-Kernel #check out branch corresponding to uname -r tag
make KCONFIG_CONFIG=Microsoft/config-wsl
sudo ln /path/to/WSL2-Linux-Kernel -s /lib/modules/4.19.104-microsoft-standard/build


정리해 보면, (또 다른 방법이 있는지는 알 수 없으나) 현재로서는 커널 소스를 빌드하는 수밖에는 없습니다. 따라서 지난 글에 설명한 대로 (가능하다면) 현재 설치된 버전의 WSL 커널 소스를 다운로드해 빌드하시면 됩니다. 설치를 완료했으면, 이제 다음과 같은 경로가 있어야 합니다.

// 5.15.153.1 WSL 커널 소스를 빌드하면 /lib/modules/ 디렉터리 하위에 2개의 디렉터리가 생성됩니다.
// * 5.15.153.1-microsoft-standard-WSL2
// * 5.15.153.1-microsoft-standard-WSL2+
//
// 테스트를 해보면, 저 상태에서 커널을 교체하지 않아도 (디렉터리가 이미 있으므로,
// bpftrace 명령어가 잘 동작합니다.

$ ll /lib/modules/5.15.153.1-microsoft-standard-WSL2+/build
lrwxrwxrwx 1 root root 34 Oct 22 20:50 /lib/modules/5.15.153.1-microsoft-standard-WSL2+/build -> /home/testusr/temp/WSL2-Linux-Kernel/

// 이외에도 source 경로도 링크돼 있습니다.
$ ll /lib/modules/5.15.153.1-microsoft-standard-WSL2+/source
lrwxrwxrwx 1 root root 34 Oct 22 20:50 /lib/modules/5.15.153.1-microsoft-standard-WSL2+/source -> /home/testusr/temp/WSL2-Linux-Kernel/

보시면, WSL 소스코드를 다운로드해 빌드한 경로가 (아마도 "make modules_install headers_install" 명령에서) 자동으로 /lib/modules/.../build로 링크돼 있습니다.

이후 다시 bpftrace 예제를 실행하면 아무런 오류 메시지 없이 동작할 것입니다.

$ sudo bpftrace -e 'BEGIN { printf("hello\n"); }'
Attaching 1 probe...
hello
^C




참고로 "kheaders not found"와 관련해 검색해 보면,

Issue with bcc tools execution #3686
; https://github.com/iovisor/bcc/issues/3686

오류 메시지에 CONFIG_IKHEADERS 옵션을 적용하지 않고 커널 빌드를 했기 때문이라고 나옵니다.

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

실제로 WSL의 경우 해당 옵션이 비활성화돼 있습니다.

// WSL + Ubuntu 20.04 LTS

$ zcat /proc/config.gz | grep CONFIG_IKHEADERS
# CONFIG_IKHEADERS is not set

$ dpkg --get-selections | grep linux-headers-$(uname -r)
$

반면, (WSL이 아닌) 별도로 설치한 Ubuntu 22.04의 경우에는 이렇게 headers가 설치돼 있습니다.

// Ubuntu 22.04 LTS (VM)

$ cat /boot/config-$(uname -r) | grep CONFIG_IKHEADERS
CONFIG_IKHEADERS=m

$ dpkg --get-selections | grep linux-headers-$(uname -r)
linux-headers-6.8.0-47-generic                  install

만약 WSL 이미지도 저렇게 CONFIG_IKHEADERS를 활성화하고 싶다면 커널 소스를 빌드하기 전에 ".config" 파일을 수정해 CONFIG_IKHEADERS 값을 "m"으로 변경하면 됩니다.

// WSL 커널 소스코드를 다운로드한 경로

$ cat .config | grep CONFIG_IKHEADERS
CONFIG_IKHEADERS=m

또는 텍스트 편집기로 직접 수정하는 것이 귀찮다면, "make menuconfig" 명령을 내려도 되지만,

$ make menuconfig

// 이후 뜨는 설정 창에서 "General setup" -> "Enable kernel headers through /sys/kernel/kheaders.tar.xz (NEW)" 옵션을 켜서 .config 파일에 반영

어차피 소스코드와 함께 빌드를 했다면 kheaders에 준하는 모든 파일들이 마련돼 있으므로 굳이 저 옵션을 적용해 빌드할 필요까지는 없습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 10/23/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  37  38  39  [40]  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
12936정성태1/22/202215348.NET Framework: 1138. C# - ffmpeg(FFmpeg.AutoGen)를 이용해 멀티미디어 파일의 메타데이터를 보여주는 예제(metadata.c)파일 다운로드1
12935정성태1/22/202216019.NET Framework: 1137. ffmpeg의 파일 해시 예제(ffhash.c)를 C#으로 포팅파일 다운로드1
12934정성태1/22/202215449오류 유형: 788. Warning C6262 Function uses '65564' bytes of stack: exceeds /analyze:stacksize '16384'. Consider moving some data to heap. [2]
12933정성태1/21/202215933.NET Framework: 1136. C# - ffmpeg(FFmpeg.AutoGen)를 이용해 MP2 오디오 파일 디코딩 예제(decode_audio.c)파일 다운로드1
12932정성태1/20/202217031.NET Framework: 1135. C# - ffmpeg(FFmpeg.AutoGen)로 하드웨어 가속기를 이용한 비디오 디코딩 예제(hw_decode.c) [2]파일 다운로드1
12931정성태1/20/202213552개발 환경 구성: 632. ASP.NET Core 프로젝트를 AKS/k8s에 올리는 과정
12930정성태1/19/202214793개발 환경 구성: 631. AKS/k8s의 Volume에 파일 복사하는 방법
12929정성태1/19/202214752개발 환경 구성: 630. AKS/k8s의 Pod에 Volume 연결하는 방법
12928정성태1/18/202214572개발 환경 구성: 629. AKS/Kubernetes에서 호스팅 중인 pod에 shell(/bin/bash)로 진입하는 방법
12927정성태1/18/202215092개발 환경 구성: 628. AKS 환경에 응용 프로그램 배포 방법
12926정성태1/17/202215020오류 유형: 787. AKS - pod 배포 시 ErrImagePull/ImagePullBackOff 오류
12925정성태1/17/202215669개발 환경 구성: 627. AKS의 준비 단계 - ACR(Azure Container Registry)에 docker 이미지 배포
12924정성태1/15/202217176.NET Framework: 1134. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 비디오 디코딩 예제(decode_video.c) [2]파일 다운로드1
12923정성태1/15/202215962개발 환경 구성: 626. ffmpeg.exe를 사용해 비디오 파일을 MPEG1 포맷으로 변경하는 방법
12922정성태1/14/202214770개발 환경 구성: 625. AKS - Azure Kubernetes Service 생성 및 SLO/SLA 변경 방법
12921정성태1/14/202212524개발 환경 구성: 624. Docker Desktop에서 별도 서버에 설치한 docker registry에 이미지 올리는 방법
12920정성태1/14/202213843오류 유형: 786. Camtasia - An error occurred with the camera: Failed to Add Video Sampler.
12919정성태1/13/202213374Windows: 199. Host Network Service (HNS)에 의해서 점유되는 포트
12918정성태1/13/202213837Linux: 47. WSL - shell script에서 설정한 환경 변수가 스크립트 실행 후 반영되지 않는 문제
12917정성태1/12/202213026오류 유형: 785. C# - The type or namespace name '...' could not be found (are you missing a using directive or an assembly reference?)
12916정성태1/12/202212299오류 유형: 784. TFS - One or more source control bindings for this solution are not valid and are listed below.
12915정성태1/11/202212912오류 유형: 783. Visual Studio - We didn't find any interpreters
12914정성태1/11/202216120VS.NET IDE: 172. 비주얼 스튜디오 2022의 파이선 개발 환경 지원
12913정성태1/11/202216534.NET Framework: 1133. C# - byte * (바이트 포인터)를 FileStream으로 쓰는 방법 [1]
12912정성태1/11/202216524개발 환경 구성: 623. ffmpeg.exe를 사용해 비디오 파일의 이미지를 PGM(Portable Gray Map) 파일 포맷으로 출력하는 방법 [1]
12911정성태1/11/202212998VS.NET IDE: 171. 비주얼 스튜디오 - 더 이상 만들 수 없는 "ASP.NET Core 3.1 Web Application (.NET Framework)" 프로젝트
... 31  32  33  34  35  36  37  38  39  [40]  41  42  43  44  45  ...