kickstart主要用于系统的自动安装,也可以通过系统引导后自动执行脚本,自动安装系,在多系统同配置的安装环境中,大大节约了时间,这篇主要说说文本中的各命令参数。
在我们的系统安装完成后,在家目录下有一个叫做anaconda-ks.cfg的文件,这个文件记录了系统安装时的各项设置,如果我们要自己做脚本的话可以参考这个文件,然后进行修改,当然,你也可以通过图形的kickstart配置来进行修改,图形的稍后再说。
kickstart分为三个部分组成:
1.命令段:比如语言啊,键盘类型啊,时区啊等等,命令段分为必须指定命令和可选命令。如果可选命令不指定正确,可能在自动安装的过程中停止并询问。
2.软件包选择段:选择我们要安装的软件包或组,组用@打头。
3.脚本段:分为预安装脚本(系统完成安装之前执行 以%pre开头) 和 安装后执行脚本(系统安装完成后执行 以%post表示)
必备的命令,命令段:
keyboard(键盘类型)例: keyboard us (美式键盘)
lang(语言) 例:lang en_US.UTF-8(美国英语和万国码)
timezone(时区) 例:timezone Asia/shanghai
rootpw(管理员密码)例: rootpw redhat(root密码为redhat)参数:--iscryrted --密码加密
authconfig(认证方式,如用到了NiS,LDAP等,可以设置,参数较多,这里没有用到就不说了)
bootloader(引导程序) 例:直接加上bootloader就行 (安装bootloader)
可选:
install | upgrade(安装或升级) (支持安装方式,可以有cdrom.harddrive,nfs,http或ftp)
例子:ur l --url=http://xx/xx如果是光盘直接输入cdrom就可以了
user(创建用户)参数:--name= --groups= --homedir= --password= --uid= 等
clearpart(清除分区)例:clearpart --all --initlabel
参数:--all (清除所有分区) --linux(清除所有Linux分区) --none(不清除任何分区,使用空间的,默认为此选项) --initlabel(初始化磁盘,如果是一个新的硬盘会提示没有有效分区表,是否继续,这里直接使用这个选项进行初始化)
firewall(防火墙) 例:firewall --disable
参数:--enable 例:firewall --enable --trust=eth0 --ssh|--port=22(允许)
--disable
selinux(Linux的访问控制)
参数:--disable --permissive --enforcing
firsboot(在安装完图形重启后还需要进行配置的那个界面)例:firsboot --disable
参数:--enable --disable
reboot(安装完重启,也可以使用halt关机) 例子:reboot --直接输入就行
text | graphical(安装界面是文本模式还是图形模式,不输入这个参数,默认为图形但要求内存大于512MB)
autopart(自动分区,如果想手动看下面参数)
part(划分分区)
例子:
part /boot --fstype=ext4 --size=200
创建一个boot分区,类型为ext4 大小为200M(MB为默认单位)
part swap --size=2000
创建一个swap分区
part pv.pvtest --size=40000
创建一个名为pvtest的pv 大小为40000MB
可以用--encrypted启动加密 --label指定标签
volgroup(创建卷组)
例子:volgroup vgtest --pesize=32768 pvtest
创建一个名为vgtest的vg Pe大小为32MB(默认单位为K)Vg内的Pv为pvtest
logvol(创建lv)
logvol / --fstype=ext3 --name=root --vgname=vgtest --size=10000
创建一个 / 类型为ext3 lv的名字为root, 从vgtest上创建 大小为10000MB
network(配置网络属性)
例 子:network --bootproto=static|dhcp --onboot=yes|no --ip=x.x.x.x --netmask=x.x.x.x --gateway=x.x.x.x --nameserver=x.x.x.x,x.x.x.x --hostname=test.kickstart.com --device=eth0|eth1
这是基本的网络配置文件参数,不解释了。
zerombr(重置mbr信息,如果原来mbr有信息会被清除)
安装软件包部分:
以%Packages开头以%end结束
@base
@x11
httpd
vsftp
@为一个软件组包 没有@符号的 为直接安装的软件
脚本部分:
以%pre或%post开头
直接把脚本内容复制上去即可。
# Kickstart file automatically generated by anaconda. #version=DEVEL install url --url=http://192.168.3.110/cblr/links/centos6.5-system-x86_64 lang en_US.UTF-8 keyboard us network --onboot yes --device eth0 --bootproto static --ip 192.168.3.140 --netmask 255.255.255.0 --gateway 192.168.3.1 --hostname kaibin.test3.com rootpw --iscrypted $1$zuoliao$ucZsjnNnYeC1ddo9O19ei0 # Reboot after installation reboot firewall --service=ssh authconfig --useshadow --enablemd5 selinux --disabled timezone America/New_York bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" # The following is the partition information you requested # Note that any partitions you deleted are not expressed # here so unless you clear all partitions first, this is # not guaranteed to work #clearpart --all --initlabel #part /boot --fstype=ext4 --size=500 #part pv.008002 --grow --size=1 #volgroup vg_kaibin --pesize=4096 pv.008002 #logvol / --fstype=ext4 --name=lv_root --vgname=vg_kaibin --grow --size=1024 --maxsize=51200 #logvol swap --name=lv_swap --vgname=vg_kaibin --grow --size=1984 --maxsize=1984 repo --name="CentOS" --baseurl=http://192.168.3.110/cblr/links/centos6.5-system-x86_64 --cost=100 repo --name="source-1" --baseurl=http://192.168.3.110/cobbler/ks_mirror/centos6.5-system-x86_64 --cost=1000 %packages @Base @Core %end %pre set -x -v exec 1>/tmp/ks-pre.log 2>&1 # Once root's homedir is there, copy over the log. while : ; do sleep 10 if [ -d /mnt/sysimage/root ]; then cp /tmp/ks-pre.log /mnt/sysimage/root/ logger "Copied %pre section log to system" break fi done & wget "http://192.168.3.110/cblr/svc/op/trig/mode/pre/system/test_001" -O /dev/null # Start pre_install_network_config generated code # generic functions to be used later for discovering NICs mac_exists() { [ -z "$1" ] && return 1 if which ip 2>/dev/null >/dev/null; then ip -o link | grep -i "$1" 2>/dev/null >/dev/null return $? elif which esxcfg-nics 2>/dev/null >/dev/null; then esxcfg-nics -l | grep -i "$1" 2>/dev/null >/dev/null return $? else ifconfig -a | grep -i "$1" 2>/dev/null >/dev/null return $? fi } get_ifname() { if which ip 2>/dev/null >/dev/null; then IFNAME=$(ip -o link | grep -i "$1" | sed -e 's/^[0-9]*: //' -e 's/:.*//') elif which esxcfg-nics 2>/dev/null >/dev/null; then IFNAME=$(esxcfg-nics -l | grep -i "$1" | cut -d " " -f 1) else IFNAME=$(ifconfig -a | grep -i "$1" | cut -d " " -f 1) if [ -z $IFNAME ]; then IFNAME=$(ifconfig -a | grep -i -B 2 "$1" | sed -n '/flags/s/:.*$//p') fi fi } # Start of code to match cobbler system interfaces to physical interfaces by their mac addresses # Start eth0 # Configuring eth0 (00:0C:29:44:C0:96) if mac_exists 00:0C:29:44:C0:96 then get_ifname 00:0C:29:44:C0:96 echo "network --device=$IFNAME --bootproto=static --ip=192.168.3.140 --netmask=255.255.255.0 --gateway=192.168.3.1 --hostname=kaibin.test3.com" >> /tmp/pre_install_network_config fi # End pre_install_network_config generated code # Enable installation monitoring %end %post --nochroot set -x -v exec 1>/mnt/sysimage/root/ks-post-nochroot.log 2>&1 %end %post set -x -v exec 1>/root/ks-post.log 2>&1 # Start yum configuration wget "http://192.168.3.110/cblr/svc/op/yum/system/test_001" --output-document=/etc/yum.repos.d/cobbler-config.repo # End yum configuration # Start post_install_network_config generated code # create a working directory for interface scripts mkdir /etc/sysconfig/network-scripts/cobbler cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/cobbler/ # set the gateway in the network configuration file grep -v GATEWAY /etc/sysconfig/network > /etc/sysconfig/network.cobbler echo "GATEWAY=192.168.3.1" >> /etc/sysconfig/network.cobbler rm -f /etc/sysconfig/network mv /etc/sysconfig/network.cobbler /etc/sysconfig/network # set the hostname in the network configuration file grep -v HOSTNAME /etc/sysconfig/network > /etc/sysconfig/network.cobbler echo "HOSTNAME=kaibin.test3.com" >> /etc/sysconfig/network.cobbler rm -f /etc/sysconfig/network mv /etc/sysconfig/network.cobbler /etc/sysconfig/network # Also set the hostname now, some applications require it # (e.g.: if we're connecting to Puppet before a reboot). /bin/hostname kaibin.test3.com # Start configuration for eth0 echo "DEVICE=eth0" > /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0 echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0 echo "HWADDR=00:0C:29:44:C0:96" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0 IFNAME=$(ip -o link | grep -i '00:0C:29:44:C0:96' | sed -e 's/^[0-9]*: //' -e 's/:.*//') if [ -f "/etc/modprobe.conf" ] && [ $IFNAME ]; then grep $IFNAME /etc/modprobe.conf | sed "s/$IFNAME/eth0/" >> /etc/modprobe.conf.cobbler grep -v $IFNAME /etc/modprobe.conf >> /etc/modprobe.conf.new rm -f /etc/modprobe.conf mv /etc/modprobe.conf.new /etc/modprobe.conf fi echo "TYPE=Ethernet" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0 echo "BOOTPROTO=none" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0 echo "IPADDR=192.168.3.140" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0 echo "NETMASK=255.255.255.0" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0 # End configuration for eth0 sed -i 's/ONBOOT=yes/ONBOOT=no/g' /etc/sysconfig/network-scripts/ifcfg-eth* rm -f /etc/sysconfig/network-scripts/ifcfg-eth0 mv /etc/sysconfig/network-scripts/cobbler/* /etc/sysconfig/network-scripts/ rm -r /etc/sysconfig/network-scripts/cobbler if [ -f "/etc/modprobe.conf" ]; then cat /etc/modprobe.conf.cobbler >> /etc/modprobe.conf rm -f /etc/modprobe.conf.cobbler fi # End post_install_network_config generated code # Start download cobbler managed config files (if applicable) # End download cobbler managed config files (if applicable) # Start koan environment setup echo "export COBBLER_SERVER=192.168.3.110" > /etc/profile.d/cobbler.sh echo "setenv COBBLER_SERVER 192.168.3.110" > /etc/profile.d/cobbler.csh # End koan environment setup # begin Red Hat management server registration # not configured to register to any Red Hat management server (ok) # end Red Hat management server registration # Begin cobbler registration # skipping for system-based installation # End cobbler registration # Enable post-install boot notification # Start final steps wget "http://192.168.3.110/cblr/svc/op/ks/system/test_001" -O /root/cobbler.ks wget "http://192.168.3.110/cblr/svc/op/trig/mode/post/system/test_001" -O /dev/null # End final steps %end