因公司centos服务器重装需求较多,且服务器没有远控卡,每次重装系统需要到机房操作,费时费力.特作此脚本.
此脚本适用于Centos6.1-Centos7.3 64系统的远程安装.如需其他版本请自行添加!
运行脚本如下:
@L_403_3@
使用VNC进行远程重装操作!
脚本如下:
#!/bin/bash #CentosAutoInstall #VER.1.1.0-http://www.fenei.net #此脚本主要为方便远程重装centos系统使用,目前因空间问题只做到6.1-7.0的64位版本 #此脚本需要搭建一套http服务器并启用目录浏览,将需要远程安装的镜像解压到http服务器 #脚本运行完成以后需要使用vnc客户端连接服务器进行安装.重装系统的服务器需和VNC客户端互通 # #2016年5月20日3 #VER.2.1.0-http://www.fenei.net #更改自动获取服务器IP地址. #新增镜像站点网络连接判断 #新增centos7系列grub2的安装 # #2017年4月24日 # # #Fenei@SinpulNetwork #http://www.fenei.net # #===================================================================== #获取本机IP及版本信息 IPADDRESS=$(ifconfig-a|grepinet|grep-v127.0.0.1|grep-vinet6|awk'{print$2}'|tr-d"addr:") NETMASK=$(ifconfig-a|grepinet|grep-v127.0.0.1|grep-vinet6|awk'{print$4}'|tr-d"Mask:") GATEWAY=$(iproute|grepdefault|awk'{print$3}') DNS=$(cat/etc/resolv.conf|awk'NR>1'|awk'{print$2}'|head-n1) RELEASE=$(rpm-qcentos-release|cut-d'-'-f3) sttyerase^h sttyerase^H sttyerase^? #将shell运行过程中读取退格键替换为退格命令,否则会输出^H!^? host=192.168.1.11 ping-c2$host>>/dev/null if[$?-eq0];then echo“Mirrorsnetworkisok,waittoinstall...” ping-c5$host>>/dev/null if["$RELEASE"="6"]; then clear printf"++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" printf"++\n" printf"+请输入VNC远程密码+\n" printf"+■必须6-8位■+\n" printf"+eg:12345678+\n" printf"++\n" printf"++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" readPASSWD clear printf"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" printf"+您的服务器IP配置信息为\n" printf"+IP地址:$IPADDRESS \n" printf"+子网掩码:$NETMASK \n" printf"+网关:$GATEWAY \n" printf"+DNS:$DNS \n" printf"+请确保配置信息正确,否则将无法远程登录\n" printf"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" readanykey clear printf"+++++++++++++++++++++++++++++++++++++++++++++++++++\n" printf"++++++请选择需要安装的Centos系统版本+++++++++++++++\n" printf"++\n" printf"+1.CentOS6.1-X86_642.CentOS6.2-X86_64+\n" printf"+3.CentOS6.3-X86_644.CentOS6.4-X86_64+\n" printf"+5.CentOS6.5-X86_646.CentOS6.6-X86_64+\n" printf"+7.CentOS6.7-X86_648.CentOS6.8-X86_64+\n" printf"+9.CentOS6.9-X86_64a.CentOS7.0-X86_64+\n" printf"+b.CentOS7.1-X86_64c.CentOS7.2-X86_64+\n" printf"+d.CentOS7.3-X86_64+\n" printf"++\n" printf"+++++++++++++++++++++++++++++++++++++++++++++++++++\n" printf"+++++++++++++++++++++++++++++++++++++++++++++++++++\n" readselec case"$selec"in "1") #####CentOS6.1-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.1/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.1/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS6.1-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/6.1\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "2") #####CentOS6.2-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.2/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.2/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS6.2-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/6.2\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "3") #####CentOS6.3-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.3/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.3/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS6.3-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/6.3\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "4") #####CentOS6.4-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.4/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.4/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS6.4-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/6.4\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "5") #####CentOS6.5-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.5/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.5/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS6.5-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/6.5\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "6") #####CentOS6.6-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.6/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.6/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS6.6-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/6.6\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "7") #####CentOS6.7-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.7/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.7/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS6.7-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/6.7\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "8") #####CentOS6.8-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.8/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.8/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS6.8-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/6.8\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "9") #####CentOS6.9-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.9/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.9/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS6.9-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/6.9\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "a") #####CentOS7.0-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.0/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.0/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS7.0-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/7.0\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "b") #####CentOS7.1-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.1/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.1/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS7.1-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/7.1\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "c") #####CentOS7.2-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.2/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.2/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS7.2-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/7.2\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; "d") #####CentOS7.3-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.3/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.3/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe #在"hiddenmenu"和"titleCentOS..."增加一项: #repo中的url为安装centos的源 sed-i-e"/hiddenmenu/a\titleCentOS7.3-X86_64Install(PXE)\nroot(hd0,0)\nkernel\/vmlinuz.cent.pxevncvncpassword=${PASSWD}noselinuxheadlessip=${IPADDRESS}IPnetmask=${NETMASK}gateway=${GATEWAY}dns=${DNS}ksdevice=method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/7.3\/lang=en_USkeymap=us\ninitrd\/initrd.img.cent.pxe"/boot/grub/grub.conf ;; esac elif["$RELEASE"="7"]; then clear printf"++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" printf"++\n" printf"+请输入VNC远程密码+\n" printf"+■必须6-8位■+\n" printf"+eg:12345678+\n" printf"++\n" printf"++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" readPASSWD clear printf"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" printf"+您的服务器IP配置信息为\n" printf"+IP地址:$IPADDRESS \n" printf"+子网掩码:$NETMASK \n" printf"+网关:$GATEWAY \n" printf"+DNS:$DNS \n" printf"+请确保配置信息正确,否则将无法远程登录\n" printf"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" readanykey clear printf"+++++++++++++++++++++++++++++++++++++++++++++++++++\n" printf"++++++请选择需要安装的Centos系统版本+++++++++++++++\n" printf"++\n" printf"+1.CentOS6.1-X86_642.CentOS6.2-X86_64+\n" printf"+3.CentOS6.3-X86_644.CentOS6.4-X86_64+\n" printf"+5.CentOS6.5-X86_646.CentOS6.6-X86_64+\n" printf"+7.CentOS6.7-X86_648.CentOS6.8-X86_64+\n" printf"+9.CentOS6.9-X86_64a.CentOS7.0-X86_64+\n" printf"+b.CentOS7.1-X86_64c.CentOS7.2-X86_64+\n" printf"+d.CentOS7.3-X86_64+\n" printf"++\n" printf"+++++++++++++++++++++++++++++++++++++++++++++++++++\n" printf"+++++++++++++++++++++++++++++++++++++++++++++++++++\n" readselec case"$selec"in "1") #####CentOS6.1-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.1/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.1/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/6.1/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "2") #####CentOS6.2-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.2/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.2/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/6.2/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "3") #####CentOS6.3-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.3/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.3/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/6.3/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "4") #####CentOS6.4-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.4/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.4/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/6.4/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "5") #####CentOS6.5-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.5/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.5/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/6.5/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "6") #####CentOS6.6-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.6/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.6/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/6.6/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "7") clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.7/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.7/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/6.7/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "8") #####CentOS6.8-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.8/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.8/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/6.8/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "9") #####CentOS6.9-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.9/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/6.9/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/6.9/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "a") #####CentOS7.0-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.0/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.0/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/7.0/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "b") #####CentOS7.1-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.1/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.1/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/7.1/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "c") #####CentOS7.2-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.2/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.2/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/7.2/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; "d") #####CentOS7.3-X86_64##### clear mkdir/centos_install cd/centos_install curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.3/images/pxeboot/initrd.img curl-Ohttp://192.168.1.11/linux/centos/x86_64/7.3/images/pxeboot/vmlinuz cpvmlinuz/boot/vmlinuz.cent.pxe cpinitrd.img/boot/initrd.img.cent.pxe cat>>/etc/grub.d/40_custom<<EOF menuentry"NetInstall"{ setroot=(hd0,1) linux/vmlinuz.cent.pxerepo=http://192.168.1.11/linux/centos/x86_64/7.3/vncvncpassword=${PASSWD}ip=${IPADDRESS}netmask=${NETMASK}gateway=${GATEWAY}nameserver=${DNS}noselinuxheadless initrd/initrd.img.cent.pxe } EOF grub2-mkconfig--output=/boot/grub2/grub.cfg grub2-rebootNetInstall ;; esac else echo"当前系统不支持此安装脚本,无法进行安装" fi printf"++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" printf"+Centos重装脚本执行成功\n" printf"+请重启服务器后使用VNC客户端远程进行系统安装 \n" printf"+VNC服务器地址:$IPADDRESS:1 \n" printf"+VNC服务器密码:$PASSWD\n" printf"++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" readanykey exit else echo“networkisUnreachable,Thisscriptcannotrun!NowExit!!!” exit fi原文链接:https://www.f2er.com/centos/377830.html