歡迎您光臨本站 註冊首頁

用bootsplash製作Linux全圖形啟動界面

←手機掃碼閱讀     火星人 @ 2014-03-24 , reply:0

  Linux的各種發行版在啟動時基本上都有兩種模式:silent mode和verbose mode。verbose模式下會列印極為詳盡的啟動信息,比如掛載文件系統,載入光碟機,激活網路服務等等,而silent模式則屏蔽掉這些信息。bootsplash工具可以將一張圖片放在silent模式下的虛擬控制台上,從而使Linux用戶看到一個全畫面的啟動過程。另外一個工具是gensplash,比bootsplash要稍微複雜一些,不過功能更為強大,設計也更為合理——它將一些非必要的元素從kernel space挪出來,放在user space來做。
  網路上關於bootsplash(啟動動畫)的使用基本上是基於Linux的SuSe發行版進行討論的——開發這組工具的作者說他們的工作平台是SuSe。gensplash則是基於Linux的Gentoo發行版進行討論的。當然這些兩組工具都可以通過適當的改動應用於Linux的其它發行版。

  由於我的工作平台是red hat linux,此篇文章就討論怎樣在RH linux下使用bootsplash。下面先給出相關的一些網站:

  http://www.bootsplash.org (官方網站,基本使用及相關原理)
  http://www.bootsplash.com (詳盡的使用方法,基於SuSe發行版)
  http://www.bootsplash.de (bootsplash的愛好者組織的網站,資料齊全)
  http://www.kernel.org (Linux內核下載)

  本文嚴重參考http://www.linuxhall.org/modules.php?name=News&file=article&sid=201,哈哈,特此說明。

  現在我們進入正題。

  http://www.bootsplash.org網站上說,bootsplash的內核補丁針對2.4.18--2.4.22和2.6.0-test9,這個消息很舊了,可以到http://www.bootsplash.de站點查看bootsplash所提供的各個版本的內核補丁,然後確定你所用的Linux內核版本,選擇一個補丁下載。

  我的內核是2.4.20-8,下載補丁bootsplash-3.0.7-2.4.20.vanilla.diff。補丁中的3.0.7是bootsplash工具的版本號,我們下載bootsplash-3.0.7.tar.bz2,再下載所要用的主題Theme-NewLinux.tar.bz2,關於材料的準備就完成了。這些都可以在上面的提及的網站上找到。如果你的內核沒有相應補丁,那麼可以選擇一個版本的內核源代碼,打上補丁后,編譯一個新的內核。

  如果沒有編譯過內核,可以到網上查找相關資料,對照著練習一下。當然,我們需要root的許可權。

  第一步 修改/usr/include目錄下的三個符號鏈接:asm,scsi,linux(mv asm asm.bak,mv scsi scsi.bak,mv linux linux.bak),如果沒有,則要新建。在編譯內核時,用到這些鏈接所指向的一些頭文件。我在/usr/src目錄下建了一個名為linux的鏈接指向同一層的內核源代碼目錄linux-2.4.20-8(這樣以後再編譯不同版本內核時,只需修改/usr/src目錄下的linux符號鏈接就可以了)。(命令ln -s linux-2.4.20-8 linux),然後進入/usr/include目錄,分別執行ln -s /usr/src/linux/include/asm-i386 asm;ln -s /usr/src/linux/include/linux linux;ln -s /usr/src/linux/include/scsi scsi。

  第二步 打補丁,假設補丁在/usr/src/linux目錄下(不在的話加上路徑即可)。patch -p1
  第三步 設定核心:make menuconfig。確定下列選項被編譯進內核而不是被編譯成模塊。

  對於2.4.x內核:
CODE:
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

  對於2.6.x內核:
CODE:
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

  第四步  
CODE:
a>  make mkproper 清除舊的設定
b>  make dep    產生依賴
c>  make bzImage 編譯內核
d>  make modules modules_install 編譯模塊
e>  cp /usr/src/linux/arch/i386/boot/bzImage /boot/bzImage-2.4.20

  第五步 安裝bootsplash的工具軟體和主題圖片
CODE:
 # 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命令時就會出現類似下面的錯誤:splash:/etc/bootsplash/themes/Linux/images/silent-800x600.jpg不存在。這個其實是由於主題的配置文件中做了絕對路徑設定。
CODE:
# mkdir /etc/bootsplash
# mkdir /etc/bootsplash/themes
# cp -a NewLinux /etc/bootsplash/themes/

  我們來看一個完整的主題配置文件,以800x600解析度為例,文件名為bootsplash-800x600.cfg,可以用vi進行編輯,####開頭的為筆者加的註釋。
CODE:
# 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

  我們可以修改這個文件中的一些選項來得到自己想要的效果。具體選項的含義可以查看:

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

  這兩行指定了作為啟動動畫的圖片和控制台背景的圖片的名字和絕對路徑,我們只需把自己製作的圖片命名為這裡指定的圖片,並且放在這個路徑下,就可以應用自己的主題了。(想想看,製作themes是相當簡單的。不明白為什麼網上沒有redhat linux的主題圖片。)

  我修改了/etc/bootsplash/themes/NewLinux/config/bootsplash-800x600.cfg文件,定義顯示文本信息區域。###部分是我添加的內容。

第六步 將圖片與 init Ram Disk 綁定 splash -s -f /etc/bootsplash/themes/Linux/config/bootsplash-800x600.cfg > /boot/initrd-splash.img 對於ide硬碟,我們可以直接用splash工具生成initrd*.img文件,這個文件對ide硬碟來說沒什麼用,我們在這裡只是通過它來使用啟動畫面。

  如果你只想看到一副靜態的畫面,跳過第七步,看第八步,不用修改腳本文件。

  第七步> 將腳本splash.sh拷入/etc/rc.d/下,並修改splash.sh和rc,建議在修改rc腳本文件前進行備份(cp rc rc.bak)
# cp bootsplash-3.0.7/Scripts/splash.sh/etc/rc.d

  下面來看完整的splash.sh腳本文件,要想這個腳本起作用,必須修改rc腳本,通過rc腳本調用splash.sh腳本,需要賦予splash.sh腳本可執行許可權。需要一些shell script的知識。網上很多,google吧。

   我現在的/etc/rc.d/splash.sh腳本,刪除了原來放在這個腳本中的繪製進度條部分(調試不成功)和播放動畫部分(還沒有實驗),以及不適用於red hat linux的一些命令。這個腳本現在只列印類似「booting the system"和"shutting down the system"的信息和實現關機時的silent mode。
CODE:
#!/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

 下面來看rc腳本(此為系統腳本,決定runlevel和kill or start services,修改前要備份一下,到時要改回來只要覆蓋一下就好了cp rc.bak rc)。下面是我現在的/etc/rc.d/rc腳本,定義一個函數,for循環中調用它,以繪製啟動進度。重新寫了幾行代碼,繪製進度條。以運行級下的服務總個數和已經啟動的服務個數之比作為progress bar的進度,這樣進度條顯得均勻了一些。

  現在這個可以實現以下功能,開機silent模式,有開始畫面,有進度條,進度條下有booting system 提示。關機時切換到silent模式,有畫面。提示shutting down the system.

不過在開機的時候,有一半時間進度條是空的(系統在載入內核,檢測硬體),在關機的時候,進度條一下子就滿了,然後又變空,直到關機。呵呵,回頭再改,告一段落了先。
CODE:
#! /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

第八步 修改(bootloader) grub(或者lilo)。我用的是grub,硬碟是ide的。只列出需要修改的部分。我的硬碟分區swap,boot,/。
CODE:
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模式。這裡的模式選擇要與圖片的大小一致。

  到這裡就可以重新啟動了。呵呵,大功告成。趕緊實驗一下,享受自己的全畫面Linux啟動吧。

[火星人 ] 用bootsplash製作Linux全圖形啟動界面已經有603次圍觀

http://coctec.com/docs/linux/show-post-134046.html