一键制作无人值守安装linux系统PXE shell脚本

发布时间:2016年04月16日 阅读:860 次

 

一键制作无人值守安装linux系统PXE shell脚本

***需要把镜像文件放在/IOS/***把网段设置在192.168.4.0 不然dhcp服务起不来!!!****

#!/bin/bash

rpm -qa |grep dhcp|awk -F - '$2 !~ /[a-z]/' &> /dev/null

if [ $? -eq 0 ];then

  echo -------------dhcp服务器以存在!-------------

p() {

cat /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample > /etc/dhcp/dhcpd.conf

[  $? -eq 0 ] && echo -------------dhcpd配置文件写入成功------------- || echo -------------dhcpd配置文件写入失败-------------

sed  -i '1,46d;56,$d' /etc/dhcp/dhcpd.conf &> /dev/null

[  $? -eq 0 ] && echo -------------dhcpd配置文件修改成功------------- || echo -------------dhcpd配置文件修改失败------------

sed  -i 's/10.5.5.0/192.168.4.0/;s/255.255.255.224/255.255.255.0/;/^  range/s/10.5.5.26 10.5.5.30/192.168.4.1 192.168.4.100/;4d;6d;s/10.5.5.1/192.168.4.254/' /etc/dhcp/dhcpd.conf &> /dev/null

sed -i '$inext-server 192.168.4.1;\nfilename "pxelinux.0";' /etc/dhcp/dhcpd.conf &> /dev/null

[  $? -eq 0 ] && echo -------------dhcpd配置pxe添加成功------------- || echo -------------dhcpd配置pxe添加失败-----------

service dhcpd restart &> /dev/null

  if [ $? -eq 0 ];then

    echo "-------------dhcpd服务成功启动!-------------"

  else

    echo "-------------dhcpd服务启动失败!-------------"

    sleep 1

    exit

  fi

chkconfig dhcpd on

}

p

else

  echo -------------开始安装dhcp-------------

fi

yum install -y dhcp &> /dev/null

sleep 2

p

rpm -qa |grep tftp-server &> /dev/null

if [ $? -eq 0 ];then

 echo -------------tftp以存在-------------

o(){

chkconfig tftp  on

service xinetd start &> /dev/null

netstat -anptu |grep :69 &> /dev/null

if [ $? -eq 0 ];then

  echo -------------tftp端口开启-------------

else

   echo "tftp服务启动失败!"

   sleep 1

   exit

fi

}

o

else

 echo -------------开始安装tftp-------------

yum install -y tftp-server &> /dev/null

sleep 2

o

fi

rpm -qa |grep vsftpd &> /dev/null

if [  $? -eq 0 ];then

  echo -------------ftp以存在-------------

i(){

chkconfig vsftpd on

service vsftpd restart &>/dev/null

if [  $? -eq 0 ];then

   echo  -------------ftp启动成功-------------

else

   echo  -------------ftp启动失败-------------

   sleep 1

   exit

fi

}

i

else

  echo -------------开始安装ftp-------------

yum install -y vsftpd &> /dev/null

sleep 3

i

fi

mkdir /var/ftp/rhel 2> /dev/null

[ $? -eq 0 ] && echo -------------/var/ftp/rhel创建成功------------ || echo -------------/var/ftp/rhel存在------------

mount -o loop /ISO/CentOS-6.5-x86_64-bin-DVD1.iso /var/ftp/rhel/ 2> /dev/null

[  $? -eq 0 -o $? -eq 32 ] && echo -------------镜像文件挂载成功------------ || echo -------------挂在文件不存在-------------

yum clean all &> /dev/null

yum list &> /dev/null

if [ $? -eq 0 ];then

 echo -------------yum检测成功-------------

else

  echo -------------yum检测失败-------------

  sleep 1

  mount -o loop /ISO/CentOS-6.5-x86_64-bin-DVD1.iso /mnt

fi

rpm -qa|grep syslinux &> /dev/null

if [ $? -eq 0 ];then

  echo -------------网卡引导器以存在-------------

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

else

  echo -------------开始安装网卡引导-------------

yum install -y syslinux &> /dev/null

sleep 2

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

fi

 

cp /var/ftp/rhel/isolinux/initrd.img /var/lib/tftpboot/  2> /dev/null

[ $? -eq 0 ] && echo -------------引导程序拷贝成功!-------------  || echo -------------引导程序以存在!-------------

cp /var/ftp/rhel/isolinux/vmlinuz /var/lib/tftpboot/ 2> /dev/null

[ $? -eq 0 ] && echo -------------微内核文件拷贝成功!-------------  || echo -------------微内核文件存在!--------------

mkdir /var/lib/tftpboot/pxelinux.cfg 2> /dev/null

[ $? -eq 0 ] && echo  -------------pxelinux.cfg目录创建成功------------- || echo -------------pxelinux.cfg目录存在!-------------

cp /CentOS/isolinux/isolinux.cfg /var/lib/tftpboot/default 2> /dev/null

[  $? -eq 0 ] && echo -------------菜单文件拷贝成功------------- || echo -------------菜单文件存在-------------

sed -i '$r /var/ftp/rhel/isolinux/isolinux.cfg' /var/lib/tftpboot/pxelinux.cfg/default &> /dev/null

[ $? -eq 0 ] && echo -------------菜单文件写入成功------------- || echo -------------菜单文件写入出错-------------

sed -i '1s/vesamenu.c32/linux/;2,17d;23,38d;19d' /var/lib/tftpboot/pxelinux.cfg/default 2> /dev/null

[  $? -eq 0 ] && echo -------------菜单文件修改成功------------- || echo -------------菜单文件修改成功-------------

sed  -i '$aks=ftp://rhel/ks.cfg' /var/lib/tftpboot/pxelinux.cfg/default 2> /dev/null

[ $? -eq 0 ] && echo -------------ks文件路径加入成功------------- || echo -------------ks文件加入失败!-------------

yum install -y system-config-kickstart &> /dev/null 2> /dev/null

sleep 2

rpm -qa |grep system-config-kickstart &> /dev/null 2> /dev/null

[  $? -eq 0 ] && echo -------------kickstartan安装成功------------- || echo -------------kickstart工具存在!-------------

echo -------------无人值守环境搭建好了!-------------

****************************************************


Tag:一键制作无人值守安装linux系统PXE shell脚本
相关文章

发表评论: