一键制作kickstart无人值守安装环境

前提:插上光盘,eth0有IP,安装完后root密码:redhat


脚本:


#!/bin/sh
#
service iptables save
service iptables stop
setenforce 0
ip=`ifconfig eth0|grep -o "addr:[^[:space:]]\{1,\}"|cut -d: -f2`
ifconfig eth0 $ip/16 up
#read -t 5 -p "Enter your ip addr: " ip
if [ ! -d /meida/Packages ] ;then
mount /dev/cdrom /media &>/dev/null
fi
tar jcvf /etc/yum.repos.d/repo.tar.bz2 /etc/yum.repos.d/* &>/dev/null
rm -rf /etc/yum.repos.d/*.repo
cat >/etc/yum.repos.d/centos.repo <<EOF
[xiaoyu]
name=centos
baseurl=file:///media
enaled=1
gpgcheck=0
cost=100
EOF
echo "install packages.............."
yum -y install httpd tftp-server dhcp syslinux >/dev/null
echo "configuration tftp .............."
# tftp
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /media/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/
cp /media/isolinux/{vesamenu.c32,splash.jpg,boot.msg} /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /media/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
if grep ".img$" /var/lib/tftpboot/pxelinux.cfg/default &>/dev/null;then
sed -i "s/.img$/.img ks=http:\/\/$ip\/ks.cfg/" /var/lib/tftpboot/pxelinux.cfg/default
fi
# dhcp
echo "configuration dhcp  .............."
rm /etc/dhcp/dhcpd.conf -f
echo "defaule dhcp network  `echo $ip |cut -d'.' -f1,2`.0.0"
read -t 2 -p "your dhcp network: " dhcp
dhcp=${dhcp:-`echo $ip |cut -d'.' -f1,2`.0.0}
cat >/etc/dhcp/dhcpd.conf <<EOF
subnet  `echo $dhcp |cut -d'.' -f1,2`.0.0  netmask 255.255.0.0 {
  range `echo $dhcp |cut -d'.' -f1,2`.0.2 `echo $dhcp |cut -d'.' -f1,2`.255.254;
        next-server $ip;
        filename "pxelinux.0";
}
EOF
# http
echo "configuration web .............."
mkdir /var/www/html/centos
mount --bind /media /var/www/html/centos
cat >/var/www/html/ks.cfg <<EOF
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://$ip/centos"
# Root password
rootpw --iscrypted \$1\$kfLaJM67\$LIlVx1fz9kAyYXk.XtnA3.
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --append="crashkernel=auto crashkernel=auto rhgb rhgb quiet quiet" --location=mbr --driveorder="sda"
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part pv.008002 --size=61440
volgroup vg0 --pesize=8192 pv.008002
logvol / --fstype=ext4 --name=root --vgname=vg0 --size=20480
logvol swap --name=swap --vgname=vg0 --size=2048
logvol /usr --fstype=ext4 --name=usr --vgname=vg0 --size=10240
logvol /var --fstype=ext4 --name=var --vgname=vg0 --size=20480
%packages
@base
#@chinese-support
#@client-mgmt-tools
@core
#@desktop-platform-devel
#@development
#@network-file-system-client
#@perl-runtime
#@server-platform-devel
#-ibus-table-cangjie
#-ibus-table-erbi
#-ibus-table-wubi
%end
EOF
service dhcpd restart
chkconfig tftp on
service xinetd restart
service httpd restart




说明:

1,安装出现下面情况说明,磁盘空间不够大

解决方案:1,换个大的。2,调整脚本的分区那几行改小点

wKioL1M_mzyiP0BYAAAXo_MGRBk577.png


2,安装出现下面情况说明,客户机没有分到IP,如果是用的这个脚本应该是不会的

  除非eth0原先没有IP

解决方案:给eth0一个IP,然后重新执行脚本

wKiom1M_m5jyO8eGAAAkX8fWOR8942.png



3,安装出现下面情况说明,分配出去的IP和服务器不在同一网段

解决方案:在填“your dhcp network:” 的时候就不要填了保持默认,重新执行脚本

wKioL1M_m4TRfbDMAAAfaQ0PtUk897.png

这个图是因为服务器的 netmask 为 255.255.255.0 分出去的却是255.255.0.0



在centos6.5上测试过可行,每次配置挺麻烦的,收藏一下吧


你可能感兴趣的:(一键制作kickstart无人值守安装环境)