Linux的各種發(fā)行版在啟動(dòng)時(shí)基本上都有兩種模式:silent mode和verbose mode。verbose模式下會(huì)打印極為詳盡的啟動(dòng)信息,比如掛載文件系統(tǒng),加載光驅(qū),激活網(wǎng)絡(luò)服務(wù)等等,而silent模式則屏蔽掉這些信息。bootsplash工具可以將一張圖片放在silent模式下的虛擬控制臺(tái)上,從而使Linux用戶看到一個(gè)全畫面的啟動(dòng)過(guò)程。另外一個(gè)工具是gensplash,比bootsplash要稍微復(fù)雜一些,不過(guò)功能更為強(qiáng)大,設(shè)計(jì)也更為合理——它將一些非必要的元素從kernel space挪出來(lái),放在user space來(lái)做。
網(wǎng)絡(luò)上關(guān)于bootsplash(啟動(dòng)動(dòng)畫)的使用基本上是基于Linux的SuSe發(fā)行版進(jìn)行討論的——開發(fā)這組工具的作者說(shuō)他們的工作平臺(tái)是SuSe。gensplash則是基于Linux的Gentoo發(fā)行版進(jìn)行討論的。當(dāng)然這些兩組工具都可以通過(guò)適當(dāng)?shù)母膭?dòng)應(yīng)用于Linux的其它發(fā)行版。
由于我的工作平臺(tái)是red hat linux,此篇文章就討論怎樣在RH linux下使用bootsplash。下面先給出相關(guān)的一些網(wǎng)站:
http://www.bootsplash.org (官方網(wǎng)站,基本使用及相關(guān)原理)
http://www.bootsplash.com (詳盡的使用方法,基于SuSe發(fā)行版)
http://www.bootsplash.de (bootsplash的愛(ài)好者組織的網(wǎng)站,資料齊全)
http://www.kernel.org (Linux內(nèi)核下載)
本文嚴(yán)重參考http://www.linuxhall.org/modules.php?name=News&file=article&sid=201,哈哈,特此說(shuō)明。
現(xiàn)在我們進(jìn)入正題。
http://www.bootsplash.org網(wǎng)站上說(shuō),bootsplash的內(nèi)核補(bǔ)丁針對(duì)2.4.18--2.4.22和2.6.0-test9,這個(gè)消息很舊了,可以到http://www.bootsplash.de站點(diǎn)查看bootsplash所提供的各個(gè)版本的內(nèi)核補(bǔ)丁,然后確定你所用的Linux內(nèi)核版本,選擇一個(gè)補(bǔ)丁下載。
我的內(nèi)核是2.4.20-8,下載補(bǔ)丁bootsplash-3.0.7-2.4.20.vanilla.diff。補(bǔ)丁中的3.0.7是bootsplash工具的版本號(hào),我們下載bootsplash-3.0.7.tar.bz2,再下載所要用的主題Theme-NewLinux.tar.bz2,關(guān)于材料的準(zhǔn)備就完成了。這些都可以在上面的提及的網(wǎng)站上找到。如果你的內(nèi)核沒(méi)有相應(yīng)補(bǔ)丁,那么可以選擇一個(gè)版本的內(nèi)核源代碼,打上補(bǔ)丁后,編譯一個(gè)新的內(nèi)核。
如果沒(méi)有編譯過(guò)內(nèi)核,可以到網(wǎng)上查找相關(guān)資料,對(duì)照著練習(xí)一下。當(dāng)然,我們需要root的權(quán)限。
第一步 修改/usr/include目錄下的三個(gè)符號(hào)鏈接:asm,scsi,linux(mv asm asm.bak,mv scsi scsi.bak,mv linux linux.bak),如果沒(méi)有,則要新建。在編譯內(nèi)核時(shí),用到這些鏈接所指向的一些頭文件。我在/usr/src目錄下建了一個(gè)名為linux的鏈接指向同一層的內(nèi)核源代碼目錄linux-2.4.20-8(這樣以后再編譯不同版本內(nèi)核時(shí),只需修改/usr/src目錄下的linux符號(hào)鏈接就可以了)。(命令ln -s linux-2.4.20-8 linux),然后進(jìn)入/usr/include目錄,分別執(zhí)行l(wèi)n -s /usr/src/linux/include/asm-i386 asm;ln -s /usr/src/linux/include/linux linux;ln -s /usr/src/linux/include/scsi scsi。
第二步 打補(bǔ)丁,假設(shè)補(bǔ)丁在/usr/src/linux目錄下(不在的話加上路徑即可)。patch -p1<bootsplash-3.0.7-2.4.20.vanilla.diff
第三步 設(shè)定核心:make menuconfig。確定下列選項(xiàng)被編譯進(jìn)內(nèi)核而不是被編譯成模塊。
對(duì)于2.4.x內(nèi)核:
Code maturity level options ---> [*] Prompt for development and/or incomplete code/drivers Processor type and features ---> [*] MTRR (Memory Type Range Register) support Block Devices -> [*] Loopback device support [*] RAM disk support (4096) Default RAM disk size [*] Initial RAM disk (initrd) support Console Drivers -> [*] VGA text console [*] Video mode selection support Console Drivers -> Frame-buffer support -> [*] Support for frame buffer devices [*] VESA VGA graphics console [*] Use splash screen instead of boot logo
對(duì)于2.6.x內(nèi)核: Code maturity level options ---> [*] Prompt for development and/or incomplete code/drivers Processor type and features ---> [*] MTRR (Memory Type Range Register) support Device Drivers ---> Block devices ---> <*> Loopback device support <*> RAM disk support (4096) Default RAM disk size [*] Initial RAM disk (initrd) support Graphics support ---> [*] Support for frame buffer devices [*] VESA VGA graphics support Console display driver support ---> [*] Video mode selection support <*> Framebuffer Console support Bootsplash configuration ---> [*] Bootup splash screen |
第四步
a> make mkproper 清除舊的設(shè)定 b> make dep 產(chǎn)生依賴 c> make bzImage 編譯內(nèi)核 d> make modules modules_install 編譯模塊 e> cp /usr/src/linux/arch/i386/boot/bzImage /boot/bzImage-2.4.20 |
第五步 安裝bootsplash的工具軟件和主題圖片
# tar jxvf /patch/bootsplash-3.0.7.tar.bz2 # tar jxvf /patch/Theme-NewLinux.tar.bz2 # cd bootsplash-3.0.7/Utilities # make all # cp fbmngplay fbresolution fbtruetype splash /sbin # cd ../../ |
下面這幾步必須要做,不然在用splash命令時(shí)就會(huì)出現(xiàn)類似下面的錯(cuò)誤:splash:/etc/bootsplash/
themes/Linux/images/silent-800x600.jpg不存在。這個(gè)其實(shí)是由于主題的配置文件中做了絕對(duì)路徑設(shè)定。
# mkdir /etc/bootsplash # mkdir /etc/bootsplash/themes # cp -a NewLinux /etc/bootsplash/themes/ |
我們來(lái)看一個(gè)完整的主題配置文件,以800x600分辨率為例,文件名為bootsplash-800x600.cfg,可以用vi進(jìn)行編輯,####開頭的為筆者加的注釋。
[/code:1:7b9eb010fc] [code:1:7b9eb010fc] # This is the configuration file for the 800x600 bootsplash picture. # # This file is necessary to specify the coordinates of the text box on # the splash screen. # # Comments are welcome by oliver@dediziert.org
# config file version version=3
# should the picture be displayed? state=1
# fgcolor is the text forground color. # bgcolor is the text background (i.e. transparent) color. fgcolor=7 bgcolor=0
# (tx, ty) are the (x, y) coordinates of the text window in pixels. # tw/th is the width/height of the text window in pixels. tx=0 ty=0 tw=800 th=600
####predefine area for the text info text_x=260 text_y=545 text_size=20 text_color=0xeef4ff ####
# name of the picture file (full path recommended) jpeg=/etc/bootsplash/themes/NewLinux/images/bootsplash-800x600.jpg silentjpeg=/etc/bootsplash/themes/NewLinux/images/silent-800x600.jpg
progress_enable=1
# background box silent noover 160 520 642 538 #00000050 box silent inter 160 520 160 537 #b77200 #b77200 #f2b700 #f2b700 box silent 160 520 642 538 #b77200 #b77200 #f2b700 #f2b700
# black border box silent 160 520 642 520 #b5b5b5 box silent 160 538 642 538 #b5b5b5 box silent 160 520 160 538 #b5b5b5 box silent 642 520 642 538 #b5b5b5
overpaintok=1 [/code:1:7b9eb010fc] |
我們可以修改這個(gè)文件中的一些選項(xiàng)來(lái)得到自己想要的效果。具體選項(xiàng)的含義可以查看:
http://www.bootsplash.org/config.html # name of the picture file (full path recommended) jpeg=/etc/bootsplash/themes/NewLinux/images/bootsplash-800x600.jpg silentjpeg=/etc/bootsplash/themes/NewLinux/images/silent-800x600.jpg |
這兩行指定了作為啟動(dòng)動(dòng)畫的圖片和控制臺(tái)背景的圖片的名字和絕對(duì)路徑,我們只需把自己制作的圖片命名為這里指定的圖片,并且放在這個(gè)路徑下,就可以應(yīng)用自己的主題了。(想想看,制作themes是相當(dāng)簡(jiǎn)單的。不明白為什么網(wǎng)上沒(méi)有redhat linux的主題圖片。)
我修改了/etc/bootsplash/themes/NewLinux/config/bootsplash-800x600.cfg文件,定義顯示文本信息區(qū)域。###部分是我添加的內(nèi)容。
[code:1:7b9eb010fc]
第六步 將圖片與 init Ram Disk 綁定 splash -s -f /etc/bootsplash/themes/Linux/config/bootsplash-800x600.cfg > /boot/initrd-splash.img 對(duì)于ide硬盤,我們可以直接用splash工具生成initrd*.img文件,這個(gè)文件對(duì)ide硬盤來(lái)說(shuō)沒(méi)什么用,我們?cè)谶@里只是通過(guò)它來(lái)使用啟動(dòng)畫面。
如果你只想看到一副靜態(tài)的畫面,跳過(guò)第七步,看第八步,不用修改腳本文件。
第七步> 將腳本splash.sh拷入/etc/rc.d/下,并修改splash.sh和rc,建議在修改rc腳本文件前進(jìn)行備份(cp rc rc.bak)
# cp bootsplash-3.0.7/Scripts/splash.sh/etc/rc.d
下面來(lái)看完整的splash.sh腳本文件,要想這個(gè)腳本起作用,必須修改rc腳本,通過(guò)rc腳本調(diào)用splash.sh腳本,需要賦予splash.sh腳本可執(zhí)行權(quán)限。需要一些shell script的知識(shí)。網(wǎng)上很多,google吧。
我現(xiàn)在的/etc/rc.d/splash.sh腳本,刪除了原來(lái)放在這個(gè)腳本中的繪制進(jìn)度條部分(調(diào)試不成功)和播放動(dòng)畫部分(還沒(méi)有實(shí)驗(yàn)),以及不適用于red hat linux的一些命令。這個(gè)腳本現(xiàn)在只打印類似“booting the system"和"shutting down the system"的信息和實(shí)現(xiàn)關(guān)機(jī)時(shí)的silent mode。
#!/bin/bash # # splash.sh - This shell script triggers bootsplash actions during # system boot/shutdown. It can be run by the init scripts repeatedly # specifying the currently executed system script. # #rewrite this script at the base of offered by http://www.bootsplash.org #line with ### added by me
_procsplash="`cat /proc/splash 2>/dev/null`"
###give the variable "THEME" the name of the directory which the current ###silent mode picture stored THEME="NewLinux"
test ! -d "/etc/bootsplash/themes/$THEME" && exit 0
# assertions test -r /proc/splash || exit 0 test -z "`echo $_procsplash|grep on`" && exit 0
####"Yast" is a utilies for SuSE Linux,no for RedHat Linux ####maybe we can erase it test "$1" == "bootnetwork stop" -o "$1" == "YaST" && exit 0 # no progress
# We chose verbose in grub test "`cat /proc/cmdline |grep \"splash=silent\"`" == "" && exit 0
if [ "$PREVLEVEL" == "3" -o "$PREVLEVEL" == "5" ]; then ###no below ,no silent mode when shutting down if [ "$RUNLEVEL" = "3" -o "$RUNLEVEL" == "5" ]; then exit 0 fi ### but why ? fi
# acquire data # _shutdown="no" _silent="no" test "`cat /proc/splash |grep silent`" && _silent="yes" test "$RUNLEVEL" == "6" -o "$RUNLEVEL" == "0" && _shutdown="yes"
test -f "/etc/bootsplash/themes/$THEME/config/bootsplash-`fbresolution`.cfg" && \ . /etc/bootsplash/themes/$THEME/config/bootsplash-`fbresolution`.cfg
# # Print text string. (Booting/Shutting down the system. Press # F2 for verbose mode) # ###switch to slient mode when shutdown or reboot the system test "$_shutdown" == "yes" && ( echo "silent" >/proc/splash; chvt 1)
###print infomation at the area predifined by config file "bootsplash-800x600.cfg" _boot="Booting"; test "$_shutdown" == "yes" && _boot="Shutting down"
###is the area for infomation defined? yes ,print info, no,run on if [ "$text_x" != "" -a "$text_y" != "" \ -a "$text_color" != "" -a "$text_size" != "" -a "$_silent" == "yes" ]; then fbtruetype -x $text_x -y $text_y -t $text_color -s $text_size \ "$_boot the system ..." fi
[/code:1:7b9eb010fc] |
下面來(lái)看rc腳本(此為系統(tǒng)腳本,決定runlevel和kill or start services,修改前要備份一下,到時(shí)要改回來(lái)只要覆蓋一下就好了cp rc.bak rc)。下面是我現(xiàn)在的/etc/rc.d/rc腳本,定義一個(gè)函數(shù),for循環(huán)中調(diào)用它,以繪制啟動(dòng)進(jìn)度。重新寫了幾行代碼,繪制進(jìn)度條。以運(yùn)行級(jí)下的服務(wù)總個(gè)數(shù)和已經(jīng)啟動(dòng)的服務(wù)個(gè)數(shù)之比作為progress bar的進(jìn)度,這樣進(jìn)度條顯得均勻了一些。
現(xiàn)在這個(gè)可以實(shí)現(xiàn)以下功能,開機(jī)silent模式,有開始畫面,有進(jìn)度條,進(jìn)度條下有booting system 提示。關(guān)機(jī)時(shí)切換到silent模式,有畫面。提示shutting down the system.
不過(guò)在開機(jī)的時(shí)候,有一半時(shí)間進(jìn)度條是空的(系統(tǒng)在加載內(nèi)核,檢測(cè)硬件),在關(guān)機(jī)的時(shí)候,進(jìn)度條一下子就滿了,然后又變空,直到關(guān)機(jī)。呵呵,回頭再改,告一段落了先。
[code:1:7b9eb010fc] #! /bin/bash # # rc This file is responsible for starting/stopping # services when the runlevel changes. # # Original Author: # Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org> #
# check a file to be a correct runlevel script
###########################Bootsplash start############## ####function progressbar function progressbar () { _progress=$1 _num=$num echo show "$(( 65534*($_progress + 1)/$_num ))">/proc/splash 2>/dev/null } ####end fuction ##########################Bootsplash End############### check_runlevel () { # Check if the file exists at all. [ -x "$1" ] || return 1
# Reject backup files and files generated by rpm. case "$1" in *.rpmsave|*.rpmorig|*.rpmnew|*~|*.orig) return 1 ;; esac return 0 }
# Now find out what the current and what the previous runlevel are. argv1="$1" set `/sbin/runlevel` runlevel=$2 previous=$1 export runlevel previous
. /etc/init.d/functions
# See if we want to be in user confirmation mode if [ "$previous" = "N" ]; then if [ -f /var/run/confirm ] \ || grep -i confirm /proc/cmdline >/dev/null; then rm -f /var/run/confirm CONFIRM=yes export CONFIRM echo $"Entering interactive startup" else echo $"Entering non-interactive startup" fi fi
# Get first argument. Set new runlevel to this argument. [ -n "$argv1" ] && runlevel="$argv1"
####################Bootsplash start############### progress=0 num=0 ###count the services for progressbar for countservices in /etc/rc$runlevel.d/*;do num=$(( $num + 1 )) done ###################Bootsplash End##################
# Is there an rc directory for this new runlevel? [ -d /etc/rc$runlevel.d ] || exit 0
# First, run the KILL scripts. for i in /etc/rc$runlevel.d/K*; do ###################Bootsplash start################# progress=$(( $progress + 1 )) /etc/rc.d/splash.sh 2>/dev/null progressbar $progress ##################Bootsplash End#################### check_runlevel "$i" || continue
# Check if the subsystem is already up. subsys=${i#/etc/rc$runlevel.d/K??} [ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \ || continue
# Bring the subsystem down. if egrep -q "(killproc |action )" $i; then $i stop else action $"Stopping $subsys: " $i stop fi done
# Now run the START scripts. for i in /etc/rc$runlevel.d/S*; do ###################Bootsplash start################# progress=$(( $progress + 1 )) /etc/rc.d/splash.sh 2>/dev/null progressbar $progress ##################Bootsplash End#################### check_runlevel "$i" || continue
# Check if the subsystem is already up. subsys=${i#/etc/rc$runlevel.d/S??} [ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \ && continue # If we’re in confirmation mode, get user confirmation if [ -n "$CONFIRM" ]; then confirm $subsys case $? in 0) :;; 2) CONFIRM=;; *) continue;; esac fi
# Bring the subsystem up. if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then export LC_ALL=C exec $i start fi if egrep -q "(daemon |action |success |failure )" $i 2>/dev/null \ || [ "$subsys" = "single" -o "$subsys" = "local" ]; then $i start else action $"Starting $subsys: " $i start fi done [/code:1:7b9eb010fc] [code:1:7b9eb010fc] |
第八步 修改(bootloader) grub(或者lilo)。我用的是grub,硬盤是ide的。只列出需要修改的部分。我的硬盤分區(qū)swap,boot,/。
title Red Hat Linux (2.4.20+bootsplash) root (hd0,0) kernel /bzImage-2.4.20 ro root=/dev/hda3 vga=788 splash=silent initrd /initrd-splash.img title Red Hat Linux (2.4.23) root (hd0,0) kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ initrd /initrd-2.4.20-8.img |
788為800x600模式,791為1024x768模式。這里的模式選擇要與圖片的大小一致。
到這里就可以重新啟動(dòng)了。呵呵,大功告成。趕緊實(shí)驗(yàn)一下,享受自己的全畫面Linux啟動(dòng)吧。