Product SiteDocumentation Site

13.7. 安​装​后​脚​本​

你​也​可​以​加​入​在​系​统​安​装​完​毕​后​运​行​的​命​令​。​这​部​分​内​容​必​须​在 kickstart 的​最​后​而​且​用 %post 命​令​开​头​。​它​被​用​于​实​现​某​些​功​能​,如​安​装​其​他​的​软​件​和​配​置​其​他​的​命​名​服​务​器​。​

Note

如​果​你​用​静​态 IP 信​息​和​命​名​服​务​器​配​置​网​络​,你​可​以​在 %post 部​分​访​问​和​解​析 IP 地​址​。​如​果​你​使​用 DHCP 配​置​网​络​,当​安​装​程​序​执​行​到 %post 部​分​时​,/etc/resolv.conf 文​件​还​没​有​准​备​好​。​此​时​,你​可​以​访​问​网​络​,但​是​你​不​能​解​析 IP 地​址​。​因​此​,如​果​你​使​用 DHCP,你​必​须​在 %post 部​分​指​定 IP 地​址​。​

Note

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 替​换​成​你​想​使​用​的​脚​本​语​言​。​

13.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

Note

kickstart 模​式​不​支​持 NFS 文​件​锁​定​,因​此​,当​挂​载 NFS 目​录​时​必​须​使​用 -o nolock 选​项​。​