centos自动安装镜像脚本

#!/bin/bash
###########################################################################################################################author:wen.lu
#email:
##########################################################################################################################
####parameters: Cdrom_name_dir   Ks_name_dir  Tmp_dir Mount_dir

auto_cd()
{
       Cdrom_name_dir=/home/remotecard/RHEL6.4_X86_64_AutoInstall_DVD_`date +'%Y%m%d'`.iso
       Source_file=/home/remotecard/rhel-server-6.4-x86_64-dvd.iso
       Ks_name_dir=ks.cfg
       Tmp_dir=/tmp/rhel6.4
       Label=RHEL6.4_X86_64_AutoInstall_DVD
       Mount_dir=/mnt
       if [ -d ${Tmp_dir} ]
       then
               echo " Tmp_dir is exits"
       else
               mkdir ${Tmp_dir} &> /dev/null
       fi
       mount ${Source_file} -o loop ${Mount_dir} &> /dev/null
       cp -a ${Mount_dir}/. ${Tmp_dir}
###create file isolinux.cfg
       mv ${Tmp_dir}/isolinux/isolinux.cfg /isolinux.cfg.bak &> /dev/null
cat << EOF >> ${Tmp_dir}/isolinux/isolinux.cfg
default install
prompt 1
#timeout 600
timeout 30

display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label install                                
 kernel vmlinuz
 append ks=cdrom:/ks.cfg initrd=initrd.img
label linux
 menu label ^Install or upgrade an existing system
 menu default
 kernel vmlinuz
 append initrd=initrd.img
label vesa
 menu label Install system with ^basic video driver
 kernel vmlinuz
 append initrd=initrd.img xdriver=vesa nomodeset
label rescue
 menu label ^Rescue installed system
 kernel vmlinuz
 append initrd=initrd.img rescue
label local
 menu label Boot from ^local drive
 localboot 0xffff
label memtest86
 menu label ^Memory test
 kernel memtest
 append -
EOF
       umount ${Mount_dir}
       cp ${Ks_name_dir} ${Tmp_dir}
       cd ${Tmp_dir}
       find -type f -name "TRANS.TBL" |xargs rm -f
       rm -rf isolinux/boot.cat
       chmod +w isolinux/* &> /dev/null
###create iso file
       mkisofs -o ${Cdrom_name_dir} -J -r -v\
       -b isolinux/isolinux.bin\
       -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table\
       -V "$Label" .
       implantisomd5 --force ${Cdrom_name_dir} &>/dev/null
       if (( $? == 0 ))
       then
               rm -rf ${Tmp_dir}
               echo "cdrom is ok"
       else
               rm -rf ${Tmp_dir}
               echo "cdrom is wrong"
       fi
}
auto_cd

 

posted @ 2017-06-23 09:37  行知散人  阅读(796)  评论(0编辑  收藏  举报