2006년 4월 4일 화요일

GRUB 부트로더에서 새로 컴파일한 커널올리기

출처 : http://infoncom.dongguk.ac.kr/%7Eswhong/cgi-bin/MoinMoin/wiki-moinmoin/ 

GRUB 부트로더에서 새로 컴파일한 커널올리기

커널을 건드리기 시작했다. 필자는 lilo를 사용해 새로 컴파일한 커널을 사용하기 위해 lilo.conf를 수정하는데는 익숙하지만,

GRUB을 사용해보지는 않았다. 커널을 수정하기 전에 GRUB 설정을 수정하는 방법을 소개한다.

/boot/grub

이 디렉토리에 가보면 (grub을 설치했다면) grub.conf 파일이 있다. 필자는 윈도우XP를 깔고, RHL9.0을 깔아 GRUB으로 멀티 부팅을 시켰다.

이제 새로운 커널을 컴파일해 보자. /usr/src/linux 에서 make (mrproper | clean | bzImage | modules | modules_install) 을 차례로 수행한다.

이제 /usr/src/linux/arch/i386/boot/bzImage 를 복사해서 /boot 디렉토리 밑으로 가져와 원하는 이름으로 바꾸자. 필자는 vmlinuz-2.4.20-test 라는 이름으로 복사했다.

그리고 나서 initial ramdisk를 만들어야 한다. 이것은 GRUB이 lilo와는 틀리게 1024 cylinder를 극복하기 위한 방안이다. 즉, bios에서 1024 cylinder주소값 이상을 가르치지

못함으로 해서 1024내에 적재된 boot partition만 인식할 수 있었던 것을 initial ramdisk안에서 좀더 넓은 boot partition address를 인식하기 위해 사용한다.

이때 initrd안에는 모듈이 포함되게 되는데, 커널 컴파일시 make modules; make modules_install; 을 수행하면 /lib/module/2.4.20 과 같이 커널 버전의 이름으로 모듈 디렉토리가 생긴다.

하지만, 기존에 있던 모듈을 덮어쓰지 않기 위해 /lib/module/2.4.20custom 이라는 디렉토리가 생기더라는 것이 중요하다.

이제 우리는 이 모듈들을 포함하여 initial ramdisk를 만들어야 하는데, 다음과 같이 생성한다.

mkinitrd target-file.img source-directory

즉, 필자는 initrd-2.4.20-test.img 라는 이름을 가진 initial ramdisk를 만들기 위해 다음과 같이 명령을 수행했다.

mkinitrd inird-2.4.20-test.img 2.4.20custom

자 이제 /boot 디렉터리안에 initrd-2.4.20-test.img가 생성되었을 것이다.

이제 새로운 커널로 부팅할 수 있도록 grub의 설정파일을 건드려 보자. grub의 설정파일은 /boot/grub/grub.conf 이다.

필자가 수정하기 전의 필자의 머쉰(windxp 와 redhat9.0 가 깔려있는)의 grub.conf는 다음과 같았다.

# grub.conf generated by anaconda #
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,5)
# kernel /vmlinuz-version ro root=/dev/hda9
# initrd /initrd-version.img
# boot=/dev/hda
default=2
timeout=10
fallback 0
splashimage=(hd0,5)/grub/splash.xpm.gz

title Red Hat Linux (2.4.20-8)
root (hd0,5) kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ hdc=ide-scsi
initrd /initrd-2.4.20-8.img



title DOS
rootnoverify (hd0,0)
chainloader +1

이것을 대충 보면 몇가지 궁금한 사항이 생긴다. root (hd0, 5) 라든가 kernel ... 라든가.. 하지만, 필자는 이것을 설명하기엔 시간이 너무 없다.

reference에 링크해 놓은 싸이트를 찾아보라. 아주 잘 설명되어 있다.

자, 그럼 이것을 다음과 같이 바꾸어 내가 새로 컴파일한 커널 이미지 /boot/vmlinuz-2.4.20-test 와 initial ramdisk인 /boot/initrd-2.4.20-test.img 를 넣어보자.

# grub.conf generated by anaconda #
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,5)
# kernel /vmlinuz-version ro root=/dev/hda9
# initrd /initrd-version.img
# boot=/dev/hda
default=2
timeout=10
fallback 0
splashimage=(hd0,5)/grub/splash.xpm.gz
title Red Hat Linux (2.4.20-8)
root (hd0,5)
kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ hdc=ide-scsi
initrd /initrd-2.4.20-8.img



title Red Hat Linux (2.4.20-test)
root (hd0,5)
kernel /vmlinuz-2.4.20-test ro root=LABEL=/ hdc=ide-scsi
initrd /initrd-2.4.20-test.img
title DOS
rootnoverify (hd0,0)
chainloader +1

자, 뭐 대충 통밥으로 다 똑같이 하고 커널 이미지와 initial ramdisk 이름만 바꾸어 준 것을 알 수 있을 것이다. 카카...

하지만, 필자는 initial ramdisk 만드는 것을 몰라 많이 고생을 했다.... 그래서 적는 것이니... 허접하다고는 하지 말기 바란다.

마지막으로 할 일은 설정된 grub.conf를 bios에 굽는 일이다. 다음과 같이 하자.

grub-install /dev/hda

자 이제 모든 것이 완료 되었다.

이제 재부팅을 하여 grub 부트로더가 뜨면 내가 올린 커널을 선택해 보자... 두근두근... 카카... 이제 커널을 수정해 볼까?

댓글 없음:

댓글 쓰기