我的LINUX学习之路之十三之用脚本通过PXE安装LINUX

上次我们说了用PXE方式批量安装LINUX,今天发个脚本,当然跟上次是一样的,只是把过程写到一个脚本文件里了!当然再次感谢我师傅--阳光奋进!!!

下面贴上脚本文件的内容:

#!/bin/bash
echo "Hello,The script can do that,such as:Install and config dhcp.tftp.syslinux.vsftpd...and so on."
umount /mnt
mount /dev/cdrom /mnt
    if [ $? = 0 ];
then
    echo "cd monut ok"
else    
    echo "cd mount fail"
fi
yum install  ftp vsftpd tftp* dhcp syslinux system-config-kickstart.noarch -y
    rm -rf /etc/dhcp/dhcpd.conf
    if [ $? = 0 ] ;
then
    echo "Your Packages aready install"
else
    echo "ERROR:Please check your yum source"
fi

echo "######################## Now,configing DHCP################"

cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
    if [ $? = 0 ];
then
    echo "Your dhcp config file copy ok"
else
    echo "dhcp config file copy fail"
fi
echo "subnet 192.168.92.0 netmask 255.255.255.0 {
    range 192.168.92.168    192.168.92.186;
    option routers        192.168.92.130;
    next-server         192.168.92.130;
    filename        \"pxelinux.0\";
}">>/etc/dhcp/dhcpd.conf

    if [ $? = 0 ];
then
    echo "config dhcp ok"
else
    echo "DHCP Config faild"
fi
service dhcpd restart
    if [ $? = 0 ];
then
    echo "services start ok"
else
    echo "services start fail"
fi
echo "#######################Now,configing tftp-server###################"
mkdir -p /tftpboot/pxelinux.cfg
    if [ $? = 0 ];
then
    echo "mkdir tftpboot ok"
else
    echo "mkdir tftpboot fail"
fi
cp -rp /mnt/isolinux/* /tftpboot
cp -rp /usr/share/syslinux/pxelinux.0 /tftpboot
cp -rp /mnt/images/* /tftpboot
cp -rp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
    if [ $? = 0 ];
then
    echo "all files copy ok"
else
    echo "some files copy fail"
fi
sed -i '13c             server_args = -s /tftpboot -u nobody' /etc/xinetd.d/tftp
    if [ $? = 0 ];
then
    echo "tftp 13 ok"
else    
    echo "tftp 13 fail"
fi
sed -i '14c           disable = no' /etc/xinetd.d/tftp
    if [ $? = 0 ];
then
    echo "tfpt 18 ok"
else    
    echo "tftp 18 fail"
fi
service xinetd restart
    if [ $? = 0 ];
then
    echo "tftp start ok"
else
    echo "tftp start fail"
fi
echo "##############################Config We Vsftpd"#########################
service vsftpd restart

    if [ $? = 0 ];
then
    echo "vsftp start ok"
else
    echo "vsftp start fail"
fi
sed -i '22c append initrd=initrd.img ks=ftp://192.168.92.130/ks.cfg' /tftpboot/pxelinux.cfg/default         
    if [ $? = 0 ];
then
    echo "default 22 ok"
else    
    echo "default 22 fail"
fi
umount /mnt
echo "umonut mnt ok"
mount /dev/cdrom1 /ftp/pub

if [ $? = 0 ];
then
    echo "cd monut ok"
else    
    echo "cd mount fail"
fi
 

事先把kickstart保存的ks.cfg文件保存到/ftp下就可以了!

if[$?=0]请参看这里http://ucweb.blog.51cto.com/4042188/974482

手动安装详细过程请看http://mcmvp.blog.51cto.com/5497438/985307

你可能感兴趣的:(sed,PXE安装linux,批量安装linux,脚本安装linux)