Kickstart无法正常工作

我试图创build一个kickstart来自动安装过程,但是当安装结束时,我检查看看结果什么都没有发生。 我试图通过将读取语句放在不同的地方来查看是否一切正常。 看来所有的variables都在那里,但是当setMask函数执行时,它重新启动。 任何帮助将不胜感激。

%pre #!/bin/sh curTTY=`tty` exec < $curTTY > $curTTY 2> $curTTY echo 'Specify the hostname to assign: '; read hostname echo -n "Enter ip of ips (separated by spaces): "; read ip echo -n "Enter ipv6 address: "; read ipv6 #Saving data echo $hostname > /tmp/hostname echo $ip > /tmp/ip echo $ipv6 > /tmp/ipv6 %end %post --nochroot #!/bin/sh curTTY=`tty` exec < $curTTY > $curTTY 2> $curTTY #Transfering data to be used in the post phase ip=$(cat /tmp/ip) ipv6=$(cat /tmp/ipv6) hostname=$(cat /tmp/hostname) numips=$(echo $ip | wc -w) numberOfIpAddresses () { if [ numips > 1 ]; then ips=$(echo $ip | awk '{$1=""; print}' | cut -c 2-) ip=$(echo $ip | awk '{print $1}') fi } ipv6GW () { echo $ipv6 | awk -F":" '{$(NF--); print}' | while read $output do do gwv6="$gwv6:$output" done gwv6="$gwv6:1" } numberOfIpAddresses ipv6GW setGateway () { case prefix in 22|23|24) gateway=$(echo $ip | cut -d. -f1-3)".1" ;; 25) if [ firstOcted -ne 65 ] || [ thirdOcted -eq 161 ]; then gateway=$(echo $ip | cut -d. -f1-3)".129" elif [ thirdOcted -eq 162 ]; then gateway=$(echo $ip | cut -d. -f1-3)".129" elif [ thirdOcted -eq 162 ]; then gateway=$(echo $ip | cut -d. -f1-3)".1" fi ;; 26) if [ firstOcted -ne 64 ]; then gateway=$(echo $ip | cut -d. -f1-3)".65" elif [ firstOcted -ne 69 ]; then gateway=$(echo $ip | cut -d. -f1-3)".129" fi ;; esac } setMask () { #Extracting necesery octeds firstOcted=$(echo $ip | cut -d. -f1) thirdOcted=$(echo $ip | cut -d. -f3) case firstOcted in 8) prefix=24 setGateway 64) echo "Aqui en setMask opcion 64" read algo if [ thirdOcted -ne 7 ] && [ thirdOcted -ne 19 ] && [ thirdOcted -ne 26 ] && [ thirdOcted -ne 30 ] && [ thirdOcted -ne 31 ]; then prefix=24 setGateway elif [ thirdOcted -ne 7 ] || [ thirdOcted -ne 19 ]; then prefix=25 setGateway elif [ thirdOcted -ne 30 ] || [ thirdOcted -ne 31 ]; then prefix=26 setGateway fi setGateway fi ;; 65) if [ thirdOcted -ge 164 ] && [ thirdOcted -le 175 ]; then prefix=22 setGateway elif [ thirdOcted -ge 176 ] && [ thirdOcted -le 185 ]; then prefix=23 setGateway elif [ thirdOcted -ge 161 ] && [ thirdOcted -le 162 ]; then prefix=25 setGateway elif [ thirdOcted -ge 187 ] && [ thirdOcted -le 190 ]; then prefix=24 setGateway fi ;; 69) if [ thirdOcted -ge 116 ] && [ thirdOcted -le 123 ]; then prefix=22 setGateway elif [ thirdOcted -ge 110 ] && [ thirdOcted -le 115 ]; then prefix=24 setGateway elif [ thirdOcted -ge 98 ] && [ thirdOcted -le 109 ]; then prefix=24 setGateway fi ;; *) echo "The ip was wrongly typed" read ip echo -n "Type the prefix to use: " read prefix echo -n "Type the gateway: " read gateway numberOfIpAddresses ipv6GW ;; esac } setMask counter=0 ls /sys/class/net/ | grep ^e | while read output; do echo 'SUBSYSTEM=="net", ACTION=="add", KERNEL=="'$output'", NAME="eth'$counter'"' \ >> /etc/udev/rules.d/70-persistent-net.rules; ((counter++)); done if [ -f /etc/debian_version ]; then else echo DEVICE=eth0 >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo BOOTPROTO=none >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo ONBOOT=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo PREFIX=$prefix >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo IPADDR=$ip >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo GATEWAY=$gateway >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo DNS1=69.60.123.201 >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo DNS2=69.60.125.254 >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo #IPv6 Conf >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo IPV6INIT=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo IPV6ADDR=$ipv6 >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo IPV6_DEFAULTGW=$gwv6 >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo IPV6ADDR=$ipv6 >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo IPV6_DEFAULTGW=$gwv6 >> /etc/sysconfig/network-scripts/ifcfg-eth0 if [ -n ips ]; then counter=0 for subip in ips; do cat ifcfg-eth0 | sed 's/DEVICE=eth0/DEVICE=eth0:$counter/' | sed 's/IPADDR=$ip/IPADDR=$subip/' >> ifcfg-eth0:$counter done %end 

根据函数,在这种情况下,– --no-chroot选项可能会导致问题。 或者,根映像所在的path可能需要附加到某些数据被redirect的path,通常是像CentOS的/mnt/sysimage/root 。 所以可以像这样设置一个variables,并在必要时添加它

 rootfs=/mnt/sysimage/root ... echo DEVICE=eth0 >> $rootfs/etc/sysconfig/network-scripts/ifcfg-eth0 ... 

除了删除--no-chroot选项以外,添加日志选项可能有助于获取有关失败的更多信息。

 %post --log=/path/to/post/install/log.log 

除了需要loggingchroot和non-chrooted部分的post以外,还可以有多个%post部分, 如Redhat所述 。 如果复杂的%post部分将任务拆分为多个具有单独日志的post脚本,对于确定kickstart文件问题的根本原因非常有用。

除了%post之外,如果你可以访问文件服务器或者某种共享存储,你可以编写包含在post中使用的函数的脚本,然后在post部分挂载/复制它们并调用相关函数。 这将使您有机会testing一些脚本,而无需在debugging时不断重新安装kickstart文件,这样可以节省大量时间。