SDB:KIWI Cookbook 启动画面

跳转到:导航搜索


本教程描述了设置定制启动画面过程的方法。
Icon-checked.png
此过程至少在 Kiwi 版本 3.25 ( kiwi --version ) 上进行了测试 - 较旧的版本不支持所有显示的功能 版本


自定义 GRUB 和启动画面图像

本示例概述了如何使用 Bootsplash 项目(撰写本文时所有发行版)定制 SUSE 发行版的启动画面。

定制 GRUB 和启动画面图像

准备时间

  • 20 分钟 + 创建图形图像的时间

烹饪时间

  • 20 分钟

配料

  • 正在运行的 openSUSE 11.1 或 11.2 系统
  • openSUSE 11.1 或 11.2 仓库
  • 已安装最新版本的 KIWI 工具集(至少版本 3.25)
  • 已安装 kiwi-doc 包
  • 背景图像
  • 可伸缩矢量图形 格式的 logo 图像
  • 已安装的 PHP 解释器
  • 已安装 GraphicsMagick
  • 已安装 Inkscape
  • 大约 1 GB 的可用磁盘空间


在开始之前,请注意一个快速声明。 您的图像的大小和颜色数量有限制,因此如果您的图像未显示,很可能是由于这些限制而不是其他地方的错误造成的。

准备工作

默认情况下,SUSE 发行版的品牌由 bootsplash-branding*gfxboot-branding- 包控制。 gfxboot-branding- 包包含在 GRUB 菜单(即您选择内核的菜单)后面显示的图像的信息。 bootsplash-branding* 包含有关实际启动过程中显示的图像的信息。

定制启动画面和 GRUB 菜单图像需要复制 bootsplash-branding*gfxboot-branding- 包的目录结构。 要查看这些结构,请运行以下命令

 rpm -qa | grep branding

这将生成一个软件包列表。 您可以从该列表中找到我们感兴趣的软件包的确切名称。 然后使用

 rpm -ql <PACKAGE_NAME>

查看软件包提供的目录和文件列表。 是的,两个软件包的列表都比较长,但不用担心,我们将使用脚本生成启动画面所需的图像。 对于 GRUB 菜单,只需要一个图像。

在开始图像创建等操作之前,让我们创建一个工作目录。

mkdir $HOME/splashCustom
cd $HOME/splashCustom

定制启动画面图像

启动画面图像

我们稍后将用于生成启动画面图像适当目录树的脚本需要 PNG 图像作为背景和 SVG 图像作为 logo,并且需要在执行目录中存在特定的名称。 预期的文件名如下

  1. background.png - 在静默启动期间显示的图像背景
  2. background-verbose.png - 在详细启动期间显示的图像背景
  3. logo.svg - 在静默启动期间使用的 logo
  4. logov.svg - 在详细启动期间使用的 logo

您可以修改脚本以更改这些名称,如果您愿意。 在本示例中,我们将坚持使用上述名称。

在工作目录中,启动您最喜欢的图形创建工具,并创建您选择的背景和 logo 图像。 请记住开头的声明。 因此,您不能过于疯狂。 如果您已经有图像,只需将它们复制到工作目录中,并使用适当的名称。 如果您只想尝试本教程而无需创建图像,可以使用以下图像。

  1. background.png
  2. background-verbose.png
  3. logo.svg
  4. logov.svg

正如您所看到的,您不必具备艺术技能。

Bootsplash 目录结构生成

在工作目录中创建一个名为 bootsplash.php 的脚本,内容如下:

#!/usr/bin/php
<?php
//depends on graphicsmagic and rsvg

$distro = "openSUSE 11.2";
$themename = "myTheme";
$themepath = "./bootsplash/$themename";
$imagepath = "/etc/bootsplash/themes/$themename/images";
//resolution, jpeg export quality pairs
$resolutions = array("640x480"=>"95", "800x600"=>"95", "1024x600"=>"94", 
		"1024x768"=>"94", "1152x768"=>"94", "1152x864"=>"93", 
		"1280x768"=>"93", "1366x768"=>"93", "1280x800"=>"93", 
		"1280x854"=>"93", 
		"1280x960"=>"92", "1280x1024"=>"92", "1400x1050"=>"91",
		"1440x900"=>"91", "1600x1024"=>"90", "1600x1200"=>"89", 
		"1680x1050"=>"89", "1920x1200"=>"80", "3200x1200"=>"70");
/*
$resolutions = array("800x600"=>"95");
*/
//create dirs
if (!is_dir($themepath)) {
	//print "removing old theme $themename\n\n";
	//exec("rm -rf ./theme/$themename");
	mkdir ("./bootsplash");
	mkdir ("$themepath");
	mkdir ("$themepath/config");
	mkdir ("$themepath/images");
} 
//create logos
if (!is_dir('./temp')) {
	mkdir ("./temp");
}
$cmd = "inkscape -w 180 -e ./temp/logo.png logo.svg"; //silent logo
exec($cmd);
$cmd = "inkscape -w 90 -e ./temp/logov.png logo.svg"; //verbose logo
exec($cmd);
$cmd = "gm convert -comment \"id logo deltabg stop\" ./temp/logo.png ./temp/logo.png ./temp/logo.mng";
exec($cmd);
$cmd = "gm convert -colorspace gray -comment \"id logov deltabg stop\" ./temp/logov.png ./temp/logov.png ./temp/logov.mng";
exec($cmd);

#exec("/usr/local/bin/convert ./building-blocks/logo.png $themepath/images/logo.mng");
copy("./temp/logo.mng", "$themepath/images/logo.mng");
copy("./temp/logov.mng", "$themepath/images/logov.mng");

while (list($res,$q) = each($resolutions)) {
//scale backgrounds

	print "creating $res resolution images\n";
	$in = "./background.png";
	$inverb = "./background-verbose.png";
	$silent = "$themepath/images/silent-$res.jpg";
	$verbose = "$themepath/images/bootsplash-$res.jpg";
	$cmd = "gm convert $in -geometry $res\! -quality $q -interlace None -colorspace YCbCr ";
	$cmd .= " -sampling-factor 2x2 $silent"; 
	exec($cmd);
	$cmd = "gm convert $inverb -geometry $res\! -quality $q -interlace None -colorspace YCbCr ";
	$cmd .= " -sampling-factor 2x2 $verbose"; 
	#$cmd = "gm convert $in -colorspace gray -geometry $res\! -quality $q -interlace None ";
	#$cmd .= "-colorspace YCbCr -sampling-factor 2x2 $verbose";
	exec($cmd);

//generate config files
	print "Generating config file for $res\n";
	$fp = fopen("$themepath/config/bootsplash-$res.cfg", "w");
	
	fwrite($fp, "# This is a bootsplash configuration file for\n");
	fwrite($fp, "# $distro, resolution $res.\n");
	fwrite($fp, "#\n");
	fwrite($fp, "# See www.bootsplash.org for more information.\n");
	fwrite($fp, "# created by SUSE Image Builder\n");
	fwrite($fp, "#\n");
	fwrite($fp, "version=3\n"); //config file version
	fwrite($fp, "state=1\n"); //picture is diplayed
	fwrite($fp, "progress_enable=0\n"); //no progress
	fwrite($fp, "overpaintok=1\n"); //no clue what this is
	fwrite($fp, "\n\n");
	//colors
	fwrite($fp, "fgcolor=7\n");
	fwrite($fp, "bgcolor=0\n\n");
	//text window frame
	ereg("([0-9]+)x([0-9]+)", $res, $dimensions);
	$x = $dimensions[1];
	$y = $dimensions[2];
	$tx = 20;
	$ty = 60;
	$tw = $x - $tx - 10;
	$th = $y - $ty;
	fwrite($fp, "tx=$tx\n");
	fwrite($fp, "ty=$ty\n");
	fwrite($fp, "tw=$tw\n");
	fwrite($fp, "th=$th\n");
	//background
	fwrite($fp, "\n\njpeg=$imagepath/bootsplash-$res.jpg\n");
	fwrite($fp, "silentjpeg=$imagepath/silent-$res.jpg\n");
	fwrite($fp, "\n\n");
	$lx = round($x/2); 
	$ly = round($y/2)-20; 
	fwrite($fp, "mnganim logo $imagepath/logo.mng initframe logo silent center $lx $ly\n");
	
	//overlay title (verbose)
	$vlx = 2;
	$vly = 2;
	fwrite($fp, "mnganim logov $imagepath/logov.mng initframe logov origin 0 $vlx $vly\n");
	
	//animation triggers
	fwrite($fp, "trigger \"isdown\" quit\n");
	fwrite($fp, "trigger \"rlreached 5\" toverbose\n");
	fwrite($fp, "trigger \"rlchange 0\" tosilent\n");
	fwrite($fp, "trigger \"rlchange 6\" tosilent\n");

	$verticalpcnt = 0.8;
	$width = 160; //width of the progress bar
	$voffset = 30; //vertical offset from the title (defined by verticalpcnt above)
	$x1 = $lx - round($width/2) - 4;
	$x2 = $x1 + $width;
	//$y1 = round($verticalpcnt*$y);
	$y1 = round($ly+$voffset);
	$y2 = $y1+1; //let's try a 2 pixel line
	fwrite($fp, "\n\n");
	fwrite($fp, "progress_enable=1\n"); //enable progress
	fwrite($fp, "box silent noover $x1 $y1 $x2 $y2 #ffffff10\n"); //progress background
	$wl = "box silent inter " . $x1 . " " . ($y1 - 1) . " " . $x1 . " " . ($y1 + 1) . " #ffffff80\n";
	fwrite($fp, $wl); //starting point ...
	$wl = "box silent " . $x1 . " " . ($y1 - 1) . " " . $x2 . " " . ($y2 + 1) . " #ffffff80\n";
	fwrite($fp, $wl); //..iterated to this

	fclose($fp);
}

?>

感谢 Jakub 提供脚本。

然后执行脚本

php bootsplash.php

脚本完成后,您将在工作目录中有一个 bootsplash 目录。 这包含定制启动画面所需的一切。

图像树生成脚本

关于上述图像树创建脚本的一些说明。

  1. 变量 $themename 的值是任意的,因此您可以使用比 myTheme 更具创意的名称。 此值稍后将在 config.xml 文件中使用。 要求是此名称和在 config.xml 文件中使用的名称匹配,因此请注意拼写错误。
  2. 字典或哈希后的给定分辨率中的数字表示图像转换的质量。 较高的质量数字意味着更大的文件大小,因此您更有可能遇到 bootsplash 系统的限制。 一个粗略的估计是,任何文件都不应超过 70K。 您可以通过更改这些数字来影响图像的大小。 这不是一门精确的科学,并且不可避免地需要反复试验。

这些是您应该对脚本进行的所有更改。 该脚本还会生成配置文件,您可以随意玩弄这些配置文件,直到获得您喜欢的颜色定位等。

处理 GRUB 背景

背景图像

启动您最喜欢的图像编辑工具,并创建您希望用于 GRUB 菜单的背景图像。 一个文件应命名为 back.jpg,另一个文件应命名为 pback.jpg。 使用这些文件名将允许您避免修改配置文件。 如果您已经有图像,请将它们复制到工作目录中,并使用这些名称。 如果您只想继续操作并完成示例,请随时使用以下准备好的图像。

  • back.jpg
  • pback.jpg


设置目录结构

创建图像后,我们需要设置目录结构。 GRUB 背景图像需要位于 /usr/share/gfxboot/themes/THEME_NAME/{data-boot,data-install} 中。 除了图像,我们还需要配置文件和 Makefile 的链接。

与其从头开始创建所有基础设施,不如利用现有工作。 安装 gfx-devel 包以使用预配置的配置文件等。

zypper in gfxboot-devel

安装后,您可以复制派生主题并为其指定自己的名称。

cp -r /usr/share/gfxboot/themes/SLED .
mv SLED myTheme

您的主题名称 (myTHeme) 必须与您在 bootsplash.php 脚本中的 $themename 变量中使用的名称匹配。 接下来,替换图像。

cp back.jpg pback.jpg myTheme/data-boot
cp back.jpg pback.jpg myTheme/data-install

随意浏览各种配置文件并根据需要修改它们。 Gfxboot 页面提供了您可能感兴趣的所有详细信息。

集成定制

完成图像创建和定制设置后,现在我们可以将我们的定制集成到 Kiwi 镜像构建中。 对于本示例,我们将使用 kiwi-doc 包提供的 live-iso 示例。

  • 将示例配置复制到工作目录。
cp -r /usr/share/doc/packages/kiwi/examples/suse-11.2/suse-live-iso .
  • 创建 bootsplash 主题的目录结构,并将您的主题移动或复制到其中。
mkdir -p etc/bootsplash/themes
mv bootsplash/myTheme etc/bootsplash/themes
  • 创建 gfxboot 主题的目录结构,并将主题移动或复制到其中。
mkdir -p usr/share/gfxboot/themes
mv myTheme usr/share/gfxboot/themes
  • 将主题打包成 tarball,并将 tarball 移动或复制到 Kiwi 配置文件树中。
tar -czvf myTheme.tgz usr etc
mv myTheme.tgz suse-live-iso
  • 使用您最喜欢的编辑器编辑 config.xml 文件
    • 如果您不想通过互联网获取软件包,请替换仓库定义
    • 在 <preferences> 元素内,添加一个子元素,其名称为 <boot-theme>,值为您的主题名称。 在本示例中,配置条目如下所示
 <boot-theme>myTheme</boot-theme>
    • 在 <packages> 元素内,添加一个子元素,其名称为 <archive>,将 name 属性值设置为我们之前创建的 tarball 的名称,并将 bootinclude 设置为 true。 在本示例中,配置条目如下所示
 <archive name="myTheme.tgz" bootinclude="true"/>
    • gfx-devel 包添加为要包含的包,并将其包含在启动镜像中,如下所示
 <package name="gfxboot-devel" bootinclude="true" bootdelete="true"/>
    • 删除包含 SUSE 品牌信息的行

应用更改后,<packages> 元素应如下所示。

<packages type="image" patternType="plusRecommended" patternPackageType="plusRecommended">
    <archive name="myTheme.tgz" bootinclude="true"/>
    <package name="gfxboot-devel" bootinclude="true" bootdelete="true"/>
    <package name="kernel-default"/>
    <package name="bootsplash"/>
    <package name="ifplugd"/>
    <package name="vim"/>
    <opensusePattern name="default"/>
    <opensusePattern name="kde4"/>
</packages>
如果您包含分发提供的品牌包,这些包将优先于您的自定义图像。 因此,重要的是不要包含分发品牌包。

这完成了自定义图像的集成。 剩下的就是构建和测试镜像。

kiwi --prepare ./suse-live-iso --root /tmp/customBoot_unpacked
kiwi --create /tmp/customBoot_unpacked -d /tmp/customBoot_image
构建 live 镜像会拉取一个名为 welcome.jpg 的图形图像。 此图像文件位于 /usr/share/gfxboot/themes/THEME_NAME/data-install 中,或者在本例中位于 usr/share/gfxboot/themes/myTheme/data-install 中。 由于我们没有修改此图像,因此在测试期间我们将看到 SLED 欢迎图像。 我们将看到 SLED 欢迎图像,因为我们的 gfxboot 主题是基于 SLED 主题的副本。 如果您想更改它,请查看 welcome.svg,该文件位于 http://gitorious.org/opensuse/art/trees/master/cdboot

Kiwi 构建 ISO 镜像后,您可以使用 qemu 进行测试,如下所示

 qemu-kvm -cdrom=/tmp/customBoot_image/IMAGE_NAME.iso
之前注意到的关于 64 位镜像的注意事项适用