2007年10月19日 星期五

Linux 系統裁減指南(LiPS) (繁體中文版) --(一)

Linux 系統裁減指南(LiPS)
Reference: http://grid.tsinghua.edu.cn/home/liulk/publish/computer/LinuxReduce.html


目 錄
1 引言 6
1.1 編寫目的 6
1.2 背景 6
1.3 定義 6
1.4 參考資料 6
2 總體描述 8
2.1 硬件環境 8
2.2 軟件環境 8
2.3 需求規定和約束 8
3 總體設計 9
3.1 基本設計概念 9
3.2 軟件結構 9
4 內核 10
4.1 創建內核的方法 10
4.2 內核配置 10
4.2.1 概述 10
4.2.2 Loadable module support 11
4.2.3 Processor type and features 11
4.2.4 General setup 12
4.2.5 Plug and Play configuration 12
4.2.6 Block devices 12
4.2.7 Multi-device support (RAID and LVM) 13
4.2.8 Networking options 13
4.2.9 ATA/IDE/MFM/RLL support 14
4.2.10 SCSI support 15
4.2.11 Network device support 15
4.2.12 Character devices 16
4.2.13 File systems 17
4.2.14 Console drivers 18
4.2.15 USB support 18
4.3 提示 19
4.3.1 EXTRAVERSION 19
4.3.2 .config 19
5 根文件系統 21
5.1 根文件系統 21
5.2 文件系統的內容 21
5.2.1 應用程序(applications) 21
5.2.2 設備文件(device files) 21
5.2.3 腳本和配置文件(scripts and configuration files) 22
5.2.4 庫文件(libraries) 23
5.2.5 必要的目錄 24
5.3 初始化RAM盤(initrd) 24
5.3.1 操作步驟 24
5.3.2 引導選項 24
5.3.3 安裝 25
5.3.4 改變根目錄設備 26
5.3.5 使用場合 27
5.3.6 淘汰的根轉換機制(change_root) 27
5.4 系統初始化(init) 27
5.4.1 init的任務 28
5.4.2 SysVinit 28
5.4.3 兩種風格:Slackware vs. Debian 28
5.5 PAM 29
5.5.1 什麼是PAM 29
5.5.2 PAM的結構 29
5.5.3 配置文件 29
5.5.4 other 29
5.6 再論initrd 30
5.6.1 根到底在哪裡 31
5.6.2 linuxrc 31
5.6.3 根轉換機制:新的?舊的? 32
5.7 提示 34
5.7.1 文件系統目錄層次結構 34
5.7.2 mklips.sh(製作LiPS的腳本) 34
5.7.3 lips.conf(LiPS配置文件) 34
5.7.4 cp –dpR 35
5.7.5 如何判斷一個程序依賴哪些文件 35
5.7.6 帶庫文件複製——lcp() 35
5.7.7 庫文件的命名 36
6 引導 38
6.1 引導過程概述 38
6.2 幾種引導方式 38
6.3 grub引導器 38
6.4 USB引導 38
6.4.1 製作步驟 39
6.5 提示 40
6.5.1 版本問題? 40
7 遠程串口控制台 41
7.1 概述 41
7.2 配置方法 41
7.3 提示 41
7.4 Linux 遠程串口控制台指南 41
8 系統安裝光盤 44
8.1 概述 44
8.2 boot.iso光盤的文件結構分析 44
8.3 製作步驟 45
9 源代碼(配置文件和腳本) 46
9.1 lips.conf 46
9.2 mklips.sh 46


1 引言

1.1 編寫目的
  說明Linux系統裁減的過程及解決的主要技術問題。本文檔的編寫是為了說明L
iPS的詳細設計過程,也可以作為構造一個小型化Linux系統的指南。
  本文檔內容的組織如下所述:這一部分是引言,第2部分是對項目軟、硬件環境
和需求的總體描述,第3部分說明了裁減LINUX的相關基本概念。後面幾個部分是具
體實現方法的詳細說明,4~6分別詳細描述了創建內核、創建根文件系統和引導系
統的方法。最後的內容可以看作附錄,其中7說明了一般Linux系統安裝光盤的創建
方法,8列出了相關的配置文件和源代碼。
1.2 背景
  華中科技大學計算機存儲系統國家專業實驗室,NAS項目(2003.3——2003.8)

1.3 定義
O boot loader: 引導器
O kernel: 內核
O root filesystem: 根文件系統
O USB: 通用串行總線
O
1.4 參考資料
[1] DIY:自己動手做一個迷你 Linux 系統. IBM developerWorks 中國網站. htt
p://www-900.ibm.com/developerWorks/cn/linux/embed/diy/index.shtml
[2] Linux From Scratch. http://clfsbook.mylab.idv.tw/index.html
[3] Linux啟動過程綜述. http://www.linuxaid.com.cn/forum/showdoc.jsp?l=1&
i=15750
[4] The Linux Bootdisk HOWTO (中譯版). http://www.linux.org.tw/CLDP/gb/B
ootdisk-HOWTO.html
[5] Using the initial RAM disk (initrd). /usr/src/linux-2.4/Documentatio
n/initrd.txt. (譯文?a href="Ghttp://zope.slat.org/Project/3ybaby/discuss-area/c" target="_blank">Ghttp://zope.slat.org/Project/3ybaby/discuss-area/c
d-boot/cdboot_refer/initrd.htm)
[6] Quickmouse於2003.1發表於白雲黃鶴BBS (http://bbs.whnet.edu.cn Linux討
論區的帖子「裁減Linux」。
[7] Filesystem Hierarchy Standard. http://www.pathname.com/fhs/pub/fhs-2
.2.pdf
[8] LINUX ALLOCATED DEVICES. /usr/src/linux-2.4/Documentation/device.txt
. 或者最新的列表?a href="bhttp://www.kernel.org/pub/linux/docs/device-list/" target="_blank">bhttp://www.kernel.org/pub/linux/docs/device-list/
[9] Karim Yaghmour. Building Embedded Linux Systems. O'Reilly, April 200
3.
[10] Alessandro Rubini. Take Command: Init. http://www.linux.it/kerneldo
cs/init/ , November 1998.
[11] 深入 Linux PAM 體系結構. IBM developerWorks 中國網站. http://www-90
0.ibm.com/developerWorks/cn/linux/l-pam/index.shtml . 2003.7.
[12]
  



2 總體描述

2.1 硬件環境
  開發主機:
  Intel 845芯片組主板,P4賽揚1.8GHz CPU,256M內存,60G IDE硬盤,RTL813
9網卡。
  目標機:
  與主機同構。
2.2 軟件環境
  開發主機:
  Redhat Linux 7.3 (kernel 2.4.18-3),或者Redhat Linux 9 (kernel 2.4.2
0-8)。可以根據需要使用其他版本的內核,比如Redhat 7.3+kernel 2.4.20。
  目標機:
  LiPS,以及應用程序。
2.3 需求規定和約束
  我們目標系統LiPS,即Linux Powered Storage是一個嵌入式Linux操作系統,
主要著眼於提供各種文件服務,不包括X GUI;並且足夠小,可以裝入32M USB盤或
者DOC/DOM等常用設備引導。
  



3 總體設計

3.1 基本設計概念
  提起「裁減Linux」,最容易想到的方法是以一個已經安裝好的系統為基礎,刪
除掉不需要的文件,以減小整個系統的尺寸。而事實上這個方法幾乎是行不通的,
因為通過光盤安裝的一個Redhat 9 Linux系統,即便是只選擇了比較少的軟件包,
其所佔空間也可以輕鬆達到300~500MB,想在這個基礎上裁減到30MB左右是比較困
難的。更困難的是確定哪些東西是可以刪除的?如果刪除了系統必須的文件,可能
導致系統不能引導。
  另一個途徑是從零開始根據需要構建整個系統。「Linux From Scratch」採用
的就是這種方式,一個個安裝需要的軟件包。類似的,更簡單的方法是,安裝一個
完整的Linux系統,然後將必要的軟件(可執行程序)、配置文件、庫文件、內核等
複製出來構建一個小系統。我們採取後一種方式。
  
3.2 軟件結構
  LiPS包括3部分:Linux內核,根文件系統和引導器。
  內核(Kernel)提供了一個操作系統的基本功能,如內存管理、進程調度、文
件系統、網絡等,以及設備驅動程序。
  根文件系統(Root filesystem)是存放運行、維護系統所必須的各種工具軟件
、庫文件、腳本、配置文件和其他特殊文件(比如設備節點)的地方,也可以安裝
各種軟件包。通常根文件系統位於某個磁盤分區,而在LiPS中應用了initrd(初始
RAM盤)機制,將根文件系統放在RAM Disk中。
  引導器(Boot Loader)的任務是從引導設備裝載內核,引導系統運行。Linux
系統常見的引導器包括早期的LILO和近期的GRUB。LiPS用的是GRUB。
  



4 內核

4.1 創建內核的方法
  Linux提供了方便靈活的方法來定製內核,主要步驟包括:下載安裝內核源代碼
樹,配置內核,編譯內核。具體方法請參考相關文檔。關鍵指令如下:
cd /usr/src/linux-2.4
make menuconfig
make dep; make clean; make bzImage
  編譯成功的內核文件為arch/i386/boot/bzImage.
4.2 內核配置
4.2.1 概述
  make menuconfig之後可以看到類似如下的內容(編號是為了描述方便而加上的
)。根據內核版本的不同,列出的項目會有差異。而變化主要發生在發行版為標準
內核打的各種補丁上面,其實標準內核是比較穩定的。
  如下所示,我們配置的內核版本為2.4.20-8,這個「-8」就是Redhat所打的補
丁版本號。補丁一般是對標準內核錯誤的修正和新增的功能。與2.4.20內核配置選
項比較會發現,[10,25,30]都屬於Redhat的補丁。
  一般地,這些補丁選項都不是必須的,因此我們的LiPS內核中都沒有包括這些
選項。其實,完全可以通過直接配置一個標準的內核版本(比如2.4.20)來產生我
們所需要的內核。
Linux Kernel v2.4.20-8-R2Lips Configuration
[1] Code maturity level options --->
[2] Loadable module support --->
[3] Processor type and features --->
[4] General setup --->
[5] Memory Technology Devices (MTD) --->
[6] Parallel port support --->
[7] Plug and Play configuration --->
[8] Block devices --->
[9] Multi-device support (RAID and LVM) --->
[10] Cryptography support (CryptoAPI) --->
[11] Networking options --->
[12] Telephony Support --->
[13] ATA/IDE/MFM/RLL support --->
[14] SCSI support --->
[15] Fusion MPT device support --->
[16] I2O device support --->
[17] Network device support --->
[18] Amateur Radio support --->
[19] IrDA (infrared) support --->
[20] ISDN subsystem --->
[21] Old CD-ROM drivers (not SCSI, not IDE) --->
[22] Input core support --->
[23] Character devices --->
[24] Multimedia devices --->
[25] Crypto Hardware support --->
[26] File systems --->
[27] Console drivers --->
[28] Sound --->
[29] USB support --->
[30] Additional device driver support --->
[31] Bluetooth support --->
[32] Kernel hacking --->
[33] Library routines --->
Load an Alternate Configuration File
Save Configuration to an Alternate File

  下面我們以2.4.20內核為例,來詳細說明內核的配置,也就是選哪些東西、不
選哪些東西。沒有說明的選項,比如「Code maturity level options」,表示不選

4.2.2 Loadable module support
Enable loadable module support
[ ] Set version information on all module symbols
Kernel module loader
  可加載模塊支持。雖然目前所選項目全部編譯進內核,但是內核是支持模塊的
。可以考慮將一些硬件設備的驅動程序編譯為模塊,從而減小內核尺寸,同時增加
適應不同硬件平台的靈活性。
4.2.3 Processor type and features
(Pentium-III/Celeron(Coppermine)) Processor family
Machine Check Exception
< > Toshiba Laptop support
< > Dell laptop support
< > /dev/cpu/microcode - Intel IA32 CPU microcode support
< > /dev/cpu/*/msr - Model-specific register support
< > /dev/cpu/*/cpuid - CPU information support
(off) High Memory Support
[ ] Math emulation
[ ] MTRR (Memory Type Range Register) support
[ ] Symmetric multi-processing support
[ ] Local APIC support on uniprocessors
[ ] Unsynced TSC support
  處理器特性。選擇一下Processor family,其餘基本上都沒有選。High Memor
y Support也可以打開,不清楚有什麼用。
4.2.4 General setup
Networking support
PCI support
(Any) PCI access mode
ISA bus support
PCI device name database
[ ] EISA support
[ ] MCA support
[ ] Support for hot-pluggable devices
System V IPC
BSD Process Accounting
Sysctl support
(ELF) Kernel core (/proc/kcore) format
< > Kernel support for a.out binaries
<*> Kernel support for ELF binaries
< > Kernel support for MISC binaries
Power Management support
< > Kernel support for MISC binaries
Power Management support
<*> Advanced Power Management BIOS support
Ignore USER SUSPEND
Enable PM at boot time
Make CPU Idle calls when idle
Enable console blanking using APM
RTC stores time in GMT
Allow interrupts during APM BIOS calls
Use real mode APM BIOS call to power off
  總體設置。這一部分選項比較重要,包括網絡、總線、進程、二進制文件格式
、電源管理等。其中APM相關的選項比較搞不清楚,有時候halt –p命令不能關閉系
統電源跟這裡有關係。
4.2.5 Plug and Play configuration
<*> Plug and Play support
< > ISA Plug and Play support
  即插即用設置。
4.2.6 Block devices
<*> Normal floppy disk support
< > XT hard disk support
< > Compaq SMART2 support
< > Compaq Smart Array 5xxx support
< > Mylex DAC960/DAC1100 PCI RAID Controller support
<*> Loopback device support
< > Network block device support
<*> RAM disk support
(4096) Default RAM disk size
Initial RAM disk (initrd) support
Per partition statistics in /proc/partitions
  塊設備。軟驅也可以不選。這裡的關鍵選項是Loopback device,RAM disk和i
nitrd,一定要選中。Default RAM disk size多少都沒有關係。
4.2.7 Multi-device support (RAID and LVM)
Multiple devices driver support (RAID and LVM)
<*> RAID support
<*> Linear (append) mode
<*> RAID-0 (striping) mode
<*> RAID-1 (mirroring) mode
<*> RAID-4/RAID-5 mode
<*> Multipath I/O support
<*> Logical volume manager (LVM) support
  MD支持。軟RAID和LVM的支持在這裡選擇,如果不使用,也可以不選。
4.2.8 Networking options
<*> Packet socket
Packet socket: mmapped IO
< > Netlink device emulation
Network packet filtering (replaces ipchains)
[ ] Network packet filtering debugging
Socket Filtering
<*> Unix domain sockets
TCP/IP networking
IP: multicasting
IP: advanced router
[ ] IP: policy routing
[ ] IP: equal cost multipath
[ ] IP: use TOS value as routing key
[ ] IP: verbose route monitoring
[ ] IP: large routing tables
IP: kernel level autoconfiguration
IP: DHCP support
IP: BOOTP support
IP: RARP support
<*> IP: tunneling
< > IP: GRE tunnels over IP
[ ] IP: multicast routing
[ ] IP: TCP Explicit Congestion Notification support
[ ] IP: TCP syncookie support (disabled per default)
IP: Netfilter Configuration --->
< > 802.1Q VLAN Support
---
< > The IPX protocol
< > Appletalk protocol support
Appletalk devices --->
< > DECnet Support
< > 802.1d Ethernet Bridging
QoS and/or fair queueing --->
Network testing --->
  網絡選項。這裡選項也比較多,如果沒有什麼特殊要求,又不是十分理解這些
選項的意義,基本上可以用缺省設置。注意DHCP選項,如果要用到的話要記得選中
這個。
  IP: Netfilter Configuration(跟iptables有關)等幾個子選項都沒有選。
4.2.9 ATA/IDE/MFM/RLL support
<*> ATA/IDE/MFM/RLL support
IDE, ATA and ATAPI Block devices --->
<*> Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support
--- Please see Documentation/ide.txt for help/info on IDE drives
[ ] Use old disk-only driver on primary interface
<*> Include IDE/ATA-2 DISK support
Use multi-mode by default
Auto-Geometry Resizing support
<*> Include IDE/ATAPI CDROM support
< > Include IDE/ATAPI TAPE support
< > Include IDE/ATAPI FLOPPY support
<*> SCSI emulation support
[ ] IDE Taskfile Access
--- IDE chipset support/bugfixes
[ ] CMD640 chipset bugfix/support
[ ] RZ1000 chipset bugfix/support
Generic PCI IDE chipset support
Sharing PCI IDE interrupts support
Generic PCI bus-master DMA support
[ ] Boot off-board chipsets first support
[ ] Force enable legacy 2.0.X HOSTS to use DMA
Use PCI DMA by default when available
[ ] Enable DMA only for disks
[ ] AEC62XX chipset support
[ ] ALI M15x3 chipset support
[ ] AMD Viper support
[ ] CMD64X and CMD680 chipset support
[ ] CY82C693 chipset support
[ ] Cyrix CS5530 MediaGX chipset support
[ ] HPT34X chipset support
[ ] HPT366/368/370 chipset support
Intel PIIXn chipsets support
PIIXn Tuning support
[ ] PROMISE PDC202{46|62|65|67|68|69|70} support
[ ] ServerWorks OSB4/CSB5 chipsets support
[ ] SiS5513 chipset support
[ ] SLC90E66 chipset support
[ ] VIA82CXXX chipset support
[ ] Other IDE chipset support
[ ] IGNORE word93 Validation BITS
  IDE設備支持。要用IDE硬盤,當然要選中。CDROM選項看情況也可以不要。SCS
I emulation似乎對使用USB盤有影響。剩下的很多都是跟IDE chipset有關的。
  最好是用dmesg命令找出目標系統主板芯片組,然後選中對應的芯片組支持,這
樣相當於安裝了IDE芯片組的驅動程序。如果沒有指定應該也可以,只是性能可能會
受到一些影響。
4.2.10 SCSI support
<*> SCSI support
--- SCSI support type (disk, tape, CD-ROM)
<*> SCSI disk support
(40) Maximum number of SCSI disks that can be loaded as modules
< > SCSI tape support
< > SCSI OnStream SC-x0 tape support
< > SCSI CD-ROM support
<*> SCSI generic support
--- Some SCSI devices (e.g. CD jukebox) support multiple LUNs
[ ] Enable extra checks in new queueing code
[ ] Probe all LUNs on each SCSI device
[ ] Verbose SCSI error reporting (kernel size +=12K)
[ ] SCSI logging facility
SCSI low-level drivers --->
  SCSI支持。如果要用到SCSI硬盤等SCSI設備,這裡當然要選。目前我們的目標
系統其實沒有SCSI硬盤,但是為了使用USB盤,也要選中SCSI支持。
  SCSI low-level drivers子選項中是一些SCSI卡,都不用選。
4.2.11 Network device support
Network device support
ARCnet devices --->
< > Dummy net driver support
< > Bonding driver support
< > EQL (serial line load balancing) support
< > Universal TUN/TAP device driver support
Ethernet (10 or 100Mbit) --->
Ethernet (10 or 100Mbit)
EISA, VLB, PCI and on board controllers
<*> EtherExpressPro/100 support (eepro100, original Becker driv
er
<*> RealTek RTL-8139 PCI Fast Ethernet Adapter support
Ethernet (1000 Mbit) --->
[ ] FDDI driver support
< > PPP (point-to-point protocol) support
< > SLIP (serial line) support
Wireless LAN (non-hamradio) --->
Token Ring devices --->
[ ] Fibre Channel driver support
Wan interfaces --->
  網絡設備支持。主要選擇網卡類型,Ethernet (10 or 100Mbit)子選項中列出
了內核可以支持的10/100M以太網卡,這裡僅列出了我們選中的2種。其他子選項都
沒有選。
4.2.12 Character devices
Virtual terminal
Support for console on virtual terminal
<*> Standard/generic (8250/16550 and compatible UARTs) serial suppo
rt
Support for console on serial port
[ ] Extended dumb serial driver options
[ ] Non-standard serial port support
[ ] Unix98 PTY support
I2C support --->
Mice --->
Joysticks --->
< > QIC-02 tape support
Watchdog Cards --->
< > AMD 768 Random Number Generator support
< > Intel i8x0 Random Number Generator support
< > AMD 76x native power management (Experimental)
< > /dev/nvram support
< > Enhanced Real Time Clock Support
< > Double Talk PC internal speech card support
< > Siemens R3964 line discipline
< > Applicom intelligent fieldbus card support
Ftape, the floppy tape device driver --->
< > /dev/agpgart (AGP Support)
[ ] Direct Rendering Manager (XFree86 DRI support)
< > ACP Modem (Mwave) support
  字符設備。這裡主要就是選擇了最前面4個跟終端和串口有關的選項,以支持虛
擬終端(遠程登錄要用到),支持標準串口,支持串口控制台。
4.2.13 File systems
Quota support
< > Kernel automounter support
<*> Kernel automounter version 4 support (also supports v3)
<*> Reiserfs support
[ ] Enable reiserfs debug mode
Stats in /proc/fs/reiserfs
<*> Ext3 journalling file system support
[ ] JBD (ext3) debugging support
<*> DOS FAT fs support
<*> MSDOS fs support
< > UMSDOS: Unix-like file system on top of standard MSDOS fs
<*> VFAT (Windows-95) fs support
< > Compressed ROM file system support
Virtual memory file system support (former shm fs)
<*> ISO 9660 CDROM file system support
Microsoft Joliet CDROM extensions
[ ] Transparent decompression extension
< > JFS filesystem support
< > Minix fs support
< > FreeVxFS file system support (VERITAS VxFS(TM) compatible)
< > NTFS file system support (read only)
< > OS/2 HPFS file system support
/proc file system support
< > QNX4 file system support (read only)
< > ROM file system support
<*> Second extended fs support
< > System V/Xenix/V7/Coherent file system support
< > UDF file system support (read only)
< > UFS file system support (read only)
Network File Systems --->
< > Coda file system support (advanced network fs)
<*> NFS file system support
Provide NFSv3 client support
[ ] Root file system on NFS
<*> NFS server support
Provide NFSv3 server support
<*> SMB file system support (to mount Windows shares etc.)
[ ] Use a default NLS
< > NCP file system support (to mount NetWare volumes)
Partition Types --->
Native Language Support --->
Default NLS Option: "iso8859-1"
<*> Codepage 437 (United States, Canada)
<*> Simplified Chinese charset (CP936, GB2312)
<*> Traditional Chinese charset (Big5)
  文件系統。這部分內容比較多,也很重要。首先是Quota,如果目標系統支持這
個功能,這裡就要選中。然後是選擇要支持的文件系統,常用的有Reiserfs,Ext3
,FAT,ISO9660,JFS等等,可以根據情況選擇。/proc和ext2一定要選中。
  還有Network File Systems子選項,可以選擇是否支持NFS和SMB。Native Lan
guage Support子選項跟所支持的語言有關,這裡沒有全部列出來,我們選中了英語
和簡體、繁體中文字符集。
4.2.14 Console drivers
VGA text console
[ ] Video mode selection support
  控制台驅動。調試的時候可以給目標系統接顯示器看一下,實際系統應該可以
不選。
4.2.15 USB support
<*> Support for USB
[ ] USB verbose debug messages
--- Miscellaneous USB options
Preliminary USB device filesystem
[ ] Long timeout for slow-responding devices (some MGE Ellipse UP
Se
--- USB Host Controller Drivers
<*> UHCI Alternate Driver (JE) support
<*> OHCI (Compaq, iMacs, OPTi, SiS, ALi, ...) support
--- USB Device Class drivers
< > USB MIDI support
<*> USB Mass Storage support
USB Mass Storage verbose debug
[ ] Freecom USB/ATAPI Bridge support
[ ] ISD-200 USB/ATA Bridge support
[ ] Microtech CompactFlash/SmartMedia support
< > USB Modem (CDC ACM) support
< > USB Printer support
--- USB Human Interface Devices (HID)
<*> USB Human Interface Device (full HID) support
--- Input core support is needed for USB HID input layer or HID
BP
[ ] /dev/hiddev raw HID device support
--- USB Imaging devices
< > USB Kodak DC-2xx Camera support
< > USB Scanner support
< > Microtek X6USB scanner support
--- USB Multimedia devices
--- Video4Linux support is needed for USB Multimedia device suppo
rt
--- USB Network adaptors
--- USB port drivers
USB Serial Converter support --->
--- USB Miscellaneous drivers
< > Texas Instruments Graph Link USB (aka SilverLink) cable suppo
rt
< > USB LCD device support
  USB支持。如果沒有使用USB設備,這部分可以不選。要使用USB盤,一定要選中
USB Mass Storage support。其餘很多選項我也不清楚是干什麼用的。
4.3 提示
4.3.1 EXTRAVERSION
  在系統中使用uname可以獲得系統版本信息。比如Redhat 9:
[root@lips root]# uname -r
2.4.20-8
[root@lips root]#
  返回結果表示了Redhat修訂後的內核版本號。前面我們提到過,這個「-8」就
是Redhat附加在標準內核版本號後面的一個信息。
  在一個運行LiPS的系統中,我們也需要確定當前使用的內核版本,通過版本信
息來知道這個內核的配置,也可以通過在標準內核版本後面附加特定的編碼來實現

  /usr/src/linux-2.4/Makefile中的變量EXTRAVERSION可以幫助我們達到這個目
標。下面是Makefile文件的最前面幾行內容:
VERSION = 2
PATCHLEVEL = 4
SUBLEVEL = 20
EXTRAVERSION = -8
KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
  現在KERNELRELEASE的值就是2.4.20-8。這個信息會被編譯到內核中,uname工
具會從內核文件中提取出版本號。如果將Makefile做一些修改,比如,
EXTRAVERSION = -8-R2Lips
  那麼我們可以得到內核版本號2.4.20-8-R2Lips,表示為了創建LiPS而編譯的一
個特定配置的內核,這個內核是以2.4.20-8為基礎,R2Lips(Release 2 Lips)即
第二個版本。
  對Makefile的修改要在編譯內核之前完成。
4.3.2 .config
  內核配置(make menuconfig)完成之後,會詢問:
Do you wish to save your new kernel configuration?
< Yes > < No >
  回答Yes,配置信息會保存在/usr/src/linux-2.4/.config文件中。注意以「.
」開頭的文件是個隱藏文件,要用ls –a才看的到。.config是個文本文件,內容類
似下面:
#
# Loadable module support
#
CONFIG_MODULES=y
# CONFIG_MODVERSIONS is not set
CONFIG_KMOD=y
  所以可以把這個文件保存起來,並且給文件名帶上版本號,方便管理、使用。

cp .config ~/config-2.4.20-8-R2Lips

1 則留言:

Priya Kannan 提到...

Usually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Great work admin.Keep update more blog.
UNIX Training in Chennai