Show Table of Contents
32.6. 预安装脚本
可以在
ks.cfg 文件被解析后马上加入要执行的命令。这个部分必须处于 kickstart 文件的最后(在命令部分之后,如 第 32.4 节 “kickstart 选项” 所述)而且必须用 %pre 命令开头,%end 命令结尾。如果 kickstart 文件还包括 %post 部分,%pre 和 %post 的顺序是没有关系的。
可以在
%pre 部分访问网络;然而,命名服务此时还未配置,所以只能使用 IP 地址。
Only the most commonly used commands are available in the pre-installation environment:
arping, awk, basename, bash, bunzip2, bzcat, cat, chattr, chgrp, chmod, chown, chroot, chvt, clear, cp, cpio, cut, date, dd, df, dirname, dmesg, du, e2fsck, e2label, echo, egrep, eject, env, expr, false, fdisk, fgrep, find, fsck, fsck.ext2, fsck.ext3, ftp, grep, gunzip, gzip, hdparm, head, hostname, hwclock, ifconfig, insmod, ip, ipcalc, kill, killall, less, ln, load_policy, login, losetup, ls, lsattr, lsmod, lvm, md5sum, mkdir, mke2fs, mkfs.ext2, mkfs.ext3, mknod, mkswap, mktemp, modprobe, more, mount, mt, mv, nslookup, openvt, pidof, ping, ps, pwd, readlink, rm, rmdir, rmmod, route, rpm, sed, sh, sha1sum, sleep, sort, swapoff, swapon, sync, tail, tar, tee, telnet, top, touch, true, tune2fs, umount, uniq, vconfig, vi, wc, wget, wipefs, xargs, zcat.
注意
预安装脚本不在更改 root 环境(chroot)中运行。
--interpreter /usr/bin/python- 允许指定不同的脚本语言,如 Python。将 /usr/bin/python 替换成要使用的脚本语言。
32.6.1. 预安装脚本示例
以下是
%pre 部分的示例:
%pre #!/bin/sh hds="" mymedia="" for file in /proc/ide/h* do mymedia=`cat $file/media` if [ $mymedia == "disk" ] ; then hds="$hds `basename $file`" fi done set $hds numhd=`echo $#` drive1=`echo $hds | cut -d' ' -f1` drive2=`echo $hds | cut -d' ' -f2` #Write out partition scheme based on whether there are 1 or 2 hard drives if [ $numhd == "2" ] ; then #2 drives echo "#partitioning scheme generated in %pre for 2 drives" > /tmp/part-include echo "clearpart --all" >> /tmp/part-include echo "zerombr" >> /tmp/part-include echo "part /boot --fstype ext3 --size 75 --ondisk hda" >> /tmp/part-include echo "part / --fstype ext3 --size 1 --grow --ondisk hda" >> /tmp/part-include echo "part swap --recommended --ondisk $drive1" >> /tmp/part-include echo "part /home --fstype ext3 --size 1 --grow --ondisk hdb" >> /tmp/part-include else #1 drive echo "#partitioning scheme generated in %pre for 1 drive" > /tmp/part-include echo "clearpart --all" >> /tmp/part-include echo "part /boot --fstype ext3 --size 75" >> /tmp/part-include echo "part swap --recommended" >> /tmp/part-include echo "part / --fstype ext3 --size 2048" >> /tmp/part-include echo "part /home --fstype ext3 --size 2048 --grow" >> /tmp/part-include fi %end
该脚本决定系统中的硬盘驱动器数量,并根据系统中有一个还是两个驱动器而编写带有不同分区方案的文本文件。不是在 kickstart 文件中有一组分区命令,而是包含以下行:
%include /tmp/part-include
使用脚本中选择的分区命令。
注意
kickstart 文件的 pre-installation 脚本部分不能够管理多个安装树或安装介质。这个信息必须包含在创建的每个 ks.cfg 文件里,这是因为预安装脚本是在安装程序的第二阶段才被执行。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.