2008年7月15日 星期二

Kickstart auto Installations



Many system administrators would prefer to use an automated installation method to install Red Hat Enterprise Linux on their machines. To answer this need, Red Hat created the kickstart installation method. Using kickstart, a system administrator can create a single file containing the answers to all the questions that would normally be asked during a typical installation.

Kickstart files can be kept on a single server system and read by individual computers during the installation. This installation method can support the use of a single kickstart file to install Red Hat Enterprise Linux on multiple machines, making it ideal for network and system administrators.

Kickstart provides a way for users to automate a Red Hat Enterprise Linux installation.

(以上文章段落取自 Red Hat Enterprise Linux 5 安​裝​手​冊  Kickstart 安​裝)





上面就是說 , 安裝 Linux 系統時 , 不是有一堆的設定要設(語系,硬碟,網路,套件,...etc.) ,
kickstart 檔就是把這些設定先寫到一個檔案內 ,
以後裝 Linux 時 , 只要把這個檔案給它 , 它便可以依照檔案內的設定值 , 把系統裝起來 ,
而不須要在介面上與使用者互動了 , 也就達到了自動安裝的效果了 .


當然 , 這並不是 Red Hat Enterprise 所獨有的機制 ,
它在很多 Linux Distributions 中都看得到 .





建立 kickstart 檔


如何建立 Kickstart 檔 , 然後利用這個檔來達到自動安裝 Linux 的功能 ?


1.  自行手動建立 kickstart 檔 . 檔名可自取 , 如 ks.cfg
2.  安裝 system-config-kickstart 工具 , 利用圖型介面工具 , 一步一步操作 , 建立 kickstart 檔 .
3.  在 RedHat base 的 Distributions , 當安裝一台 Linux 系統時 , 它會自動把這次安裝的選項 ,
     做成一個 kickstart 檔 , 也就是說 , 在現有的系統下 , 已經有一個現成的 kickstart 檔了 .
     這個現成的 kickstart 檔就是 /root/anaconda-ks.cfg .



kickstart 檔的內容可以放入以下項目 :
(檔案中 , # 字號開頭的說明行)


install
(install 當然就是安裝囉 ! 相對的設定就是 upgrade , 兩者二擇一)


cdrom
(安裝媒體的位置 , 可以是 cdrom , 網路上 ftp 或 http 的服務位置如下 , 請擇一)
(url --url ftp://192.168.0.18/pub/redhat/5/i386/cdrom)
(url --url http://192.168.0.18/pub/redhat/5/i386/cdrom)


key --skip
(安裝序號 , 這是 RedHat Enterprise 用得到的 , Fedora or CentOS 可忽略)


lang en_US.UTF-8
(系統所使用的語系)


keyboard us
(鍵盤型態為 "美式鍵盤")


network --device eth0 --bootproto static --ip 192.168.0.1 --netmask 255.255.255.0 --gateway 192.168.0.254 --nameserver 168.95.1.1,168.95.1.2 --hostname rhel5.example.com.tw
(注意 : 上面為一行 , 因太長而自動摺行) (network 開頭就是網路設定開始)


rootpw --iscrypted $1$8VD6gfhn$YQsVaCS5QRpC2RPeWysAu/
(最高權限者的密碼)


firewall --disabled
(防火牆 , --disabled 是關閉 , --enable 是開啟)


authconfig --enableshadow --enablemd5
(認証項目 支援 shadow passwd 及 MD5 編碼)


selinux --disabled
(selinux --disabled 為關閉 ,--inforcing 為啟動 , --permissive 啟動但只警告)


timezone Asia/Taipei
(時區 , 亞洲/台北)


bootloader --location=mbr
(開機選單 , --location=mbr 是說要裝在 MBR 內)


clearpart --all --initlabel
(刪除 partition , --all 是全部 , --initlabel 初始磁碟標籤)


part /boot --fstype ext3 --size=100
(切一個 partition , mount point 為 /boot , Filesystem 為 Ext3 , 大小為 100MB)


part / --fstype ext3 --size=3072 --grow --maxsize=6144
(/ 根目錄的大小為 3 GB , 若還有空間則自動放大 , 最大不可超過 6 GB)


part swap --size=1024
(swap 分割區的大小為 1 GB)


reboot
(裝完後要重開機)



%include (非必要)
(%include 這個選項可以放在任意位置)
(使用 %include /path/to/file 指令來含括另一個檔案的內容)
(就好像該檔案的內容是在 kickstart 檔案中 %include 指令的位置)


%packages
(%packages 這行開始 , 往下就是系統要安裝的套件)


@development-libs 
@editors 
@system-tools 
@core 
@base 
@server-cfg 
@sql-server 
@admin-tools 
@development-tools

(@開頭的是套件群組)
mc 
sysstat 

(上面兩項是單獨的套件)


%pre (非必要)
(%pre 這行開始 , 往下可以寫一些 Shell Scripts)
(這些 Scripts 會在安裝前先執行)
(譬如可以寫個 Script 來判斷硬碟數量或大小 , 用來決定要如何規劃 partitions
)
(不做範例 , 您可參考 Red Hat Enterprise Linux 安​裝​手​冊 Kickstart 安​裝 前置安裝碼)



%post (非必要)
(%post 這行開始 , 往下可以寫一些 Shell Scripts)
(這些 Scripts 會在安裝完成後 , 第一次重開機前執行.)

(以下是 %post 段落的範例)
cat > /etc/cron.d/pgsql <<END
0 0 * * * root su -l postgres -c "/usr/bin/pg_dumpall > \
/var/lib/pgsql/backups/pgsql_`date +%d`.sql"
END

(上面這段只是舉個簡單的例子 , 做個資料庫定時備份的排程)
/sbin/chkconfig telnet off
/sbin/chkconfig postgrepsql on
(上面這段只是舉個簡單的例子 , 設定開機時 , 要啟動的服務)
(以上是 %post 段落的範例)





以上便是 Kickstart 設定檔的範例 ,
有些非必要性的參數可以省略 , 有些則不可省(刻意要省略某一參數也是可以啦 !) .
若是少了某項該有參數 , 它會在安裝階段跑到該處時 , 跳出對話匡詢問操作者 .













沒有留言: