Kickstart 不工作

Kickstart 不工作

我正在尝试创建一个 kickstart 来自动化安装过程,但当安装结束时,我检查结果时什么都没有发生。我试图通过将 read 语句放在不同的地方来调试它,看看是否一切都运行正常。似乎所有变量都在那里,但当 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

答案1

根据功能,似乎该--no-chroot选项可能导致此问题。或者,可能需要将根映像所在的路径附加到某些数据重定向的路径,通常类似于/mnt/sysimage/rootCentOS。因此,可以设置这样的变量并将其附加到必要时

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

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

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

除了记录帖子的 chrooted 部分和非 chrooted 部分是否必要之外,还可以有多个%post部分,例如Redhat 的概述如下. 在部分复杂的情况下%post,将任务拆分为多个带有单独日志的后续脚本,对于确定 kickstart 文件问题的根本原因非常有价值。

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

相关内容