KickStart脚本
#!/bin/bash
#declare var
yum_ins="yum -y install"
sys_res="systemctl restart"
#1.配置dhcp
dhcp_cfg() {
#declare dhcp_var
dhcp_path="/etc/dhcp"
dhcp_conf=$dhcp_path/dhcpd.conf
# 网段
net_seg="192.168.152.0"
# 子网掩码
net_mask="255.255.255.0"
#地址池
ran="192.168.152.201 192.168.152.204"
# 网关
op_router="192.168.152.2"
# tftp主机
next_ser="192.168.152.200"
$yum_ins dhcp
#解决cp覆盖时强制询问
rm -rf $dhcp_conf
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example $dhcp_conf
#去除注释和空行
sed -i "/^$/d;/^#/d" $dhcp_conf
#将内容存入中转文件
cat $dhcp_conf | awk 'NR<6{print $0}' >$dhcp_path/transfer
#将中转内容转回并删除
cat $dhcp_path/transfer >$dhcp_conf
rm -rf $dhcp_path/transfer
#配置dhcpd.conf文件
cat >>$dhcp_conf <<EOF
subnet $net_seg netmask $net_mask {
range $ran;
option routers $op_router;
next-server $next_ser;
filename "pxelinux.0";
}
EOF
#重启dhcp
if $sys_res dhcpd &>/dev/null; then
echo "dhcp启动完成"
else
echo "dhcp启动失败"
exit 1
fi
}
#2.配置tftp
tftp_cfg() {
$yum_ins tftp-server xinetd lsof
sed -i.bak '14s/yes/no/' /etc/xinetd.d/tftp
$sys_res xinetd
echo "配置tftp完成"
}
#3.配置syslinux
sys_kick() {
#路径
pxe_path="/var/lib/tftpboot"
pxe_cfg="$pxe_path/pxelinux.cfg"
pxe_def="$pxe_cfg/default"
$yum_ins syslinux system-config-kickstart
mkdir $pxe_cfg
cp /usr/share/syslinux/pxelinux.0 $pxe_path
cp /mnt/cdrom/images/pxeboot/* $pxe_path
cp /mnt/cdrom/isolinux/isolinux.cfg $pxe_def
sed -i '1s/vesamenu.c32/linux/' $pxe_def
sed -i '64a\ append initrd=initrd.img inst.repo=ftp://192.168.152.200/pub inst.ks=ftp://192.168.152.200/ks.cfg' $pxe_def
sed -i '64d' $pxe_def
echo "配置syslinux完成"
}
#4.安装vsftpd
ins_ftp() {
if $yum_ins vsftpd &>/dev/null; then
if $sys_res vsftpd &>/dev/null; then
echo "安装vsftpd完成"
else
echo "重启vsftpd失败"
exit 1
fi
else
echo "安装vsftp失败"
exit 1
fi
}
#5.准备执行Kickstart
use_kick() {
mount /dev/sr0 /var/ftp/pub/
echo "之前就将yum仓库命名为development",此处无需更改
cat <<EOF >/etc/yum.repos.d/development.repo
[development]
name=origin
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=0
EOF
yum clean all
yum repolist
echo "配置development yum仓库完成"
#安装图形化
$yum_ins xorg-x11-xauth
#安装语言包
yum -y groupinstall "fonts"
echo "kickstart最后准备完成"
}
#执行Kickstart
echo "1.开始配置dhcp"
dhcp_cfg
echo "2.开始配置tftp"
tftp_cfg
echo "3.开始配置syslinux"
sys_kick
echo "4.安装vsftpd"
ins_ftp
echo "5.执行kickstart"
use_kick
echo "final: 开始kickstart"
echo "接下来需要重连xshell"
echo "通过system-config-kickstart命令进入配置图形化界面"
报错
-
使用kickstart无人化安装时报错ERR anaconda.stdout: Kickstart file /run/install/ks.cfg is missing
/var/lib/tftpboot/pxelinux.cfg/default中inst.ks=ftp://192.168.152.200/ks.cfg出错,ftp忘记写
-
kickstart 由于下载软件包信息失败,软件包选择被禁止
yum仓库名称没有改为development
-
kickstart 在图形化安装界面停止
在生成ks.cfg文件时进入进行更改,紧急关闭生成了swap交换文件,将交换文件删除
-
Entering emeryency mode. Exit the shell to continue
/var/lib/tftpboot下文件有问题
没有挂载sr0 mount /dev/sr0 /var/lib/tftpboot
-
dracut-initqueue-timeout
没有挂载sr0 mount /dev/sr0 /var/lib/tftpboot
-
命令行卡在"#/"
内存不够