ks.cfg文件:又稱Kickstart文件,主要用于Linux系統(tǒng)的自動(dòng)化安裝。
在CentOS系統(tǒng)中 /root/anaconda-ks.cfg就是一個(gè)ks.cfg文件,它指明了當(dāng)前系統(tǒng)預(yù)安裝環(huán)境時(shí)的設(shè)置內(nèi)容。
linux安裝大致可以分為2個(gè)階段
第一階段:linux的預(yù)安裝環(huán)境
此階段是linux的預(yù)安裝環(huán)境,提供linux安裝選項(xiàng)的一個(gè)接口,可以將它比作是windows中的PE環(huán)境
第二階段:自動(dòng)安裝過(guò)程
該階段系統(tǒng)會(huì)按照第一階段設(shè)定的參數(shù)自動(dòng)安裝,
第一階段有兩種模式:交互式和非交互式
交互式就和普通安裝一樣,按照提示選擇選項(xiàng)一步步的安裝
非交互式則通過(guò)讀取kickstart文件的配置,進(jìn)行自動(dòng)安裝,這和window中的無(wú)人值守安裝差不多的,這個(gè)文件即是ks.cfg文件(相當(dāng)于window中的wi2k3.sif應(yīng)答文件)
而在安裝linux過(guò)程中,獲取ks.cfg文件的方式有多種,如直接在cdrom中獲取,常見(jiàn)的形式還有http,ftp,nfs等方式。
在使用ks.cfg之前,需要先引導(dǎo)啟動(dòng)環(huán)境
引導(dǎo)方式有很多,cdrom,usb,PXE等。
在引導(dǎo)進(jìn)入第一階段后,即可通過(guò)讀取ks.cfg來(lái)進(jìn)行系統(tǒng)的自動(dòng)安裝
這里開(kāi)始說(shuō)說(shuō)ks文件的大致內(nèi)容
ks.cfg文件組成大致分為3段
1.命令段:
鍵盤(pán)類型,語(yǔ)言,安裝方式等系統(tǒng)的配置,有必選項(xiàng)和可選項(xiàng),如果缺少某項(xiàng)必選項(xiàng),安裝時(shí)會(huì)中斷并提示用戶選擇此項(xiàng)的選項(xiàng)
2.軟件包段:
%packages
@groupname:指定安裝的包組
package_name:指定安裝的包
-package_name:指定不安裝的包
在安裝過(guò)程中默認(rèn)安裝的軟件包,安裝軟件時(shí)會(huì)自動(dòng)分析依賴關(guān)系。
3.腳本段(可選):
%pre:預(yù)安裝腳本(由于只依賴于啟動(dòng)鏡像,支持的命令很少)
%post:后安裝腳本(基本支持所有命令)
而具體的ks.cfg文件的配置,我們只需要在已經(jīng)安裝好的linux的root家目錄找到anaconda_ks.cfg(這個(gè)ks文件就是在安裝linux后,根據(jù)用戶的安裝選項(xiàng)自動(dòng)生成的)
下面的是一個(gè)樣例:
#version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512# 系統(tǒng)授權(quán)信息 # Use network installation url --url="http://192.168.52.132/centos7"# 安裝方式,如果是本地光盤(pán)安裝則是 cdrom # Use graphical install graphical # Run the Setup Agent on first boot firstboot --enable # Keyboard layouts keyboard --vckeymap=cn--xlayouts='cn'# 鍵盤(pán)樣式 # System language lang zh_CN.UTF-8 #語(yǔ)言
# 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賬戶的信息及密碼,密碼是加密過(guò)的 rootpw --iscrypted$6$qUeqvWWOr921mWBY$h5wjwdcnIOC/FS6rCaZblKNGELwN9jrGwJZuwlrNi9OHzI.n1lxaKKrkwdN7nadXP5f2mFRDrW9D9gYStXGZu/ # System timezone # 系統(tǒng)時(shí)區(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 # 初始化磁盤(pán)設(shè)置 clearpart --none --initlabel
# 分區(qū)設(shè)置 # part / --fstype=ext4 --size=18000 #開(kāi)始分區(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í)行的腳本可以寫(xiě)在這里
# %post %end %addon com_redhat_kdump --enable --reserve-mb='auto' %end
如果覺(jué)得使用樣本的方式手工寫(xiě)配置文件比較麻煩,也可以使用圖形化工具來(lái)制作ks.cfg文件。在linux中用yum安裝system-config-kickstart就行了(圖形化依賴于x-window),選項(xiàng)也有些限制(比如分區(qū)不能使用lvm)
參考資料:http://www.linuxdiyf.com/linux/3191.html
參考資料:http://www.linuxidc.com/Linux/2013-07/87299.htm
================================以下為一個(gè)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)的自動(dòng)化安裝。
在CentOS系統(tǒng)中 /root/anaconda-ks.cfg就是一個(gè)ks.cfg文件,它指明了當(dāng)前系統(tǒng)預(yù)安裝環(huán)境時(shí)的設(shè)置內(nèi)容。
linux安裝大致可以分為2個(gè)階段
第一階段:linux的預(yù)安裝環(huán)境
此階段是linux的預(yù)安裝環(huán)境,提供linux安裝選項(xiàng)的一個(gè)接口,可以將它比作是windows中的PE環(huán)境
第二階段:自動(dòng)安裝過(guò)程
該階段系統(tǒng)會(huì)按照第一階段設(shè)定的參數(shù)自動(dòng)安裝,
第一階段有兩種模式:交互式和非交互式
交互式就和普通安裝一樣,按照提示選擇選項(xiàng)一步步的安裝
非交互式則通過(guò)讀取kickstart文件的配置,進(jìn)行自動(dòng)安裝,這和window中的無(wú)人值守安裝差不多的,這個(gè)文件即是ks.cfg文件(相當(dāng)于window中的wi2k3.sif應(yīng)答文件)
而在安裝linux過(guò)程中,獲取ks.cfg文件的方式有多種,如直接在cdrom中獲取,常見(jiàn)的形式還有http,ftp,nfs等方式。
在使用ks.cfg之前,需要先引導(dǎo)啟動(dòng)環(huán)境
引導(dǎo)方式有很多,cdrom,usb,PXE等。
在引導(dǎo)進(jìn)入第一階段后,即可通過(guò)讀取ks.cfg來(lái)進(jìn)行系統(tǒng)的自動(dòng)安裝
這里開(kāi)始說(shuō)說(shuō)ks文件的大致內(nèi)容
ks.cfg文件組成大致分為3段
1.命令段:
鍵盤(pán)類型,語(yǔ)言,安裝方式等系統(tǒng)的配置,有必選項(xiàng)和可選項(xiàng),如果缺少某項(xiàng)必選項(xiàng),安裝時(shí)會(huì)中斷并提示用戶選擇此項(xiàng)的選項(xiàng)
2.軟件包段:
%packages
@groupname:指定安裝的包組
package_name:指定安裝的包
-package_name:指定不安裝的包
在安裝過(guò)程中默認(rèn)安裝的軟件包,安裝軟件時(shí)會(huì)自動(dòng)分析依賴關(guān)系。
3.腳本段(可選):
%pre:預(yù)安裝腳本(由于只依賴于啟動(dòng)鏡像,支持的命令很少)
%post:后安裝腳本(基本支持所有命令)
而具體的ks.cfg文件的配置,我們只需要在已經(jīng)安裝好的linux的root家目錄找到anaconda_ks.cfg(這個(gè)ks文件就是在安裝linux后,根據(jù)用戶的安裝選項(xiàng)自動(dòng)生成的)
下面的是一個(gè)樣例:
#version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512# 系統(tǒng)授權(quán)信息 # Use network installation url --url="http://192.168.52.132/centos7"# 安裝方式,如果是本地光盤(pán)安裝則是 cdrom # Use graphical install graphical # Run the Setup Agent on first boot firstboot --enable # Keyboard layouts keyboard --vckeymap=cn--xlayouts='cn'# 鍵盤(pán)樣式 # System language lang zh_CN.UTF-8 #語(yǔ)言
# 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賬戶的信息及密碼,密碼是加密過(guò)的 rootpw --iscrypted$6$qUeqvWWOr921mWBY$h5wjwdcnIOC/FS6rCaZblKNGELwN9jrGwJZuwlrNi9OHzI.n1lxaKKrkwdN7nadXP5f2mFRDrW9D9gYStXGZu/ # System timezone # 系統(tǒng)時(shí)區(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 # 初始化磁盤(pán)設(shè)置 clearpart --none --initlabel
# 分區(qū)設(shè)置 # part / --fstype=ext4 --size=18000 #開(kāi)始分區(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í)行的腳本可以寫(xiě)在這里
# %post %end %addon com_redhat_kdump --enable --reserve-mb='auto' %end
如果覺(jué)得使用樣本的方式手工寫(xiě)配置文件比較麻煩,也可以使用圖形化工具來(lái)制作ks.cfg文件。在linux中用yum安裝system-config-kickstart就行了(圖形化依賴于x-window),選項(xiàng)也有些限制(比如分區(qū)不能使用lvm)
參考資料:http://www.linuxdiyf.com/linux/3191.html
參考資料:http://www.linuxidc.com/Linux/2013-07/87299.htm
================================以下為一個(gè)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