What is the difference between zImage and bzImage targets when compiling a kernel?
A. zImage is compressed using gzip, bzImage is compressed using bzip2
B. zImage is for 2.4 series kernels, bzImage is for 2.6 series kernels
C. zImage is loaded into low memory, bzImage is loaded into high memory
D. zImage is limited to 64k, bzImage is not
題解
zImage 是使用「gzip」來壓縮的 Linux Kernel Image,但 bzImage 並不是使用「bzip2」壓縮 Linux Kernel Image。bzImage 的「b」是「big」的意思,因此 bzImage 是指「big zImage」,顧名思義就是「大的 zImage」。之所以有 bzImage,是因為原先 zImage 的檔案大小上限是 512KiB,雖然很小,但在當年算是夠用。但隨著 Kernel 功能愈來愈多,zImage 的 512KiB 如今已經是遠遠不夠了。
這題所說的 low memory 和 high memory,是指開機時核心被載入的記憶體位置。x86 的電腦剛開機時處於真實模式(real mode),只能存取 1MiB 以下的記憶體,其中前 640KiB 就是 low memory,而 1MiB 以上的記憶體則為 high memory。zImage 會被完整地載入到 low memory 的空間(位址 0x10000 ~ 0x90000),所以才會有 512KiB 的大小限制。bzImage 則只有開機用的真實模式程式會放在 low memory,核心的主體會被載入到 high memory 的空間(從位址 0x100000,也就是 1MiB 的位置開始),所以沒有這個限制。
另外,Linux 核心在管理記憶體時也有 low memory 和 high memory 的說法,但意思和這題所說的不同。在 32 位元(x86)的 Linux 作業系統中,虛擬記憶體位址被切割為 3GiB 的使用者空間(0x00000000 - 0xBFFFFFFF)和 1GiB 的核心空間(0xC0000000 - 0xFFFFFFFF),核心空間實際上只會固定使用其中前 896MiB 的位址,後面的 128MiB 是保留的位址(用來映射到實體記憶體中的「high memory」部份)。實體記憶體中的前段記憶體空間「low memory」(即 16MiB 的 DMA Zone 和 880MiB 的 Normal Zone)是直接與核心空間位址的前 896MiB 連續對應的部份(當然,這邊的實體記憶體可能會比 896MiB 還要小,如果是這樣的話,核心空間位址的前 896MiB 就不會完全對應);而實體記憶體中的「high memory」(High Memory Zone)則是除了「low memory」之外的其餘的部份。
至於現在 64 位元(x86_64)的 Linux 作業系統,由於記憶體位址空間充足,就沒有再區分 low memory 和 high memory 了。但是虛擬記憶體位址的區段定義也複雜了許多,有興趣的話可以參考這份文件:
