Menu Close
Red Hat Training
A Red Hat training course is available for Red Hat Enterprise Linux
28.7. 安装后脚本
你也可以加入在系统安装完毕后运行的命令。这部分内容必须在 kickstart 的最后而且用
%post
命令开头。它被用于实现某些功能,如安装其他的软件和配置其他的命名服务器。
注意
如果你用静态 IP 信息和命名服务器配置网络,你可以在
%post
部分访问和解析 IP 地址。如果你使用 DHCP 配置网络,当安装程序执行到 %post
部分时,/etc/resolv.conf
文件还没有准备好。此时,你可以访问网络,但是你不能解析 IP 地址。因此,如果你使用 DHCP,你必须在 %post
部分指定 IP 地址。
注意
post-install 脚本是在 chroot 环境里运行的。因此,某些任务如从安装介质复制脚本或 RPM 将无法执行。
--nochroot
- 允许你指定你想在 chroot 环境之外运行的命令。下例把
/etc/resolv.conf
文件复制到刚安装的文件系统里。%post --nochroot cp /etc/resolv.conf /mnt/sysimage/etc/resolv.conf
--interpreter /usr/bin/python
- 允许你指定不同的脚本语言,如 Python。把 /usr/bin/python 替换成你想使用的脚本语言。
28.7.1. 范例
向红帽网络 Satellite 注册:
%post ( # Note that in this example we run the entire %post section as a subshell for logging. wget -O- http://proxy-or-sat.example.com/pub/bootstrap_script | /bin/bash /usr/sbin/rhnreg_ks --activationkey=<activationkey> # End the subshell and capture any output to a post-install log file. ) 1>/root/post_install.log 2>&1
从 NFS 共享目录运行叫
runme
的命令:
mkdir /mnt/temp mount -o nolock 10.10.0.2:/usr/new-machines /mnt/temp open -s -w -- /mnt/temp/runme umount /mnt/temp
注意
kickstart 模式不支持 NFS 文件锁定,因此,当挂载 NFS 目录时必须使用
-o nolock
选项。