1 min read

리눅스 모듈 빌드 (1)

Ubuntu OS 설치시 UEFI를 끄고 설치할것 별도의 보안처리가 있어 추가 설정이 필요하기 때문

커널 모듈을 빌드하기 위한 최소한의 패키지 매니저

ubuntu 기준

sudo apt-get update 
apt-cache search linux-headers-`uname -r`

sudo apt-get install build-essential kmod

hello-1.c

#include <linux/module.h>
#include <linux/printk.h>

int init_module(void){
    pr_info("hello world\n");

    return 0;
}

void cleanup_module(void){
    pr_info("goodbye world \n");
}

MODULE_LICENSE("GPL");

MakeFile

obj-m += hello-1.o 
 
PWD := $(CURDIR) 
 
all: 
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules 
 
clean: 
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

make 빌드후 아래 키워드 입력 모듈 자세한 정보 출력됨

modinfo hello-1.ko

모듈 로드 및 언로드

sudo insmod hello-1.ko 
sudo rmmod hello_1