浙林龙哥

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

轻松拿下Bootsplash


作者:tram 2005-01-13 10:16:22 来自:www.linuxsir.org

安装Bootsplash手记。
我的内核是2.4.23,LFS版本是5.0后的cvs1222。
1.下载所需内核补丁,工具和主题:
ftp://ftp.suse.com/pub/people/stepa...2.4.23.diff.bz2
ftp://ftp.suse.com/pub/people/stepa...h-3.0.7.tar.bz2
ftp://ftp.suse.com/pub/people/stepa...e-Linux.tar.bz2

2.给内核打补丁,并加上所需要的内核参数。
cd /usr/src/linux
make mrproper
patch -Np1 -i ../bootsplash-3.0.7-2.4.23.diff
make menuconfig
选上这几个参数:
Code maturity level options --->
Prompt for development and/or incomplete code/drivers
Block devices ---> RAM disk support
Block devices ---> Initial RAM disk (initrd) support
Console drivers ---> 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
然后是编译内核了:
make dep && make bzImage
再把生成的内核拷贝到/boot下:
cp arch/i386/boot/bzImage /boot/lfs-bootsplash
再在grub的配置文件/boot/grub/menu.lst里面增加一项:
title LFS Boot Splash
root (hd0,6)
kernel /boot/lfs-bootsplash root=/dev/hda7 ro
现在这个已经能启动了,不过还缺少一些boot splash
需要的参数,我们后面还要改的。

3.安装bootsplash-3.0.7里面的工具
解压,并进入bootsplash-3.0.7/Utilities目录。执行命令:
make
cp fbresolution fbmngplay fbtruetype splash /sbin/

4.把图片用splash程序写到ramdisk里,这样在启动的时候才能读到,因为这时候还没有加载分区呢。
建立目录/etc/bootsplash/themes,解压Theme-Linux.tar.bz2到这个目录下,现在的目录结构应该是:
/etc/bootsplash/themes/Linux
ln -s Linux current
再使用splash程序:
/sbin/splash -s -f /etc/bootsplash/themes/Linux/config/bootsplash-1024x768.cfg >> /boot/initrd.splash
这时候,就需要修改刚才的menu.lst文件了,改成:
title LFS Boot Splash
root (hd0,6)
kernel /boot/lfs-bootsplash root=/dev/hda7 ro vga=791 splash=silent
initrd /boot/initrd.splash
现在重启,就能看到可爱的小企鹅了,按F2,会变成verbose模式。

5.加个进度条。
这一步需要修改启动脚本。打开文件/etc/rc.d/init.d,在最后加入:
代码:
progressbar()
{
if [ $# != 1 ]
then
echo "Usage: progressbar {progress}"
exit 1
fi

echo "show $(( 65534 * $1 / 100 ))" > /proc/splash
}

这个就是进度条函数了。要使用这个函数,还需要在具体的启动脚本里添加调用语句。
我一般是用运行级3的,这时的启动过程,需要经过rcsysinit.d和rc3.d两个目录。
我的这两个目录下面的链接是这样:
[root:/etc/rc.d/rc3.d]# ls /etc/rc.d/rcsysinit.d/
S10swap S30checkfs S50cleanfs S70loadkeys
S20mountproc S40mountfs S60setclock S80localnet
[root:/etc/rc.d/rc3.d]# ls /etc/rc.d/rc3.d/
S10sysklogd S25random S40alsa
现在就需要根据个人的情况,编辑相应的启动脚本。别忘了,所有的启动脚本都在/etc/rc.d/init.d下面。按照我的情况,需要编辑的脚本是:
checkfs mountfs cleanfs setclock loadkeys localnet
sysklogd random 和 alsa.
为 什么不编辑前两个脚本swap和mountproc呢?这是因为,progressbar函数里用到了/proc/splash,而在 mountproc之前,这个文件是不存在的。一共是10个脚本,在每个脚本的loadproc那一句(有些脚本没有loadproc的,这就需要根据情 况来看了,反正都是在start参数后面,而在evaluate_retval前面的)前面,加上:
progressbar XXX
这个XXX是小于100的数字,也就是表示启动时进度条的百分比。要说明的是,这个数字按照启动顺序,只能增大,要不然,进度条就会反着走了。启动顺序就是我上面列出的从小到大,从rcsysinit.d到rc3.d。
举 个例子,第一个要编辑的是S30checkfs,就进入/etc/rc.d/init.d目录,打开checkfs脚本,这个脚本不仅没有 loadproc,而且连start参数也没有,但没关系,我们找到evaluate_retval,它前面的一句就是真正执行的语句,如下:
echo "Mounting root file system in read-only mode..."
mount -n -o remount,ro /
evaluate_retval
我把它改成:
echo "Mounting root file system in read-only mode..."
progressbar 10
mount -n -o remount,ro /
evaluate_retval
其他的也差不多。由于执行各个脚本的时间不太清楚,所以需要经过仔细调整,才能让进度条走得均匀。不过这个问题倒是不大,只要能从0走到100就差不多了吧:)
现在重启,就能看到进度条了。不过我做完了以后,发现意思不大,因为在checkfs之前,进度条不走,而开始走了以后,很快就到100%啦,呵呵,可能服务装多了以后,效果更明显吧。

6.动画效果
在前面的bootsplash-3.0.7.tar.bz2解压后,里面有个Scripts目录,这里提供了bootanim和splash.sh两个脚本,但它都是用于suse的,对于LFS不太适用,因此我做了两个脚本:
bootanim.sh:
代码:
#!/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.
#
# This script is used to play animations/sounds/show text/move the
# progress bar, etc.
#
# We call this function from /etc/rc.status:rc_splash()
#
# This program is free software; you may redistribute it under
# the terms of the GNU General Public License. This program has
# absolutely no warranty.
#
# written 2002-2003 Stefan Reinauer, <stepan@suse.de>
#
# this script expects the following environment variables for an
# operable
# progress bar:
#
# sscripts = number of start scripts to be executed for runlevel change
# kscripts = number of stop scripts to be executed for runlevel change
# progress = number of currently executed start/stop script
# RUNLEVEL = runlevel to be reached.
#
# To play animations, it's advised that you have an animations.cfg in
# your
# theme's config directory specifying the initscript name for an event
# and
# the command to be executed:
#
# fsck start:bootanim start bounce.mng
# master:bootanim stop
#
# See http://www.bootsplash.org/ for more information.
#

_procsplash="`cat /proc/splash 2>/dev/null`"

THEME="current"
#test -f /etc/sysconfig/bootsplash && . /etc/sysconfig/bootsplash
test ! -d "/etc/bootsplash/themes/$THEME" && exit 0

# parse animations.cfg. This part should not be handled by the
# splash binary.

function box() { true; } # ignore box descriptions in the config file

test -f
"/etc/bootsplash/themes/$THEME/config/bootsplash-`fbresolution`.cfg" &&
\
. /etc/bootsplash/themes/$THEME/config/bootsplash-`fbresolution`.cfg

if [ -f /etc/bootsplash/themes/$THEME/config/animations.cfg ]; then
COMMAND="`cat /etc/bootsplash/themes/$THEME/config/animations.cfg |
grep "^$1"|cut -f2 -d\:`"
eval $COMMAND
fi

第二个是bootanim:
代码:
#!/bin/bash
#
# bootanim - boot animation wrapper script for fbmngplay
#
# This script parses /usr/share/splash/current/config/bootsplash-XxY.cfg
# to determine the correct animation position.
#
# (C) 2002 SuSE AG. Written by Stefan Reinauer <stepan@suse.de>
#
# modified by Michael Aichler <micha at aichler dot net>
#
usage()
{
echo "Usage: `basename $0` COMMAND [OPTIONS] mng1 [mng2 ...]"
cat << EOF

Available commands:
start starts given animation
stop fades out all running animations
kill immediately stops all animations
next kills current and starts next animation.

Options for use with start command:
EOF
echo -e "`fbmngplay -h 2>&1 | grep -v \"usage:\" | grep
\"-\"`\n"
}

if [ ! -x /sbin/splash ]; then
echo "`basename $0`: can't find splash utility"
exit 1
fi

DIRECTORY=/etc/bootsplash/themes/current/animations
OPTIONS=""
FILES=""
buffer=""
console=""

case "$1" in
start)
# We fall through here.
;;
stop)
killall -q -2 fbmngplay
exit 0
;;
kill)
killall -q fbmngplay
exit 0
;;
next)
killall -q -USR1 fbmngplay
exit 0
;;
*)
echo "`basename $0`: illegal parameter."
usage
exit 1
;;
esac

shift

# We end up in bootanim start

for arg in $*; do
if [ "${arg#*.}" == "mng" ]; then
FILES="$FILES $arg"
else
test "$arg" == "-b" && buffer="true"
test "$arg" == "-c" && console="true"
OPTIONS="$OPTIONS $arg"
fi
done

test -f
"/etc/bootsplash/themes/current/config/bootsplash-`fbresolution`.cfg" &&
\
. /etc/bootsplash/themes/current/config/bootsplash-`fbresolution`.cfg


test -z "$buffer" && OPTIONS="$OPTIONS -b"
test -z "$console" && OPTIONS="$OPTIONS -c 1"
echo $ax
OPTIONS="$OPTIONS -x $ax -y $ay"
CMDLINE="fbmngplay $OPTIONS"

for file in $FILES; do
CMDLINE="$CMDLINE ${DIRECTORY}/${file}"
done

eval "$CMDLINE &"

把这两个脚本保存好,然后:
chmod 755 bootanim.sh bootanim &&
cp bootanim.sh bootanim /sbin
这两个脚本以及前面安装的fbmngplay程序是用来处理动画效果的。不过,动画效果还需要主题的支持。我前面下载的主题Linux,不支持动画效果。关于主题所支持的功能,参见:
http://bootsplash.org/themes.html
我下载了一个Redmond的主题,它能支持动画。
ftp://ftp.suse.com/pub/people/stepa...Redmond.tar.bz2
与前面的做法一样,还是解压到/etc/bootsplash/themes目录下,并删除老的current链接,新建一个:
rm current
ln -s Redmond current
由于主题换了,自然就需要重新写initrd文件了:
/sbin/splash -s -f /etc/bootsplash/themes/current/config/bootsplash-1024x768.cfg >> /boot/initrd.splash
为了使用动画,还要在/etc/rc.d/init.d/functions里增加新的函数。
代码:
animate()
{

if [ $# = 0 ]
then
echo "Usage: animate {hook}"
exit 1
fi

/sbin/bootanim.sh "$*"

}

还要修改启动脚本,使用这个函数要比progressbar复杂一点。需要在启动脚本里添加:
animate HOOK
这个HOOK的值,要到/etc/bootsplash/themes/current/config/animations.cfg文件里找。
对于Redmond这个主题,这个文件的内容是:
fsck start:bootanim start bounce.mng
master:bootanim stop
shutdown: bootanim start bounce.mng
这里的格式是:
HOOK:command
冒号前面的,是需要增加到启动脚本里的内容,而后面的,是真正执行的命令。
我修改了三个脚本,第一个是checkfs(动画开始),第二个是alsa(动画结束),第三个是/etc/rc.d/rc6.d里面的第一个alsa(显示关机画面).
例:
checkfs脚本,修改后相关内容如下:
echo "Mounting root file system in read-only mode..."
progressbar 10
mount -n -o remount,ro /
animate fsck start
evaluate_retval
alsa脚本要修改两个地方,开机动画结束,应该在start参数里,而关机画面,则是在stop参数里。
如下:
代码:
    start)
echo "Starting ALSA... Restoring volumes..."
progressbar 100
animate master
loadproc /usr/sbin/alsactl restore
#echo " Loading MIDI font..."
#loadproc sfxload /path/to/soundfont
;;

stop)
echo "Stopping ALSA... Saving volumes......"
animate shutdown
loadproc /usr/sbin/alsactl store
#echo " Removing MIDI font.........."
#loadproc sfxload -i

现在开机的时候比较正常了,既有背景,又有动画。没有进度条是因为这个主题不支持进度条。关机的时候还不太好,只有动画,没有全图。

7.关机画面。
在你关机执行的第一个脚本里加入
echo "silent" > /proc/splash
还没忘记吧,要在/etc/rc.d/rc6.d里面找以K打头,数字最小的链接。我的机子上是alsa
,改了以后,stop参数是:
代码:
stop)
echo "Stopping ALSA... Saving volumes......"
echo "silent" >> /proc/splash
animate shutdown
loadproc /usr/sbin/alsactl store
#echo " Removing MIDI font.........."
#loadproc sfxload -i
;;

要说明的是,这个关机画面其实就是把主题切换到silent模式,所以如果主题不支持silent模式,就没有用了。Linux和Redmond都支持silent模式的。
同样,在关机的时候也可以显示进度条,只要按照上面所说的,在/etc/rc.d/rc6.d下的脚本里添加progressbar 1-100 就行了,注意要加到stop参数里。

8.不同控制台用不同的背景图片。
splash -n -s -u 1 \
/etc/bootsplash/themes/{任何主题}/config/bootsplash-1024x768.cfg
那个1表示第2个终端。为了一启动就每个控制台控制台都有背景,可以把这些语句加到你的启动脚本里。我是加到alsa脚本里了。如下:
代码:
 start)
echo "Starting ALSA... Restoring volumes..."
progressbar 100
animate master
splash -n -s -u 1 \
/etc/bootsplash/themes/Linux/config/bootsplash-1024x768.cfg
splash -n -s -u 2 \
/etc/bootsplash/themes/SuSE-8.2/config/bootsplash-1024x768.cfg
splash -n -s -u 3 \
/etc/bootsplash/themes/SuSE-8.2/config/bootsplash-1024x768.cfg
loadproc /usr/sbin/alsactl restore
#echo " Loading MIDI font..."
#loadproc sfxload /path/to/soundfont
;;

如果要把背景去掉:
splash -n -s -u 1
注意,有的主题是不能做背景的,比如Redmond,因为它只有silent模式,而normal模式的图片是全黑的,做背景的话,和正常的没什么区别,看不到图。但Linux主题是支持做背景的。

9.使用其他分辨率。
主要是主题要支持,我看下来,还是1024x768支持最好,不过方法都是一样的啦。下面给一个表,是vga模式与分辨率和色深的关系:
Colors-----640x480-----800x600-----1024x768-----1280x1024

256----------769---------771----------773----------775
32000--------784---------787----------790----------793
65000--------785---------788----------791----------794
16.7 Mill.---786---------789----------792----------795

我用的vga是791(没忘吧?在grub的menu.lst里面),也就是1024x768,65000种颜色。

10.定做自己的主题
bootsplash作 为背景,应该是比较顺利的,做进度条稍麻烦,需要手工调整时间,做动画最麻烦,因为没有通用的脚本支持。我上面的脚本只是能在Redmond主题下使用, 效果还不错,其他版本的主题,就不知道如何了。为什么没有一个既好看,又能支持所有特性的主题呢?最后我选择用Linux作为主题,因为不想让LFS背着 个SuSE的名字。为了让Linux主题支持动画,我把 Redmond下面的animation目录和config/animations文件拷贝到了Linux主题下,并且修改Linux主题下的 config/bootsplash-1024x768.cfg文件,增加两个动画所需要的变量。ax和ay是动画显示的位置,我添加如下:
ax=420
ay=100

11.支持TrueType字体
可以在启动过程中显示TrueType字体,定制消息:)
首先要修改主题。Linux主题不支持TrueType字体。在/etc/bootsplash/themes/Linux/config/bootsplash-1024x768.cfg中添加:
# ttf message output parameters
text_x=204
text_y=544
text_size=36
text_color=0xeef4ff
这样就行了。

建立文件/sbin/bootttf:
代码:
#!/bin/bash -x
#
# bootanim - boot animation wrapper script for fbmngplay
#
# This script parses /usr/share/splash/current/config/bootsplash-XxY.cfg
# to determine the correct animation position.
#
# (C) 2002 SuSE AG. Written by Stefan Reinauer <stepan@suse.de>
#
# modified by Michael Aichler <micha at aichler dot net>
#
function box() { true; } # ignore box descriptions in the config file

test -f
"/etc/bootsplash/themes/current/config/bootsplash-`fbresolution`.cfg" &&
\
. /etc/bootsplash/themes/current/config/bootsplash-`fbresolution`.cfg

STRING="What are you going to do?"
case "$1" in
start)
STRING="Booting LFS...Press F2 for verbose mode"
;;

shutdown)
STRING="Shutting down...Press F2 if you want to"
;;

*)
;;
esac

if [ "$text_x" != "" -a "$text_y" != "" \
-a "$text_color" != "" -a "$text_size" != "" ];
then
fbtruetype -x $text_x -y $text_y -t $text_color -s $text_size \
"$_boot $STRING"
fi

这个文件的case那里,可以接受不同的参数,你可以修改或增加自己的消息。使这个脚本可执行:
chmod 755 /sbin/bootttf
然后是在启动脚本里调用。我只用了两个消息,呵呵。在checkfs中:
/sbin/bootttf start
animate fsck start
echo "Checking file systems..."
#Note: -a option used to be -p; but this fails e.g. on fsck.minix
fsck $options -a -A -C -T
error_value=$?
animate fsck stop
第一行就是调用啦。在alsa中,显示关机消息:
代码:
stop)
echo "Stopping ALSA... Saving volumes......"
echo "silent" >> /proc/splash
/sbin/bootttf shutdown
progressbar 1
animate shutdown
loadproc /usr/sbin/alsactl store
#echo " Removing MIDI font.........."
#loadproc sfxload -i
;;

现在重启,就什么都有啦:)
更进一步的主题定制,需要阅读bootsplash.org上的文档。

参考:
http://bootsplash.org/index.html
bootsplash的官方网站。上面可以找到自定义主题的内容,以及其他版本内核的补丁。
http://www.linuxfromscratch.org/hin.../bootsplash.txt
如果需要编译静态的fbmngplay,以便在没有加载/usr分区时使用,可以参考这里。
http://forums.gentoo.org/viewtopic.php?t=49036
posted on 2005-04-22 21:35  浙林龙哥  阅读(2126)  评论(0编辑  收藏  举报