LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 12647|回复: 32

轻松拿下Bootsplash

[复制链接]
发表于 2004-1-5 02:09:50 | 显示全部楼层 |阅读模式
安装Bootsplash手记。
我的内核是2.4.23,LFS版本是5.0后的cvs1222。
1.下载所需内核补丁,工具和主题:
ftp://ftp.suse.com/pub/people/st ... 0.7-2.4.23.diff.bz2
ftp://ftp.suse.com/pub/people/st ... plash-3.0.7.tar.bz2
ftp://ftp.suse.com/pub/people/st ... Theme-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,在最后加入:

  1. progressbar()
  2. {
  3.         if [ $# != 1 ]
  4.                      then
  5.                         echo "Usage: progressbar {progress}"
  6.                         exit 1
  7.                 fi
  8.                
  9.         echo "show $(( 65534 * $1 / 100 ))" > /proc/splash
  10. }
复制代码

这个就是进度条函数了。要使用这个函数,还需要在具体的启动脚本里添加调用语句。
我一般是用运行级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:

  1. #!/bin/bash
  2. #
  3. # splash.sh - This shell script triggers bootsplash actions during
  4. # system boot/shutdown. It can be run by the init scripts repeatedly
  5. # specifying the currently executed system script.
  6. #
  7. # This script is used to play animations/sounds/show text/move the
  8. # progress bar, etc.
  9. #
  10. # We call this function from /etc/rc.status:rc_splash()
  11. #
  12. # This program is free software; you may redistribute it under
  13. # the terms of the GNU General Public License. This program has
  14. # absolutely no warranty.
  15. #
  16. # written 2002-2003 Stefan Reinauer, <stepan@suse.de>
  17. #
  18. # this script expects the following environment variables for an
  19. # operable
  20. # progress bar:
  21. #
  22. #  sscripts = number of start scripts to be executed for runlevel change
  23. #  kscripts = number of stop scripts to be executed for runlevel change
  24. #  progress = number of currently executed start/stop script
  25. #  RUNLEVEL = runlevel to be reached.
  26. #
  27. # To play animations, it's advised that you have an animations.cfg in
  28. # your
  29. # theme's config directory specifying the initscript name for an event
  30. # and
  31. # the command to be executed:
  32. #
  33. #   fsck start:bootanim start bounce.mng
  34. #   master:bootanim stop
  35. #
  36. # See [url]http://www.bootsplash.org/[/url] for more information.
  37. #

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

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

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

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

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

  49. if [ -f /etc/bootsplash/themes/$THEME/config/animations.cfg ]; then
  50.   COMMAND="`cat /etc/bootsplash/themes/$THEME/config/animations.cfg |
  51. grep "^$1"|cut -f2 -d\:`"
  52.   eval $COMMAND
  53. fi
复制代码

第二个是bootanim:

  1. #!/bin/bash
  2. #
  3. # bootanim - boot animation wrapper script for fbmngplay
  4. #
  5. # This script parses /usr/share/splash/current/config/bootsplash-XxY.cfg
  6. # to determine the correct animation position.
  7. #
  8. # (C) 2002 SuSE AG. Written by Stefan Reinauer <stepan@suse.de>
  9. #
  10. # modified by Michael Aichler <micha at aichler dot net>
  11. #
  12. usage()
  13. {
  14.     echo "Usage: `basename $0` COMMAND [OPTIONS] mng1 [mng2 ...]"
  15.     cat << EOF

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

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

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

  30. DIRECTORY=/etc/bootsplash/themes/current/animations
  31. OPTIONS=""
  32. FILES=""
  33. buffer=""
  34. console=""

  35. case "$1" in
  36.         start)
  37.                 # We fall through here.
  38.                 ;;
  39.         stop)
  40.                 killall -q -2 fbmngplay
  41.                 exit 0
  42.                 ;;
  43.         kill)
  44.                 killall -q fbmngplay
  45.                 exit 0
  46.                 ;;
  47.         next)
  48.                 killall -q -USR1 fbmngplay
  49.                 exit 0
  50.                 ;;
  51.         *)
  52.                 echo "`basename $0`: illegal parameter."
  53.                 usage
  54.                 exit 1
  55.                 ;;
  56. esac

  57. shift

  58. # We end up in bootanim start

  59. for arg in $*; do
  60.         if [ "${arg#*.}" == "mng" ]; then
  61.                 FILES="$FILES $arg"
  62.         else
  63.                 test "$arg" == "-b" && buffer="true"
  64.                 test "$arg" == "-c" && console="true"
  65.                 OPTIONS="$OPTIONS $arg"
  66.         fi
  67. done

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


  72. test -z "$buffer" && OPTIONS="$OPTIONS -b"
  73. test -z "$console" && OPTIONS="$OPTIONS -c 1"
  74. echo $ax
  75. OPTIONS="$OPTIONS -x $ax -y $ay"
  76. CMDLINE="fbmngplay $OPTIONS"

  77. for file in $FILES; do
  78.         CMDLINE="$CMDLINE ${DIRECTORY}/${file}"
  79. done

  80. 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/st ... eme-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里增加新的函数。

  1. animate()
  2. {

  3.         if [ $# = 0 ]
  4.                        then
  5.                         echo "Usage: animate {hook}"
  6.                         exit 1
  7.                 fi

  8.         /sbin/bootanim.sh "$*"

  9. }
复制代码

还要修改启动脚本,使用这个函数要比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参数里。
如下:

  1.     start)
  2.         echo "Starting ALSA...    Restoring volumes..."
  3.         progressbar 100
  4.         animate master
  5.         loadproc /usr/sbin/alsactl restore
  6.         #echo "                    Loading MIDI font..."
  7.         #loadproc sfxload /path/to/soundfont
  8.         ;;
  9.                                                                                 
  10.     stop)
  11.         echo "Stopping ALSA...    Saving volumes......"
  12.         animate shutdown
  13.         loadproc /usr/sbin/alsactl store
  14.         #echo "            Removing MIDI font.........."
  15.         #loadproc sfxload -i
复制代码

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

7.关机画面。
在你关机执行的第一个脚本里加入
echo "silent" > /proc/splash
还没忘记吧,要在/etc/rc.d/rc6.d里面找以K打头,数字最小的链接。我的机子上是alsa
,改了以后,stop参数是:

  1. stop)
  2.     echo "Stopping ALSA...    Saving volumes......"
  3.     echo "silent" >> /proc/splash
  4.     animate shutdown
  5.     loadproc /usr/sbin/alsactl store
  6.     #echo "            Removing MIDI font.........."
  7.     #loadproc sfxload -i
  8.     ;;
复制代码

要说明的是,这个关机画面其实就是把主题切换到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脚本里了。如下:

  1. start)
  2.         echo "Starting ALSA...    Restoring volumes..."
  3.         progressbar 100
  4.         animate master
  5.         splash -n -s -u 1 \
  6.                 /etc/bootsplash/themes/Linux/config/bootsplash-1024x768.cfg
  7.         splash -n -s -u 2 \
  8.                 /etc/bootsplash/themes/SuSE-8.2/config/bootsplash-1024x768.cfg
  9.         splash -n -s -u 3 \
  10.                 /etc/bootsplash/themes/SuSE-8.2/config/bootsplash-1024x768.cfg
  11.         loadproc /usr/sbin/alsactl restore
  12.         #echo "                    Loading MIDI font..."
  13.         #loadproc sfxload /path/to/soundfont
  14.         ;;
复制代码

如果要把背景去掉:
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:

  1. #!/bin/bash -x
  2. #
  3. # bootanim - boot animation wrapper script for fbmngplay
  4. #
  5. # This script parses /usr/share/splash/current/config/bootsplash-XxY.cfg
  6. # to determine the correct animation position.
  7. #
  8. # (C) 2002 SuSE AG. Written by Stefan Reinauer <stepan@suse.de>
  9. #
  10. # modified by Michael Aichler <micha at aichler dot net>
  11. #
  12. function box() { true; } # ignore box descriptions in the config file

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

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

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

  25.         *)
  26.                 ;;
  27. esac

  28.   if [ "$text_x" != "" -a "$text_y" != "" \
  29.        -a "$text_color" != "" -a "$text_size" != "" ];
  30.   then
  31.     fbtruetype -x $text_x -y $text_y -t $text_color -s $text_size \
  32.                         "$_boot $STRING"
  33.   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中,显示关机消息:

  1. stop)
  2.         echo "Stopping ALSA...    Saving volumes......"
  3.         echo "silent" >> /proc/splash
  4.         /sbin/bootttf shutdown
  5.         progressbar 1
  6.         animate shutdown
  7.         loadproc /usr/sbin/alsactl store
  8.         #echo "            Removing MIDI font.........."
  9.         #loadproc sfxload -i
  10.         ;;
复制代码

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

参考:
http://bootsplash.org/index.html
bootsplash的官方网站。上面可以找到自定义主题的内容,以及其他版本内核的补丁。
http://www.linuxfromscratch.org/ ... iles/bootsplash.txt
如果需要编译静态的fbmngplay,以便在没有加载/usr分区时使用,可以参考这里。
http://forums.gentoo.org/viewtopic.php?t=49036
发表于 2004-1-5 05:05:05 | 显示全部楼层
tram的原创?
好文:)
对于启动脚本又多了一些了解,谢谢:)
发表于 2004-1-5 16:34:21 | 显示全部楼层
虽然不是原创,但总结也是创新嘛。
用bootsplash关键字搜索论坛,你会看到更多。
发表于 2004-1-5 21:40:28 | 显示全部楼层
太棒了,我需要的正是这个,用bootsplash关键字搜索论坛,会找到一些好帖子,我就是按照本论坛的几个帖子做成了bootsplash开机图片,而开机动画以及进度条就是搞不定,这篇帖子太好了
 楼主| 发表于 2004-1-5 22:32:13 | 显示全部楼层
这可是我原创的啊!就是那几个脚本写得太烂了。
发表于 2004-1-5 22:57:41 | 显示全部楼层
这可是第一个系统的安装帖子
 楼主| 发表于 2004-1-5 23:03:22 | 显示全部楼层
其实bootsplash就是四个程序。
fbmngplay是读mng文件,放动画。
fbtruetype是显示truetype字体。
fbresolution是检查分辨率。
splash程序是在framebuffer上显示图片。
其他的脚本,只是以不同参数来读取配置文件,调用所需程序。
发表于 2004-1-6 16:11:10 | 显示全部楼层
影响性能吗?
发表于 2004-1-6 17:16:15 | 显示全部楼层
老兄你太NB了!做我老婆吧!:p:p:p
不管怎么说,先谢了(收了以后再看吧!)
发表于 2004-1-7 10:41:44 | 显示全部楼层

能解释一下下面的意思吗?

能解释一下下面的意思吗?
title LFS Boot Splash
root (hd0,6)
kernel /boot/lfs-bootsplash root=/dev/hda7 ro vga=791 splash=silent
initrd /boot/initrd.splash
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表