2. 목차
• 커널 중요 디렉토리 이해 하기
• 커널 컴파일 준비 하기
• 커널 컴파일 진행 하기
• 커널 이미지 파일 설치 하기
• 추가 설명
• 커널 컴파일 시간 줄이기
3. 커널 중요 디렉토리 이해 하기
linux-4.9.7linux-4.9.7kernel // 프로세스, 타이밍, 시그널, 모듈, 커널 핵심 코드
linux-4.9.7linux-4.9.7include // 커널 소스 헤더 파일
linux-4.9.7linux-4.9.7dirvers // 하드웨어를 제어하는 디바이스 드라이버
linux-4.9.7linux-4.9.7net // 네트워크 프로토콜 스택
linux-4.9.7linux-4.9.7lib // 커널 내부적으로 사용하는 범용 함수 라이브러리
linux-4.9.7linux-4.9.7arch // 플랫폼(아키텍처)에 의존적인 코드
4. 커널 컴파일 준비 하기
준비 물
커널 컴파일할 대상 PC 1EA(테스트 시 가상머신도 가능) ubuntu16.04 LTS버전
설치
커널 컴파일할 소스 준비
컴파일 할 pc정보
코어 개수 : 16코어
램 : 16GB
시스템 종류: 64비트 x64프로세서
리눅스 버전 확인
명령어 : cat /etc/issue
Ubuntu 16.04.1 LTS
5. 커널 컴파일 준비 하기
gcc버전 확인 1
root@tester-Virtual-Machine:/usr/src# gcc –v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-
5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-
linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --
enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object -
-disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-
cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-
amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-
ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --
enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-
gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
gcc버전 확인 2
root@tester-Virtual-Machine:/usr/src# gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
커널버전 + gcc버전 확인 3
root@tester-Virtual-Machine:/usr/src# cat /proc/version
Linux version 4.4.0-59-generic (buildd@lgw01-11) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #80-Ubuntu SMP Fri
Jan 6 17:47:47 UTC 2017
6. 커널 컴파일 준비 하기
커널 소스 다운로드
https://www.kernel.org/
다운로드 파일
linux-4.9.7.tar
7. 커널 컴파일 진행 하기
실제 커널 정보 확인
$ uname -a
Linux tester-Virtual-Machine 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64
x86_64 x86_64 GNU/Linux
$ uname -r
4.4.0-59-generic
커널 컴파일에 필요한 패키지 설치
sudo apt-get install build-essential libncurses5 libncurses5-dev bin86 kernel-package –y
기존 소스 확인
$ ls -al
total 24
drwxr-xr-x 6 root root 4096 1월 15 10:17 .
drwxr-xr-x 11 root root 4096 7월 20 2016 ..
drwxr-xr-x 27 root root 4096 2월 2 11:59 linux-headers-4.4.0-31
drwxr-xr-x 7 root root 4096 7월 20 2016 linux-headers-4.4.0-31-generic
drwxr-xr-x 27 root root 4096 2월 2 12:05 linux-headers-4.4.0-59
drwxr-xr-x 7 root root 4096 1월 15 10:17 linux-headers-4.4.0-59-generic
8. 커널 컴파일 진행 하기
다운로드 받은 파일을 커널 컴파일 할 pc로 파일 이동
$ mv linux-4.9.7.tar.xz /usr/src/
$ ls -al
total 91052
drwxr-xr-x 6 root root 4096 2월 2 12:31 .
drwxr-xr-x 11 root root 4096 7월 20 2016 ..
-rw-rw-r-- 1 tester tester 93209160 2월 2 12:08 linux-4.9.7.tar.xz
drwxr-xr-x 27 root root 4096 2월 2 11:59 linux-headers-4.4.0-31
drwxr-xr-x 7 root root 4096 7월 20 2016 linux-headers-4.4.0-31-generic
drwxr-xr-x 27 root root 4096 2월 2 12:05 linux-headers-4.4.0-59
drwxr-xr-x 7 root root 4096 1월 15 10:17 linux-headers-4.4.0-59-generic
압축 풀기
xz -d linux-4.9.7.tar.xz
tar xf linux-4.9.7.tar
압축 풀기가 정상적으로 되었는지 확인
root@tester-Virtual-Machine:/usr/src# ls -al
total 679412
drwxr-xr-x 7 root root 4096 2월 2 12:34 .
drwxr-xr-x 11 root root 4096 7월 20 2016 ..
drwxrwxr-x 24 root root 4096 2월 1 16:33 linux-4.9.7
-rw-rw-r-- 1 tester tester 695685120 2월 2 12:08 linux-4.9.7.tar
drwxr-xr-x 27 root root 4096 2월 2 11:59 linux-headers-4.4.0-31
drwxr-xr-x 7 root root 4096 7월 20 2016 linux-headers-4.4.0-31-generic
drwxr-xr-x 27 root root 4096 2월 2 12:05 linux-headers-4.4.0-59
drwxr-xr-x 7 root root 4096 1월 15 10:17 linux-headers-4.4.0-59-generic
9. 커널 컴파일 진행 하기
현재 커널의 configuration 파일을 커널 소스 디렉토리에 복사 합니다.
Virtual-Machine:/usr/src/linux-4.9.7# cp /boot/config-4.4.0-59-generic ./.config
10. 커널 컴파일 진행 하기
Config 파일 복사 확인
$ ls -al
total 912
drwxrwxr-x 24 root root 4096 2월 2 12:46 .
drwxr-xr-x 7 root root 4096 2월 2 12:34 ..
drwxrwxr-x 33 root root 4096 2월 1 16:33 arch
drwxrwxr-x 3 root root 4096 2월 1 16:33 block
drwxrwxr-x 2 root root 4096 2월 1 16:33 certs
-rw-rw-r-- 1 root root 59 2월 1 16:33 .cocciconfig
-rw-r--r-- 1 root root 190047 2월 2 12:43 .config
-rw-rw-r-- 1 root root 18693 2월 1 16:33 COPYING
-rw-rw-r-- 1 root root 98277 2월 1 16:33 CREDITS
drwxrwxr-x 4 root root 4096 2월 1 16:33 crypto
drwxrwxr-x 119 root root 12288 2월 1 16:33 Documentation
drwxrwxr-x 129 root root 4096 2월 1 16:33 drivers
drwxrwxr-x 36 root root 4096 2월 1 16:33 firmware
drwxrwxr-x 75 root root 4096 2월 1 16:33 fs
-rw-rw-r-- 1 root root 31 2월 1 16:33 .get_maintainer.ignore
-rw-rw-r-- 1 root root 30 2월 1 16:33 .gitattributes
-rw-rw-r-- 1 root root 1307 2월 1 16:33 .gitignore
drwxrwxr-x 28 root root 4096 2월 1 16:33 include
drwxrwxr-x 2 root root 4096 2월 1 16:33 init
drwxrwxr-x 2 root root 4096 2월 1 16:33 ipc
-rw-rw-r-- 1 root root 2888 2월 1 16:33 Kbuild
-rw-rw-r-- 1 root root 252 2월 1 16:33 Kconfig
drwxrwxr-x 16 root root 4096 2월 1 16:33 kernel
drwxrwxr-x 12 root root 12288 2월 1 16:33 lib
-rw-rw-r-- 1 root root 7720 2월 1 16:33 .mailmap
-rw-rw-r-- 1 root root 382615 2월 1 16:33 MAINTAINERS
-rw-rw-r-- 1 root root 59015 2월 2 12:39 Makefile
drwxrwxr-x 3 root root 4096 2월 1 16:33 mm
drwxrwxr-x 64 root root 4096 2월 1 16:33 net
-rw-rw-r-- 1 root root 18372 2월 1 16:33 README
-rw-rw-r-- 1 root root 7490 2월 1 16:33 REPORTING-BUGS
drwxrwxr-x 25 root root 4096 2월 1 16:33 samples
drwxrwxr-x 14 root root 4096 2월 1 16:33 scripts
drwxrwxr-x 10 root root 4096 2월 1 16:33 security
drwxrwxr-x 23 root root 4096 2월 1 16:33 sound
drwxrwxr-x 29 root root 4096 2월 1 16:33 tools
drwxrwxr-x 2 root root 4096 2월 1 16:33 usr
drwxrwxr-x 4 root root 4096 2월 1 16:33 virt
11. 커널 컴파일 진행 하기
Menuconfig들어가기
새로받은 소스코드 경로에서 menuconfig들어가기
$ make menuconfig
16. 커널 컴파일 진행 하기
커널 설치 이미지 만들기
즉.ded 패키지 파일을 만들다. 만약 커널에 들어 있지 않은 모듈이 있다면
그 모듈의 .ded파일도 커널에 맞춰서 만듭니다.
업버전 경로로 들어가기
/usr/src/linux-4.9.7
이미지 만들기 명령어 입력
sudo make-kpkg --initrd --revision=1.0 kernel_image
주의 사항
추후에 같은 커널을 여러 번 빌드 하는 경우 “—revision=1.0“, “—
revision=2.0“, “—revision=3.0“ 으로 변경 한다. 버전정보는 숫자만 입력
한다.
25. 추가 설명
y 혹은 m 아니면 #으로 막혀져 있는 것이 있는데 y는 커널에 직접 포함 되도록 설정한 항목을
의미하고 m은 module로 설정한 것, #으로 막힌 것은 사용되지 않는 것을 의미한다.
26. 커널 컴파일 시간 줄이기
Core 개수 확인
cat /proc/cpuinfo
grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+1}’
Cpu core : 16
커널 컴파일 옵션 추가 후 진행
old
sudo make-kpkg --initrd --revision=1.0 kernel_image
new
sudo make-kpkg –j16 --initrd --revision=2.0 kernel_image
주의 할점
코어 개수를 실제 개수 보다 더 크게 넣을 시 시간이 더 걸림.
27. 커널 컴파일 시간 줄이기
Core 개수 미입력시
2시간 50분
Core 개수 입력시
20분