ks.cfg文件:又稱Kickstart文件,主要用于Linux系統(tǒng)的自動化安裝。
在CentOS系統(tǒng)中 /root/anaconda-ks.cfg就是一個ks.cfg文件,它指明了當(dāng)前系統(tǒng)預(yù)安裝環(huán)境時的設(shè)置內(nèi)容。
linux安裝大致可以分為2個階段
第一階段:linux的預(yù)安裝環(huán)境
此階段是linux的預(yù)安裝環(huán)境,提供linux安裝選項的一個接口,可以將它比作是windows中的PE環(huán)境
第二階段:自動安裝過程
該階段系統(tǒng)會按照第一階段設(shè)定的參數(shù)自動安裝,
第一階段有兩種模式:交互式和非交互式
交互式就和普通安裝一樣,按照提示選擇選項一步步的安裝
非交互式則通過讀取kickstart文件的配置,進行自動安裝,這和window中的無人值守安裝差不多的,這個文件即是ks.cfg文件(相當(dāng)于window中的wi2k3.sif應(yīng)答文件)
而在安裝linux過程中,獲取ks.cfg文件的方式有多種,如直接在cdrom中獲取,常見的形式還有http,ftp,nfs等方式。
在使用ks.cfg之前,需要先引導(dǎo)啟動環(huán)境
引導(dǎo)方式有很多,cdrom,usb,PXE等。
在引導(dǎo)進入第一階段后,即可通過讀取ks.cfg來進行系統(tǒng)的自動安裝
這里開始說說ks文件的大致內(nèi)容
ks.cfg文件組成大致分為3段
1.命令段:
鍵盤類型,語言,安裝方式等系統(tǒng)的配置,有必選項和可選項,如果缺少某項必選項,安裝時會中斷并提示用戶選擇此項的選項
2.軟件包段:
%packages
@groupname:指定安裝的包組
package_name:指定安裝的包
-package_name:指定不安裝的包
在安裝過程中默認安裝的軟件包,安裝軟件時會自動分析依賴關(guān)系。
3.腳本段(可選):
%pre:預(yù)安裝腳本(由于只依賴于啟動鏡像,支持的命令很少)
%post:后安裝腳本(基本支持所有命令)
而具體的ks.cfg文件的配置,我們只需要在已經(jīng)安裝好的linux的root家目錄找到anaconda_ks.cfg(這個ks文件就是在安裝linux后,根據(jù)用戶的安裝選項自動生成的)
下面的是一個樣例:
#version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512# 系統(tǒng)授權(quán)信息 # Use network installation url --url="http://192.168.52.132/centos7"# 安裝方式,如果是本地光盤安裝則是 cdrom # Use graphical install graphical # Run the Setup Agent on first boot firstboot --enable # Keyboard layouts keyboard --vckeymap=cn--xlayouts='cn'# 鍵盤樣式 # System language lang zh_CN.UTF-8 #語言
# Network information # 網(wǎng)絡(luò)配置信息,設(shè)置IP獲取方式,網(wǎng)關(guān)及DNS等信息 network --bootproto=dhcp --device=eno16777736 --ipv6=auto --activate network --hostname=localhost.localdomain
# Root password # root賬戶的信息及密碼,密碼是加密過的 rootpw --iscrypted$6$qUeqvWWOr921mWBY$h5wjwdcnIOC/FS6rCaZblKNGELwN9jrGwJZuwlrNi9OHzI.n1lxaKKrkwdN7nadXP5f2mFRDrW9D9gYStXGZu/ # System timezone # 系統(tǒng)時區(qū)與其他用戶信息及用戶密碼 timezone Asia/Shanghai --isUtc user --groups=wheel--name=pxetest --password=$6$.hgpJdCAhSMaf7yB$5GKYIAgTkLxfS1JHK5KSpN96LXhkKGFX3FbnQl0hTME3wbF1njxyezmPF/HXAtI9Bp8U6MsF3hRXlFvFfn9Nm/--iscrypted --gecos="pxetest" # System bootloader configuration # 引導(dǎo)程序相關(guān)參數(shù) bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda autopart --type=lvm # Partition clearing information # 初始化磁盤設(shè)置 clearpart --none --initlabel
# 分區(qū)設(shè)置 # part / --fstype=ext4 --size=18000 #開始分區(qū) # part swap --grow --size=1024 # repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100
# 需要安裝的系統(tǒng)模式及附加軟件包
%packages @^infrastructure-server-environment @base @compat-libraries @core @debugging @development @dns-server @file-server @ftp-server @security-tools @smart-card kexec-tools
# 后安裝腳本,Linux安裝完成后執(zhí)行的腳本可以寫在這里
# %post %end %addon com_redhat_kdump --enable --reserve-mb='auto' %end
如果覺得使用樣本的方式手工寫配置文件比較麻煩,也可以使用圖形化工具來制作ks.cfg文件。在linux中用yum安裝system-config-kickstart就行了(圖形化依賴于x-window),選項也有些限制(比如分區(qū)不能使用lvm)
參考資料:http://www.linuxdiyf.com/linux/3191.html
參考資料:http://www.linuxidc.com/Linux/2013-07/87299.htm
================================以下為一個ks.cfg的例子====================================
#version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 url --url="http://192.168.17.151/cobbler/ks_mirror/CentOS-7-x86_64" text # Firewall configuration # Run the Setup Agent on first boot firstboot --enable ignoredisk --only-use=sda keyboard --vckeymap=cn --xlayouts='cn' # System language lang zh_CN.UTF-8 # Network information network --bootproto=dhcp --device=eno16777736 --ipv6=auto --activate network --bootproto=dhcp --hostname=Client-x # Reboot after installation reboot # Root password rootpw --iscrypted $6$PumnYZm77S9o.9e5$IRSIoUF4GgOxpj.r2OY5qTxJwBz1NyUVYciFPhEyj5MqcFCOHCQd3cNpt60LIwWlXtWLXZ2tT8G51FZkYXJyW/ # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # System timezone timezone Asia/Shanghai --isUtc user --groups=wheel --name=test --password=$6$Rs9WcGhknZPweSTO$aAAyGL61HFwF8zrUG.8E6q99MUNI/rTCHWFyM7Qz3Jqf.VQskwCfhYQ8fT78WXcDprl3xSWtbDCBCJHToY3gc. --iscrypted --gecos="test" # System bootloader configur
ks.cfg文件:又稱Kickstart文件,主要用于Linux系統(tǒng)的自動化安裝。
在CentOS系統(tǒng)中 /root/anaconda-ks.cfg就是一個ks.cfg文件,它指明了當(dāng)前系統(tǒng)預(yù)安裝環(huán)境時的設(shè)置內(nèi)容。
linux安裝大致可以分為2個階段
第一階段:linux的預(yù)安裝環(huán)境
此階段是linux的預(yù)安裝環(huán)境,提供linux安裝選項的一個接口,可以將它比作是windows中的PE環(huán)境
第二階段:自動安裝過程
該階段系統(tǒng)會按照第一階段設(shè)定的參數(shù)自動安裝,
第一階段有兩種模式:交互式和非交互式
交互式就和普通安裝一樣,按照提示選擇選項一步步的安裝
非交互式則通過讀取kickstart文件的配置,進行自動安裝,這和window中的無人值守安裝差不多的,這個文件即是ks.cfg文件(相當(dāng)于window中的wi2k3.sif應(yīng)答文件)
而在安裝linux過程中,獲取ks.cfg文件的方式有多種,如直接在cdrom中獲取,常見的形式還有http,ftp,nfs等方式。
在使用ks.cfg之前,需要先引導(dǎo)啟動環(huán)境
引導(dǎo)方式有很多,cdrom,usb,PXE等。
在引導(dǎo)進入第一階段后,即可通過讀取ks.cfg來進行系統(tǒng)的自動安裝
這里開始說說ks文件的大致內(nèi)容
ks.cfg文件組成大致分為3段
1.命令段:
鍵盤類型,語言,安裝方式等系統(tǒng)的配置,有必選項和可選項,如果缺少某項必選項,安裝時會中斷并提示用戶選擇此項的選項
2.軟件包段:
%packages
@groupname:指定安裝的包組
package_name:指定安裝的包
-package_name:指定不安裝的包
在安裝過程中默認安裝的軟件包,安裝軟件時會自動分析依賴關(guān)系。
3.腳本段(可選):
%pre:預(yù)安裝腳本(由于只依賴于啟動鏡像,支持的命令很少)
%post:后安裝腳本(基本支持所有命令)
而具體的ks.cfg文件的配置,我們只需要在已經(jīng)安裝好的linux的root家目錄找到anaconda_ks.cfg(這個ks文件就是在安裝linux后,根據(jù)用戶的安裝選項自動生成的)
下面的是一個樣例:
#version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512# 系統(tǒng)授權(quán)信息 # Use network installation url --url="http://192.168.52.132/centos7"# 安裝方式,如果是本地光盤安裝則是 cdrom # Use graphical install graphical # Run the Setup Agent on first boot firstboot --enable # Keyboard layouts keyboard --vckeymap=cn--xlayouts='cn'# 鍵盤樣式 # System language lang zh_CN.UTF-8 #語言
# Network information # 網(wǎng)絡(luò)配置信息,設(shè)置IP獲取方式,網(wǎng)關(guān)及DNS等信息 network --bootproto=dhcp --device=eno16777736 --ipv6=auto --activate network --hostname=localhost.localdomain
# Root password # root賬戶的信息及密碼,密碼是加密過的 rootpw --iscrypted$6$qUeqvWWOr921mWBY$h5wjwdcnIOC/FS6rCaZblKNGELwN9jrGwJZuwlrNi9OHzI.n1lxaKKrkwdN7nadXP5f2mFRDrW9D9gYStXGZu/ # System timezone # 系統(tǒng)時區(qū)與其他用戶信息及用戶密碼 timezone Asia/Shanghai --isUtc user --groups=wheel--name=pxetest --password=$6$.hgpJdCAhSMaf7yB$5GKYIAgTkLxfS1JHK5KSpN96LXhkKGFX3FbnQl0hTME3wbF1njxyezmPF/HXAtI9Bp8U6MsF3hRXlFvFfn9Nm/--iscrypted --gecos="pxetest" # System bootloader configuration # 引導(dǎo)程序相關(guān)參數(shù) bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda autopart --type=lvm # Partition clearing information # 初始化磁盤設(shè)置 clearpart --none --initlabel
# 分區(qū)設(shè)置 # part / --fstype=ext4 --size=18000 #開始分區(qū) # part swap --grow --size=1024 # repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100
# 需要安裝的系統(tǒng)模式及附加軟件包
%packages @^infrastructure-server-environment @base @compat-libraries @core @debugging @development @dns-server @file-server @ftp-server @security-tools @smart-card kexec-tools
# 后安裝腳本,Linux安裝完成后執(zhí)行的腳本可以寫在這里
# %post %end %addon com_redhat_kdump --enable --reserve-mb='auto' %end
如果覺得使用樣本的方式手工寫配置文件比較麻煩,也可以使用圖形化工具來制作ks.cfg文件。在linux中用yum安裝system-config-kickstart就行了(圖形化依賴于x-window),選項也有些限制(比如分區(qū)不能使用lvm)
參考資料:http://www.linuxdiyf.com/linux/3191.html
參考資料:http://www.linuxidc.com/Linux/2013-07/87299.htm
================================以下為一個ks.cfg的例子====================================
#version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 url --url="http://192.168.17.151/cobbler/ks_mirror/CentOS-7-x86_64" text # Firewall configuration # Run the Setup Agent on first boot firstboot --enable ignoredisk --only-use=sda keyboard --vckeymap=cn --xlayouts='cn' # System language lang zh_CN.UTF-8 # Network information network --bootproto=dhcp --device=eno16777736 --ipv6=auto --activate network --bootproto=dhcp --hostname=Client-x # Reboot after installation reboot # Root password rootpw --iscrypted $6$PumnYZm77S9o.9e5$IRSIoUF4GgOxpj.r2OY5qTxJwBz1NyUVYciFPhEyj5MqcFCOHCQd3cNpt60LIwWlXtWLXZ2tT8G51FZkYXJyW/ # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # System timezone timezone Asia/Shanghai --isUtc user --groups=wheel --name=test --password=$6$Rs9WcGhknZPweSTO$aAAyGL61HFwF8zrUG.8E6q99MUNI/rTCHWFyM7Qz3Jqf.VQskwCfhYQ8fT78WXcDprl3xSWtbDCBCJHToY3gc. --iscrypted --gecos="test" # System bootloader configuration bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda autopart --type=lvm # Partition clearing information clearpart --none --initlabel %packages @^minimal @core @debugging @development kexec-tools kexec-tools net-tools vim %end %addon com_redhat_kdump --enable --reserve-mb='auto' %end
ation bootloader –append=" crashkernel=auto" –location=mbr –boot-drive=sda autopart –type=lvm # Partition clearing information clearpart –none –initlabel %packages @^minimal @core @debugging @development kexec-tools kexec-tools net-tools vim %end %addon com_redhat_kdump –enable –reserve-mb='auto' %end