Linux Booting bckddndaum net 1 15 SUN Sparc
Linux Booting 과정 이해 백창우 bckddn@daum. net 1
부팅 과정 도식도 (1/5) SUN Sparc, … ROM BIOS HDD의 MBR Intel ix 86 Power On VGA 체크 Memory 체크 IDE 장치 체크 FDD의 MBR 각종 장치 정보 수집 Strong. ARM, XScale, … Flash Memory MBR에 있는 Boot loader 로딩 또는 bootsect. S 로딩 The place for generating the top 1% software experts
부팅 과정 도식도 kernel을 main memory로 로딩 (2/5) kernel 압축 해제 The place for generating the top 1% software experts
부팅 과정 도식도 (3/5) 초기화 code 수행 start_kernel() { Architecture 의존적인 설정 trap에 대한 초기화 Interrupt에 대한 초기화 Scheduler에 대한 초기화 softirq에 대한 초기화 Timer 초기화 Console 초기화 kernel module 사용을 위한 초기화 kernel cache에 대한 초기 설정 Clock tick과 Bogo. MIPS를 구함 buddy system 사용을 위한 memory 초기화 kernel cache에 대한 초기화 fork에 관한 초기화 (max threads) 각종 kernel cache 및 buffer에 대한 생성 및 초기화 /proc 디렉토리에 대한 초기화 IPC에 대한 초기화 SMP에 대한 초기화 init kernel thread 시작 kernel idle init kernel thread 각종 interface 장치 초기화 network interface 초기화 initrd 로딩 및 ‘/’ mount free memory 재 계산 console open /sbin/init process 수행 } The place for generating the top 1% software experts
부팅 과정 도식도 (4/5) /etc/rc. d/rc. sysinit /sbin/init 수행 signal handler 설정 console 설정 /etc/inittab 파일 read /etc/rc. d/rc. sysinit script 수행 /etc/rc. d/rc script 수행 /sbin/mingetty 수행 run level 5이면 /etc/X 11/prefdm수행 /etc/X 11/prefdm gdm 또는 kdm 또는 xdm 실행 host name 설정 시간 설정 usb 설정 file system check ISA 설정 sound 설정 /etc/rc. d/rc 3 run level에 따른 /etc/rc*. d 디렉토리의 script를 수행 /sbin/mingetty 가상 터미널을 띄우고 login 프로그램 실행 The place for generating the top 1% software experts
부팅 과정 도식도 (5/5) /sbin/login 인증 수행 후 shell 실행 Shell 실행 The place for generating the top 1% software experts
ROM BIOS의 구조 (2/2) CMOS의 구조 POST 과정 The place for generating the top 1% software experts
MBR의 이해 (2/2) MBR 이미지 (dd if=/dev/had of=MBR. img bs=1 c count=512) LILO 문자열 time out 시간 jmp 0 x 7 C second boot loader의 위치 map 파일 image 디스크 립트 1 위치 Boot Loader code 파티션 1 파티션 2 파티션 3 파티션 4 fs type The place for generating the top 1% software experts Magic number
LILO first. S loading BIOS의 시스템 초기화가 끝날 무렵 MBR에 있는 LILO의 first. S를 메모리의 0 x 7 C 00 (0 x 7 C 0: 0 x 0000)으로 옮기고 제어를 0 x 7 C 00으로 넘긴다. 이후 모든 설명은 LILO를 기준으로 설명하고자 한다. 0 x 7 C 00 The place for generating the top 1% software experts first. S
second. S load 1. 하드 디스크상의 second. S를 메모리 0 x 9 B 000 번지로 로딩한다. 0 x 7 C 00 first. S 하드 디스크상의 위치는 lilo명령어를 내릴 때 first. S에 저장된 값이고 second. S는 /boot. b를 의미한다. 2. ‘I’를 화면에 출력하고 제어를 second. S로 옮긴다. 0 x 9 A 000 0 x 9 A 200 0 x 9 B 000 The place for generating the top 1% software experts first. S Stack second. S
second. S의 초기화 작업 1. 터미널 부팅을 사용하는가 체크하고 사용한다면 시리얼 포트를 설정한다. 0 x 7 C 00 first. S 2. 키보드 버퍼를 비운다. 3. 화면에 ‘L’을 출력한다. 0 x 9 A 000 0 x 9 A 200 0 x 9 B 000 23 kjds sadjlkasd sadjlkas ksjd=-= The place for generating the top 1% software experts first. S Stack second. S
Image descriptor table load 1. second. S는 내부 boot parameter(“LILO”, version)의 값을 비교하여 second. S가 제대로 load 되었는가 체크한다. 0 x 7 C 00 first. S 2. 부트 이미지들의 정보가 들어있는 Image descriptor table을 메모리의 0 x 9 D 200에 로드한다. Image descriptor table은 /boot/map 파일 내부에 존재 한다. 3. checksum 값으로 Image descriptor table이 정확이 로드 되었는지 점검한다. 0 x 9 A 000 0 x 9 A 200 0 x 9 B 000 0 x 9 D 200 The place for generating the top 1% software experts first. S Stack second. S Image descriptor table
Keyboard translation table load 1. keyboard translation table을 메모리 0 x 9 D 800에 로드 한다. 0 x 7 C 00 first. S keyboard translation table은 keyboard에서 넘어오는 scan code를 ASCII 코드로 변환 시켜 주는 역할을 수행한다. keyboard translation table 역시 /boot/map 파일 내부에 존재하고 있다. 0 x 9 A 000 0 x 9 A 200 0 x 9 B 000 0 x 9 D 200 first. S Stack second. S Image descriptor table 0 x 9 D 800 keyboard translation table The place for generating the top 1% software experts
Default command line load 1. Default command line을 메모리 0 x 9 D 600 위치에 로드 한다. 0 x 7 C 00 first. S Default command line 역시 /boot/map 파일 내에 존재한다. 2. ‘O’를 화면에 출력한다. 3. “boot : ” prompt를 출력하고 사용자 입력을 기다린다. 0 x 9 A 000 first. S Stack second. S 0 x 9 A 200 0 x 9 B 000 0 x 9 D 200 0 x 9 D 600 0 x 9 D 800 Image descriptor table Default command line, etc keyboard translation table The place for generating the top 1% software experts
RAM disk 및 initrd load 1. 화면에 “Loading”을 출력한다. 2. 사용자의 입력으로 부팅할 boot image가 선택되면 image descriptor tables에서 부팅할 image descriptor를 선택하여 initrd의 사용 여부를 검사하고 initrd를 사용한다면 initrd를 로딩한다. 0 x 7 C 00 first. S initrd의 로딩을 위해 먼저 메모리 량과 initrd의 사이즈를 검사한다. initrd 로딩시 한 sector를 읽을 때마다 화면에 ‘. ’을 출력 0 x 9 A 000 first. S Stack second. S 0 x 9 A 200 0 x 9 B 000 Image descriptor 자료구조 typedef struct { char name[MAX_IMAGE_NAME+1]; char password[MAX_PW+1]; unsigned short rd_size[2]; // ram disk size SECTOR_ADDR initrd, start; // image 시작 sector unsigned short start_page; unsigned short flags, vga_mode; } IMAGE_DESCR; 0 x 9 D 200 0 x 9 D 600 0 x 9 D 800 Image descriptor table Default command line, etc keyboard translation table The place for generating the top 1% software experts
Boot map load 1. /boot/map 파일 내에 있는 boot map을 읽어 메모리의 0 x 9 D 000에 로드 한다. 0 x 7 C 00 first. S 이러한 boot map에는 bootsect. S의 하드디스크상 위치 정보와 setup. S의 하드디스크상 위치 정보가 담겨있다. 0 x 9 A 000 0 x 9 A 200 0 x 9 B 000 0 x 9 D 200 0 x 9 D 600 0 x 9 D 800 first. S Stack second. S Map load area Image descriptor table Default command line, etc keyboard translation table The place for generating the top 1% software experts
Default command line load and save 1. default command line sector(파일)를 재 로딩하여 매직 넘버를 확인한다. 그리고 /boot/map 파일의 boot map 상에 fallback sector가 있다면 default command line(메모리)을 fallback sector의 내용으로 덮어 쓴다. 0 x 7 C 00 first. S fallback sector는 boot map 상의 첫 번째 sector로서 현재 지정된 kernel image로 부팅이 실패 되었을 시 다른 kernel로 부팅 가능하게 다른 kernel을 지정하는 부분이다. 2. 기존의 default command line sector(파일)에 fallback sector의 내용을 write한다. 0 x 9 A 000 0 x 9 A 200 0 x 9 B 000 0 x 9 D 200 0 x 9 D 600 0 x 9 D 800 first. S Stack second. S Map load area Image descriptor table Default command line, etc keyboard translation table The place for generating the top 1% software experts
Parameter line 작성 1. Default command line에 option sector를 로드 한다. option sector는 /boot/map 파일 내에 존재한다. (1/2) 0 x 7 C 00 first. S option sector에는 다음과 같은 내용이 들어 있다. ro BOOT_FILE=/boot/vmlinuz-2. 4. 20 -8 root=LABEL=/ 2. “boot : ” prompt로 부터 받은 내용과 option sector의 내용을 조합하여 Parameter line을 작성한다. 0 x 9 A 000 0 x 9 A 200 0 x 9 B 000 0 x 9 D 200 0 x 9 D 600 0 x 9 D 800 first. S Stack second. S Map load area Image descriptor table Default command line, etc keyboard translation table The place for generating the top 1% software experts
Parameter line 작성 (2/2) 다음은 parameter line을 작성하는 예를 그림으로 나타내었다. command line는 “boot : ” prompt로 부터 받은 정보이고 option sector가 map 파일로 부터 읽어온 option string이다. The place for generating the top 1% software experts
Boot sector load 1. Boot map으로 부터 boot sector의 하드 디스크상의 주소를 알아내어 메모리 0 x 90000 위치에 로드 한다. 0 x 7 C 00 first. S 2. command line magic number위치(0 x 90020)에 magic number를 기입한다. 3. 0 x 90022 위치에 parameter line의 offset을 기입한다. 4. option sector에 VGA에 대한 설정이 있는가 확인하고 있다면 메모리 0 x 506 번지에 쓴다. 0 x 90000 0 x 9 A 200 0 x 9 B 000 0 x 9 D 200 0 x 9 D 600 0 x 9 D 800 boot sector first. S Stack second. S Map load area Image descriptor table Default command line, etc keyboard translation table The place for generating the top 1% software experts
setup. S load 1. setup. S를 하드 디스크에서 읽어 메모리 0 x 90200에 로드한다. 0 x 7 C 00 0 x 90000 0 x 90200 0 x 9 A 000 0 x 9 A 200 0 x 9 B 000 0 x 9 D 200 0 x 9 D 600 0 x 9 D 800 first. S boot sector setup. S first. S Stack second. S Map load area Image descriptor table Default command line, etc keyboard translation table The place for generating the top 1% software experts
kernel load 1. modern kernel(big kernel)인지 flag 값을 비교하여 확인한다. (1/2) 0 x 7 C 00 first. S A 2. load low(z. Image)라면 메모리 0 x 10000 위치에 kernel을 로드 한다. B 2. load high(bz. Image)라면 heap의 사용 가능여부를 따져 보고 사용가능 하다면 loadflags 위치에 LFLAG_USE_HEAP을 설정한다. 3. RAM disk를 사용한다면 setup. S의 ramdisk_image와 ramdisk_size에 initrd의 시작 주소와 initrd의 크기를 각각 넣는다. 0 x 90000 0 x 90200 0 x 9 A 000 0 x 9 A 200 0 x 9 B 000 0 x 9 D 000 B 4. 압축된 modern kernel(big kernel)을 메모리 0 x 100000 위치에 로드 한다. 0 x 9 D 200 5. 제어를 setup. S로 옮긴다. 0 x 9 D 800 0 x 9 D 600 boot sector setup. S first. S Stack second. S Map load area Image descriptor table Default command line, etc keyboard translation table The place for generating the top 1% software experts
kernel load (2/2) 0 x 7 BE kernel (not big kernel)을 로드한 최종 모습 Partition table 0 x 7 FE 0 x 7 C 00 BIOS에서 메모리 에 저장한 정보 first. S 0 x 10000 kernel 0 x 90000 0 x 90200 0 x 9 A 000 0 x 9 A 200 0 x 9 B 000 0 x 9 D 200 0 x 9 D 600 0 x 9 D 800 boot sector setup. S first. S Stack second. S Map load area Image descriptor table Default command line, etc keyboard translation table The place for generating the top 1% software experts
setup. S (1/4) arch/i 386/boot/setup. S : start_of_setup 세컨드리 하드디스크를 읽는다. 만약 SAFE_RESET_DISK_CONTROLLER이 define되었다면 프라이머리를 읽는다. start_of_setup: setup. S의 마지막 부분에 할당되어 있는 setup_sig 1과 setup_sig 2 변수의 값을 읽어 setup. S 가 정상적으로 로딩되었는가 확인한다. (setup_sig 1 = 0 x. AA 55, setup_sig 2 = 0 x 5 A 5 A) good_sig 1: -> good_sig: kernel이 제대로 로딩되었는지 확인한다. (big kernel은 loadflags 변수에 1이 들어 있고 type_of_loader 변수에 kernel을 로딩한 boot loader ids 값이 들어 있음. ) loader_ok: extended memory size를 구함 먼저 BIOS function인 0 xe 820을 사용할 수 있는지 체크하고 사용 가능하면 0 xe 820을 호출, 최대 32번 반복 호출하여 e 820 map struct에 저장 (eax = 0 xe 820; int 0 x 15) 다음으로 BIOS function 0 xe 810을 호출하고 마지막으로 BIOS function 0 x 88을 호출하여 extended memory size를 결정 The place for generating the top 1% software experts
setup. S (3/4) no_mca: PS/2 마우스가 있다면 0 x 901 FF에 0 x. AA를 저장 no_psmouse: APM의 작동 유무 확인 (APM BIOS라면 관련 설정을 함) rmodeswtch_normal: -> default_switch: NMI (Non-Maskable Interrupt)를 포함하여 모든 interrupt를 disable 한다. rmodeswtch_end: code 32 변수에 kernel의 시작 주소를 설정한다. (big kernel 이면 code 32 = 0 x 100000 아니면 code 32 = 0 x 1000) big kernel이 아니라면 0 x 10000에 있는 kernel을 0 x 1000으로 옮긴다. (압축 해제를 위한 공간 확보가 목적) The place for generating the top 1% software experts
setup. S (4/4) a 20_none: A 20 line이 사용 가능한가 테스트 한다. a 20_kbc: empty_8042 루틴을 호출하여 키보드 버퍼를 비운다. A 20 line을 enable시킨다. (movb $0 x. DF, %al; outb %al, $0 x 60) a 20_done: 초기 idt와 gdt를 설정한다. (lidt idt_48; …; lgdt gdt_48; ) coprecess를 초기화 한다. (xorw %ax, %ax; outb %al, $0 xf 0; outb %al, $0 xf 1) IRQ를 재 프로그래밍 해준다. protected mode로 전환 한다. kernel에 제어를 넘긴다. (arch/i 386/boot/compressed/head. S : startup_32) The place for generating the top 1% software experts
head. S (1/4) 1. 보호모드로 전환된 상태에서 data segment 지정을 위한 각 segment select에 값을 지정한다. %es = %fs = %gs = %ds = __KERNEL_DS ( = 0 x 18) (0 x 18은 이진수로 00011000 이고 3 bit 우로 shift하면 0 x 03이 된다. 이 0 x 03이 GDT의 index가 된다. ) 2. stack을 설정하고 A 20라인이 활성화 되었는지 확인한다. %ss = KERNEL_DS, %esp = stack_start arch/i 386/boot/setup. S gdt: . word 0, 0, 0, 0 # dummy. word 0, 0, 0, 0 # unused # kernel code segment. word 0 x. FFFF # 0 x 100000*0 x 1000 = 4 Gb. word 0 # base address = 0. word 0 x 9 A 00 # code read/exec. word 0 x 00 CF # granularity = 4096, 386 # kernel data segment. word 0 x. FFFF # 0 x 100000*0 x 1000 = 4 Gb. word 0 # base address = 0. word 0 x 9200 # data read/write. word 0 x 00 CF # granularity = 4096, 386 GDT (Global Descriptor Table) dummy(0) unused(1) code (2) data (3) 0 x 0000 0 x 0000 0 x 00 CF 0 x 9 A 00 0 x 0000 0 x. FFFF 0 x 00 CF 0 x 9200 0 x 0000 0 x. FFFF The place for generating the top 1% software experts
head. S (2/4) 3. eflags register를 0으로 초기화한 후 kernel 내의 BSS 영역을 0으로 초기화 한다. (BSS 영역은 _end 심볼의 주소 값에서 _edata 심볼의 주소 값을 뺀 크기이다. ) 4. kernel 압축을 0 x 100000 위치에 푼다. “Uncompressing Linux. . . ” 를 출력 후 압축을 풀고 다 푼 후 “Ok, booting the kernel. ”을 출력 normal kernel이면 0 x 1000위치의 압축된 kernel을 0 x 100000 위치로 그냥 풀고 big kernel이면 0 x 100000 위치의 압축된 kernel을 임시 buffer에 풀고 임시 버퍼에 풀린 kernel을 0 x 100000위치에 이동시키기 위한 move_routine_start 루틴을 0 x 1000에 이동시키고 제어를 넘긴다. 제어를 넘겨 받은 move_routine_start 루틴은 0 x 2000 위치에 압축이 풀린 kernel을 0 x 100000으로 복사하고 제어를 arch/i 386/kernel/head. S(0 x 100000)로 넘긴다. normal kernel z. Image 0 x 1000 vmlinux 0 x 100000 The place for generating the top 1% software experts
head. S big kernel (3/4) Uncompressing low buffer 0 x 2000 bz. Image 0 x 90000 0 x 100000 move_routine_start를 복사 후 제어가 넘어감 vmlinux 0 x 1000 bz. Image 0 x 90000 0 x 100000 0 x 2000 move_routine_start에 의해 복사된 후 제어가 kernel로 넘아감 vmlinux 0 x 1000 0 x 2000 vmlinux 0 x 100000 The place for generating the top 1% software experts
head. S (4/4) 5. 제어가 0 x 100000 위치에 있는 arch/i 386/kernel/head. S에 넘어오면 cs와 ss를 제외한 각 segment selector 의 값을 GDT의 kernel data segment를 지칭하게 한다. ds = es = fs = gs = 0 x 18 6. page table을 초기화 하고 paging을 활성화 시킨다. cr 3 = pgd address, cr 0 = PG bit “ 1” 7. stack을 설정한다. lss stack_start, %esp 8. BSS 영역을 모두 0으로 초기화 한다. 9. default interrupt handler를 등록한다. 10. boot parameter와 command line을 empty_zero_page(0 x 104000)로 옮긴다. 11. CPU에 관한 정보를 찾아 설정한다. 12. start_kernel로 제어를 옮긴다. The place for generating the top 1% software experts
start_kernel (1/10) lock_kernel() SMP일 경우 spin lock을 건다. single CPU는 해당되지 않고 SMP CPU는 동시에 여러 processor가 kernel에 진입하는 것을 방지하기 위함 배너를 출력한다. (init/version. c) Linux version 2. 4. 20 -19. 9 (bhcompile@daffy. perf. redhat. com) (gcc version 3. 2. 2 20030222 (Red Hat Linux 3. 2. 2 -5)) #1 Tue Jul 15 17: 03: 30 EDT 2003 The place for generating the top 1% software experts
start_kernel (3/10) parse_options() command line을 parsing한다. 환경변수는 envp_init에 kernel option은 argv_init에 저장 trap_init() 1. idt (Interrupt Descriptor Table)에 예외 처리 핸들러를 등록한다. 2. CPU의 register들을 설정한다. gdtr = gdt_descr, idtr = idt_descr nested task flag bit clear debug register들의 값을 0으로 초기화 FPU 초기화 The place for generating the top 1% software experts
start_kernel / trap_init() (1/4) IDT (Interrupt Descriptor Table)내 예외처리 handler 0 divide_error 11 segment_not_present 1 debug 12 stack_segment 2 nmi 13 general_protection 3 int 3 14 page_fault 4 overflow 15 spurious_interrupt_bug 5 bounds 16 coprocessor_error 6 invalid_op 17 alignment_check 7 device_not_available 18 machine_check 8 double_fault 19 simd_coprocessor_error 9 coprocessor_segment_overrun 128 system_call 10 invalid_TSS The place for generating the top 1% software experts
start_kernel / trap_init() (2/4) IDT (Interrupt Descriptor Table)내 예외처리 handler int 0 (divide_error) DIV 명령어에 의한 나누기 에러 발생시 호출 int 1 (debug) single step 또는 debugging exception 예외 발생시 호출되는 함수는 arch/i 386/kernel/entry. S에서 찾을 수 있다. int 2 (nmi) Non-Maskable 인터럽트 발생시 int 3 byte breakpoint 명령어(0 x. CC)에 의해 발생 int 4 (overflow) OF flag가 설정되었을 때 발생 int 5 (bounds) bound 명령어 실행시 경계 초과에 의해 발생 int 6 (invalid_op) instruction 오류에 의해 발생 The place for generating the top 1% software experts
start_kernel / trap_init() (3/4) IDT (Interrupt Descriptor Table)내 예외처리 handler int 7 (device_not_available) coprocessor 부재 int 8 (double_fault) double fault에서 발생 int 9 (coprocessor_segment_overrun) 보호모드에서 coprocessor 명령어가 coprocessor에 전달될 때, page 또는 segment 침해에 발생 int 10 (invalid_TSS) task 전환 시 새로운 TSS가 타당하지 않을 때 발생 int 11 (segment_not_present) 보호 모드에서 로딩된 segment가 시스템에 존재하지 않을 때 발생 int 12 (stack_segment) 보호모드에서 stack segment 변경 시 limit violation에 의해 발생 int 13 (general_protection) 보호모드에서 심각한 에러가 감지되면 발생 The place for generating the top 1% software experts
start_kernel / trap_init() (4/4) IDT (Interrupt Descriptor Table)내 예외처리 handler int 14 (page_fault) paging system에서 page access error시 발생 int 15 (spurious_interrupt_bug) P 6 Local APIC Spurious Interrupt Bug 발생시 발생 (linux에서는 하는 일 없음) int 16 (coprocessor_error) coprocessor error에 의해 발생 int 17 (alignment_check) AC flag를 설정하였을 시 메모리 정렬 에러에 의해 발생 int 18 (machine_check) 시스템에 설치된 메모리 크기를 반환한다. (linux에서는 하는 일 없음) int 19 (simd_coprocessor_error) SIMD FPU 예외시 발생 int 128 (system_call) system call 요구 시 발생 The place for generating the top 1% software experts
start_kernel (4/10) init_IRQ() idt에 interrupt handler를 등록한다. IDT index 32번부터 시작하여 차례로 등록하고 등록된 IRQ는 시스템마다 다르나 보편적으로 i 386계열의 경우 32(IRQ 0)번은 timer, 33(IRQ 1)번 keyboard 순으로 등록된다. sched_init() 1. init_task의 processor를 설정한다. 2. pidhash table을 초기화 한다. 3. 프로그램 가능한 타이머 벡트를 작성한다. 4. 하반부 핸들러 루틴들을 셋팅한다. softirq_init() softirq를 설정한다. The place for generating the top 1% software experts
start_kernel (5/10) time_init() 1. 타임 퀀텀을 구함. 2. CPU clock을 구함. console_init() 1. tty_ldisc_N_TTY 자료구조를 정의하고 각 flag를 셋팅한다. 2. console_driver 자료 구조를 설정하고 device driver로 등록한다. 3. columns과 row를 참조하여 사용할 buffer size를 결정한다. 4. cursor 크기 및 깜빡임에 대한 설정을 한다. init_modules() kernel symbol table의 크기를 결정하여 kernel_module 구조체에 저장한다. profiling을 사용한다면 profile buffer를 활당한다. The place for generating the top 1% software experts
start_kernel (6/10) kmem_cache_init() slab 활당자를 위한 cache_cache 구조체의 값들을 셋팅한다. calibrate_delay() 보다 높은 정밀도의 delay를 위해 clock tick을 구하고 Bogo. MIPS를 구한다. mem_init() 1. empty_zero_page의 하드웨어 정보를 0으로 초기화 시킨다. 2. buddy system을 만들고, free page 수를 구하고, 사용하는 page 수 등을 출력한다. The place for generating the top 1% software experts
start_kernel / mem_init() buddy System 2^0 2^1 2^2 2^n 만큼 block size가 늘어남 2^3 2^4 2^5 2^6 2^7 2^8 2^9 The place for generating the top 1% software experts
start_kernel (7/10) kmem_cache_sizes_init() kernel cache 사이즈를 결정하고, slab table을 생성. pgtable_cache_init() PAE를 쓸 경우 “pae_pgd” object를 만들어 줌. fork_init() 시스템에서 생성할 수 있는 최대 thread 수를 구함 proc_caches_init() task_struct 에서 사용하는 자료구조들의 object를 만들어줌 files_cache, fs_cache, vm_area_struct, mm_struct The place for generating the top 1% software experts
start_kernel (8/10) vfs_caches_init() vfs에서 사용 할 cache의 object를 생성, dentry_cache object 생성, dentry 헤쉬 테이블의 크기를 계산해서 생성후 초기화 inode_cache object 생성, inode 헤쉬 테이블의 크기를 계산해서 생성후 초기화 메모리의 사이즈로 최대로 허용하는 file의 갯수를 결정 (총 메모리 양의 10%) rootfs를 마운트 하기 위해서 mnt, super_block, inode("/"), dentry("/"), dcache를 생성, 셋팅 bdev를 마운트 하기 위해서 mnt, super_block, inode("/"), dentry("/"), dcache를 생성, 셋팅 cdev 헤쉬 테이블을 초기화 하고 cdev_cache object를 생성 iobuf_cache object 생성 buffer_init() buffer cache hash table을 초기화한다. page_cache_init() page cache hash table을 초기화한다. The place for generating the top 1% software experts
start_kernel (9/10) signal_init() sigqueue object를 생성한다. proc_root_init() /proc 디렉토리에 파일과 디렉토리 및 sub 디렉토리 엔트리를 생성하고 셋팅 ipc_init() 128개의 세마포어 identifiers 테이블을 초기화, /proc/sysvipc/sem 생성 16개의 메시지 큐 identifiers 테이블을 초기화 , /proc/sysvipc/msg 생성 1개의 공유 메모리 identifiers 테이블을 초기화 , /proc/sysvipc/shm 생성 check_bugs() 현재까지 bug가 발생했는지 체크 화면에 “POSIX conformance testing by UNIFIX” 를 출력 The place for generating the top 1% software experts
start_kernel (10/10) smp_init() SMP 시스템이라면 관련 설정을 수행한다. rest_init() init kernel thread를 수행하고 kernel을 unlock하고 idle mode로 전환한다. The place for generating the top 1% software experts
init kernel thread (1/2) lock_kernel() SMP 시스템이라면 spin lock을 건다. do_basic_setup() 1. mtrr을 초기화하고 CPU에 따른 설정을 한다. 2. 각종 interface에 대한 초기화를 수행한다. PCI, SBUS, MCA, ECARD, NUBUS, ISA(Pn. P) 3. networking을 위한 object (“sock”)를 만들고 netlink를 위한 자료구조와 device file을 생성 4. “keventd” kernel thread 실행 5. kernel에 static으로 설정된 device driver들의 초기화 수행 6. Ir. DA 초기화 7. PCMCIA 초기화 The place for generating the top 1% software experts
init kernel thread (2/2) prepare_namespace() 1. /dev, /root, /dev/console등이 없다면 새로이 생성 2. devfs를 사용한다면 devfs를 /dev에 mount 3. initrd를 사용한다면 mount 4. root device mount free_initmem() 필요 없는 page를 반환한다. 1. console을 open한다. 2. dup() 시스템 콜로 표준 출력(1), 표준 에러(2)를 앞서 open한 console로 설정한다. 3. /sbin/init을 exec한다. The place for generating the top 1% software experts
init process (2/8) pstree ps -aux The place for generating the top 1% software experts
init process (3/8) /etc/inittab # 6 - reboot (Do NOT set initdefault to this) # id: 3: initdefault: /sbin/init은 /etc/inittab에 기술된 대로 스크립트를 실행하고 프로그램을 실행한다. # System initialization. 그래서 /etc/inittab를 분석하는 일은 init이 si: : sysinit: /etc/rc. d/rc. sysinit 하는 일을 분석하는 것과 같다. l 0: 0: wait: /etc/rc. d/rc l 1: 1: wait: /etc/rc. d/rc l 2: 2: wait: /etc/rc. d/rc l 3: 3: wait: /etc/rc. d/rc l 4: 4: wait: /etc/rc. d/rc l 5: 5: wait: /etc/rc. d/rc l 6: 6: wait: /etc/rc. d/rc 0 1 2 3 4 5 6 # Trap CTRL-ALT-DELETE ca: : ctrlaltdel: /sbin/shutdown -t 3 -r now 새로운 파티션 등록 pf: : powerfail: /sbin/shutdown -f -h +2 "Power Failure; System Shutting Down" pr: 12345: powerokwait: /sbin/shutdown -c "Power Restored; Shutdown Cancelled" The place for generating the top 1% software experts
init process (4/8) /etc/inittab # Run gettys in standard runlevels 1: 2345: respawn: /sbin/mingetty 1 2: 2345: respawn: /sbin/mingetty 2 3: 2345: respawn: /sbin/mingetty 3 4: 2345: respawn: /sbin/mingetty 4 5: 2345: respawn: /sbin/mingetty 5 6: 2345: respawn: /sbin/mingetty 6 # Run xdm in runlevel 5 x: 5: respawn: /etc/X 11/prefdm -nodaemon The place for generating the top 1% software experts
- Slides: 62