回文章列表
作者JohnLinq.bbs@ptt.cc (林約翰) 看板: linux
標題Re: [問題] Kernel與root-filesystem的關係是怎樣的?
時間批踢踢實業 (2008/03/28 Fri 17:51:37)
我對技術方面的東西懂得不多,
所以我對jserv前輩的回文只能夠理解一小部份,
我把我目前理解到的一小部份寫在這裡,希望大家不要見笑/不要介意。
也期待諸位前輩賢達的補充與指正。

(我以下將會引用的某份資料可能很舊了,希望大家不要見笑/不要介意。)

※ 引述《jserv.bbs@bbs.sayya.org (松鼠)》之銘言:
: ※ 引述《JohnLinq.bbs@ptt.cc (林約翰)》之銘言:
: > 這樣是不是表示說Kernel跟root-filesystem可以隨意混合搭配呢?
: 這個問題的答案是 "Yes and No"
: Linux kernel 屬於典型的作業系統核心設計,提供若干 system calls,而 C 語言
: 既然是這類 UNIX-like 的系統的母語,在上層的 application (userspace) 透過
: Standard C Library 的 function wrapper 將函式對應成底層的系統呼叫序列。
: 所以問題就在於,上、下層的系統呼叫是否匹配。以 GNU glibc 來說,花了很多

http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html

 --with-headers=/tools/include

    This tells Glibc to compile itself against the headers recently installed
to the tools directory, so that it knows exactly what features the kernel has
and can optimize itself accordingly.

編譯Glibc的時候需要kernel-headers
也就是說 UserSpace App -> Glibc -> System Call -> Kernel
Glibc與Kernel匹配的關鍵就在於編譯Glibc時所用的kernel-headers

: 心力在作 linux kernel 不同版本間的相容性匹配處理,以確保絕大部分的應用程式
: 能與 kernel version 無關 (像是 2.4 <-> 2.6 kernel),但多少還是會有些微的
: 技術問題。

    可是像我用Kernel 2.4的Library配Kernel 2.6的核心,
    那麼舊Library如何知道新核心的長相並與其相容呢?

: root filesystem 當然得提供以上關鍵元件,如果採用 C 語言作為母語。至於說
: 直接使用 assembly 去建構系統 (如 AsmUtil),那要注意到 system call 的處理
: 模式。
: > Kernel是不需要Library而能夠獨立運作的。(沒錯吧?)
: Kernel 基本上是 static link 的,先不談 kernel module。

http://www.win.tue.nl/~aeb/linux/lk/lk-2.html

2.7 The C code

The Linux kernel is written in C, and compiled by gcc. Various gcc extensions
are used, so it is not easy to use a different compiler. A few
architecture-specific fragments are in assembler.

The code is self-contained, no library is linked in. In particular, standard
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
routines like printf() are not available. (But there is printk() that does
more or less the same.) However, the kernel has its own library, and things
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
like strcpy() exist.

: > Kernel主動跟外界溝通的方式(主動去叫別人作事),是呼叫程式名稱嗎?
: > Kernel被動跟外界溝通的方式(被別人叫來作事),是通過Kernel API溝通是嗎?
: 所謂的 kernel API 其實包含兩個層面,一個是 C style function call,另一個

Kernel主動去叫別人作事,就是透過"C style function call"嗎?
長得像下面這個例子這樣嗎?
execve("/sbin/hello", argv_init, envp_init);

http://www.win.tue.nl/~aeb/linux/lk/lk-3.html

If one wants to play with this, find kernel 2.5.64 and apply the above klibc
patch. It contains a usr/root/hello.c program, that however is never invoked.
Add an invocation in init/main.c before the prepare_namespace(), e.g.,

        unlock_kernel();
        system_running = 1;

        execve("/sbin/hello", argv_init, envp_init);

        prepare_namespace();
        if (open("/dev/console", O_RDWR, 0) < 0) ...

: 是 system call,端看從哪個角度來看。
: 小弟以前整理的 slides 與 hacking,可參考:
:     http://jserv.sayya.org/helloworld/
: 這是從 "Hello World!" 等級的小程式去探討 Linux 的系統設計。


--
※ 發信站: 批踢踢實業坊(ptt.cc) 
◆ From: 211.72.242.40
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻