編寫 Initial Script

From Jollen's Wiki

Jump to: navigation, search

根據 inittab 的設定,我們 root filesystem 的 init script 位於 /etc/rc.d/rc.init。以下提供一個供 Embedded Linux 使用的 init script 範本:

#!/bin/sh 
# automount (/etc/fstab)
mount -a 
# remount root
mount -o remount rw / 
#
mkdir /var/lock
mkdir /var/lock/subsys
mkdir /var/run
# start other applications (Running application automatically during
# booting up.
# eg. /bin/thttpd –p 80 –d /var/www

當我們執行「mount –a」後,mount 便會去讀取前一步驟所設定的 fstab,並根據此表格的內容來做 mount 的動作。另外,這裡有一個 remount 的動作:

# mount -o remount rw / 

此動作的目的是將 root(’/’)重新 mount 成可讀寫,此動作是選擇性的,若省略不做,請務必保持 /var 與 /tmp 目錄是能寫入的(建議以 ramdisk 方式實作為佳)。

若 root filesystem 未包含 inittab 設定檔,則 Busybox 會使用以下的內建設定:

::sysinit:/etc/init.d/rcS
::askfirst:/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
::restart:/sbin/init 

不過,還是建議編寫自己的 inittab 設定檔。



下一步:製作 Root Filesystem 映像檔(Image File)

Views
個人工具
導航
工具