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 位址。
注意
後續安裝的 script 會在 chroot 環境下執行,因此將無法執行如從安裝媒體複製 script 或 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. 範例
將系統登記至 Red Hat 網路衛星:
%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
。