{"id":139,"date":"2018-11-30T23:54:33","date_gmt":"2018-11-30T15:54:33","guid":{"rendered":"http:\/\/www.zhangyijun.com\/?p=139"},"modified":"2018-11-30T23:54:33","modified_gmt":"2018-11-30T15:54:33","slug":"linux-vps-centos-%e7%bd%91%e7%bb%9c%e5%ae%89%e8%a3%85-%e9%87%8d%e8%a3%85%e7%b3%bb%e7%bb%9f%e4%b8%80%e9%94%ae%e8%84%9a%e6%9c%ac-%e7%ba%af%e5%87%80%e5%ae%89%e8%a3%85","status":"publish","type":"post","link":"http:\/\/www.zhangyijun.com\/?p=139","title":{"rendered":"[ Linux VPS ] CentOS \u7f51\u7edc\u5b89\u88c5\/\u91cd\u88c5\u7cfb\u7edf\u4e00\u952e\u811a\u672c \u7eaf\u51c0\u5b89\u88c5"},"content":{"rendered":"<p>\t\t\t\thttps:\/\/moeclub.org\/2018\/03\/26\/597\/<\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li><strong>\u80cc\u666f<\/strong>:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u9002\u7528\u4e8e\u7531GRUB\u5f15\u5bfc\u7684CentOS,Ubuntu,Debian\u7cfb\u7edf.<br \/>\n\u4f7f\u7528\u5b98\u65b9\u53d1\u884c\u7248\u53bb\u6389\u6a21\u677f\u9884\u88c5\u7684\u8f6f\u4ef6.<br \/>\n\u540c\u65f6\u4e5f\u53ef\u4ee5\u89e3\u51b3\u5185\u6838\u7248\u672c\u4e0e\u8f6f\u4ef6\u4e0d\u517c\u5bb9\u7684\u95ee\u9898\u3002<br \/>\n\u53ea\u8981\u6709root\u6743\u9650,\u8fd8\u60a8\u4e00\u4e2a\u7eaf\u51c0\u7684\u7cfb\u7edf\u3002<\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li><strong>\u76f8\u5173\u6587\u7ae0<\/strong>:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong><a href=\"https:\/\/moeclub.org\/2017\/03\/25\/82\/\"><u>[ Linux VPS ] Debian(Ubuntu)\u7f51\u7edc\u5b89\u88c5\/\u91cd\u88c5\u7cfb\u7edf\u4e00\u952e\u811a\u672c<\/u><\/a><\/strong><\/p>\n<hr \/>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li><strong>\u6ce8\u610f<\/strong>:\n<ul>\n<li>\u5168\u81ea\u52a8\u5b89\u88c5\u9ed8\u8ba4root\u5bc6\u7801:<code>Vicer<\/code>,\u5b89\u88c5\u5b8c\u6210\u540e\u8bf7\u7acb\u5373\u66f4\u6539\u5bc6\u7801.<\/li>\n<li>\u5168\u81ea\u52a8\u5b89\u88c5\u65f6\u9ed8\u8ba4\u63d0\u4f9bVNC\u529f\u80fd,\u53ef\u4f7f\u7528<a href=\"https:\/\/moeclub.org\/go-vncviewer\" target=\"_blank\" rel=\"noopener noreferrer\"><strong><u>VNC Viewer<\/u><\/strong><\/a>\u67e5\u770b\u8fdb\u5ea6,<br \/>\n<strong>VNC\u7aef\u53e3<\/strong>\u4e3a<strong>1<\/strong>\u6216\u8005<strong>5901<\/strong>,\u53ef\u81ea\u884c\u5c1d\u8bd5\u8fde\u63a5.(\u6210\u529f\u540eVNC\u529f\u80fd\u4f1a\u6d88\u5931.)<\/li>\n<li>\u76ee\u524d\u53ea\u652f\u6301\u00a0<strong>CentOS 6.9<\/strong>\u00a0\u53ca\u4ee5\u4e0b\u7248\u672c(5.x,6.x).<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u7279\u522b\u6ce8\u610f:<em><code>OpenVZ<\/code>\u6784\u67b6\u4e0d\u9002\u7528.<\/em><\/strong><\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li><strong>\u66f4\u65b0<\/strong>:\n<ul>\n<li>[2018.04.03]<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u529f\u80fd\u5408\u5e76:<br \/>\n<strong><a href=\"https:\/\/moeclub.org\/2018\/04\/03\/603\/\" target=\"_blank\" rel=\"noopener noreferrer\"><u>[ Linux VPS ] Debian\/Ubuntu\/CentOS \u7f51\u7edc\u5b89\u88c5\/\u91cd\u88c5\u7cfb\u7edf\/\u7eaf\u51c0\u5b89\u88c5 \u4e00\u952e\u811a\u672c<\/u><\/a><\/strong><\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li>[2018.03.30]<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4f18\u5316GRUB\u68c0\u6d4b\u6d4b\u903b\u8f91.<br \/>\n\u6dfb\u52a0\u7ec4\u4ef6\u4f9d\u8d56\u68c0\u6d4b.<br \/>\n\u4fee\u590d\u5b58\u5728\u591a\u7f51\u5361\u7684\u95ee\u9898.<br \/>\n\u4fee\u590d\u4e00\u4e9b\u5df2\u77e5BUG.<\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li style=\"list-style-type: none;\"><\/li>\n<li><strong>\u9700\u8981<\/strong>:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>1.<code>Debian\/Ubuntu\/CentOS<\/code>\u00a0\u7cfb\u7edf(\u7531<code>GRUB<\/code>\u5f15\u5bfc)\uff1b<br \/>\n2.<code>wget<\/code>\u00a0\u7528\u6765\u4e0b\u8f7d\u6587\u4ef6\uff0c\u83b7\u53d6\u516c\u7f51IP;<br \/>\n3.<code>ip<\/code>\u00a0\u83b7\u53d6\u7f51\u5173\uff0c\u63a9\u7801\u7b49;<br \/>\n4.<code>sed awk grep<\/code>\u00a0\u5904\u7406\u6587\u672c\u6d41\uff1b<br \/>\n5.<code>openssl<\/code>\u00a0\u521b\u5efaroot\u7528\u6237\u5bc6\u7801;<br \/>\n6.<code>xz-utils<\/code>\u00a0\u91cd\u65b0\u6253\u5305\u955c\u50cf.<\/p>\n<hr \/>\n<hr \/>\n<ul>\n<li><strong>\u786e\u4fdd\u5b89\u88c5\u4e86\u6240\u9700\u8f6f\u4ef6<\/strong>:<\/li>\n<\/ul>\n<pre class=\"pure-highlightjs\"><code class=\"\" null=\"\">#Debian\/Ubuntu:\napt-get install -y xz-utils openssl gawk coreutils file\n \n#RedHat\/CentOS:\nyum install -y xz openssl gawk coreutils file<\/code><\/pre>\n<ul>\n<li><strong>\u5982\u679c\u51fa\u73b0\u4e86\u9519\u8bef,\u8bf7\u8fd0\u884c<\/strong>:<\/li>\n<\/ul>\n<pre class=\"pure-highlightjs\"><code class=\"\" null=\"\">#Debian\/Ubuntu:\napt-get update\n \n#RedHat\/CentOS:\nyum update<\/code><\/pre>\n<ul>\n<li><strong>\u4e00\u952e\u4e0b\u8f7d\u53ca\u4f7f\u7528<\/strong>:<\/li>\n<\/ul>\n<pre class=\"pure-highlightjs\"><code class=\"\" null=\"\">wget --no-check-certificate -qO CentOSNET.sh 'https:\/\/moeclub.org\/attachment\/LinuxShell\/CentOSNET.sh' &amp;&amp; chmod a+x CentOSNET.sh<\/code><\/pre>\n<pre class=\"pure-highlightjs\"><code class=\"\" null=\"\">Usage:\n        bash CentOSNET.sh       -c\/--centos [dist-version]\n                                -v\/--ver [32\/i386|64\/amd64]\n                                --ip-addr\/--ip-gate\/--ip-mask\n                                -yum\/--mirror\n                                -a\/-m<\/code><\/pre>\n<ul>\n<li><strong>\u5168\u81ea\u52a8\u5b89\u88c5<\/strong>:<\/li>\n<\/ul>\n<pre class=\"pure-highlightjs\"><code class=\"\" null=\"\">#\u4f7f\u7528\u9ed8\u8ba4\u955c\u50cf\u5168\u81ea\u52a8\u5b89\u88c5\nbash CentOSNET.sh -c 6.8 -v 64 -a\n \n#\u4f7f\u7528\u81ea\u5b9a\u4e49\u955c\u50cf\u5168\u81ea\u52a8\u5b89\u88c5\nbash CentOSNET.sh -c 6.9 -v 64 -a --mirror 'http:\/\/mirror.centos.org\/centos'\n \n#\u4f7f\u7528\u81ea\u5b9a\u4e49\u955c\u50cf\u81ea\u5b9a\u4e49\u7f51\u7edc\u53c2\u6570\u5168\u81ea\u52a8\u5b89\u88c5\n#bash CentOSNET.sh -c 6.9 -v 64 -a --ip-addr x.x.x.x --ip-gate x.x.x.x --ip-mask x.x.x.x --mirror 'http:\/\/mirror.centos.org\/centos'<\/code><\/pre>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li><strong>\u4e00\u4e9b\u63d0\u793a<\/strong>:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u5982\u679c\u770b\u5230 \u201c<strong>Starting graphical installation<\/strong>\u201d \u6216\u8005\u7c7b\u4f3c\u8868\u8fbe,\u5219\u8868\u793a\u6b63\u5728\u5b89\u88c5.<br \/>\n\u6b63\u5e38\u60c5\u51b5\u4e0b\u53ea\u9700\u8981\u8010\u5fc3\u7b49\u5f85\u5b89\u88c5\u5b8c\u6210\u5373\u53ef.<br \/>\n\u5982\u679c\u9700\u8981\u67e5\u770b\u8fdb\u5ea6,\u4f7f\u7528<strong>VNC Viewer<\/strong>(\u6216\u8005\u5176\u4ed6VNC\u8fde\u63a5\u5de5\u5177)<br \/>\n\u8fde\u63a5\u63d0\u793a\u4e2d\u7684<strong>IP\u5730\u5740:\u7aef\u53e3<\/strong>\u8fdb\u884c\u8fde\u63a5.(\u7aef\u53e3\u4e00\u822c\u4e3a<strong>1<\/strong>\u6216\u8005<strong>5901<\/strong>)<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\" null=\"\">#!\/bin\/bash\n \nexport tmpVER=''\nexport tmpDIST=''\nexport tmpWORD=''\nexport tmpMirror=''\nexport tmpINS=''\nexport ipAddr=''\nexport ipMask=''\nexport ipGate=''\nexport linuxdists=''\nexport setNet='0'\nexport isMirror='0'\nexport UNKNOWHW='0'\nexport UNVER='6.4'\n \nwhile [[ $# -ge 1 ]]; do\n  case $1 in\n    -v|--ver)\n      shift\n      tmpVER=\"$1\"\n      shift\n      ;;\n    -c|--centos)\n      shift\n      linuxdists='centos'\n      tmpDIST=\"$1\"\n      shift\n      ;;\n    -p|--password)\n      shift\n      tmpWORD=\"$1\"\n      shift\n      ;;\n    --ip-addr)\n      shift\n      ipAddr=\"$1\"\n      shift\n      ;;\n    --ip-mask)\n      shift\n      ipMask=\"$1\"\n      shift\n      ;;\n    --ip-gate)\n      shift\n      ipGate=\"$1\"\n      shift\n      ;;\n    -a|--auto)\n      shift\n      tmpINS='auto'\n      ;;\n    -m|--manual)\n      shift\n      tmpINS='manual'\n      ;;\n    -yum|--mirror)\n      shift\n      isMirror='1'\n      tmpMirror=\"$1\"\n      shift\n      ;;\n    *)\n      echo -ne \" Usage:\\n\\tbash DebianNET.sh\\t-c\/--centos [\\033[33m\\033[04mdists-verison\\033[0m]\\n\\t\\t\\t\\t-v\/--ver [32\/\\033[33m\\033[04mi386\\033[0m|64\/amd64]\\n\\t\\t\\t\\t--ip-addr\/--ip-gate\/--ip-mask\\n\\t\\t\\t\\t-apt\/--mirror\\n\\t\\t\\t\\t-dd\/--image\\n\\t\\t\\t\\t-a\/--auto\\n\\t\\t\\t\\t-m\/--manual\\n\"\n      exit 1;\n      ;;\n    esac\n  done\n \n[[ \"$EUID\" -ne '0' ]] &amp;&amp; echo \"Error:This script must be run as root!\" &amp;&amp; exit 1;\n \nfunction CheckDependence(){\nFullDependence='0';\nfor BIN_DEP in `echo \"$1\" |sed 's\/,\/\\n\/g'`\n  do\n    if [[ -n \"$BIN_DEP\" ]]; then\n      Founded='0';\n      for BIN_PATH in `echo \"$PATH\" |sed 's\/:\/\\n\/g'`\n        do\n          ls $BIN_PATH\/$BIN_DEP &gt;\/dev\/null 2&gt;&amp;1;\n          if [ $? == '0' ]; then\n            Founded='1';\n            break;\n          fi\n        done\n      if [ \"$Founded\" == '1' ]; then\n        echo -en \"$BIN_DEP\\t\\t[\\033[32mok\\033[0m]\\n\";\n      else\n        FullDependence='1';\n        echo -en \"$BIN_DEP\\t\\t[\\033[31mfail\\033[0m]\\n\";\n      fi\n    fi\n  done\nif [ \"$FullDependence\" == '1' ]; then\n  exit 1;\nfi\n}\n \nclear &amp;&amp; echo -e \"\\n\\033[36m# Check Dependence\\033[0m\\n\"\nCheckDependence wget,awk,xz,openssl,grep,dirname,file,cut,cat,cpio,gzip\n \n[[ -f '\/boot\/grub\/grub.cfg' ]] &amp;&amp; GRUBOLD='0' &amp;&amp; GRUBDIR='\/boot\/grub' &amp;&amp; GRUBFILE='grub.cfg';\n[[ -z \"$GRUBDIR\" ]] &amp;&amp; [[ -f '\/boot\/grub2\/grub.cfg' ]] &amp;&amp; GRUBOLD='0' &amp;&amp; GRUBDIR='\/boot\/grub2' &amp;&amp; GRUBFILE='grub.cfg';\n[[ -z \"$GRUBDIR\" ]] &amp;&amp; [[ -f '\/boot\/grub\/grub.conf' ]] &amp;&amp; GRUBOLD='1' &amp;&amp; GRUBDIR='\/boot\/grub' &amp;&amp; GRUBFILE='grub.conf';\n[ -z \"$GRUBDIR\" -o -z \"$GRUBFILE\" ] &amp;&amp; echo -ne \"Error! \\nNot Found grub path.\\n\" &amp;&amp; exit 1;\n \n[[ -n \"$tmpVER\" ]] &amp;&amp; {\n  [ \"$tmpVER\" == '32' -o \"$tmpVER\" == 'i386' ] &amp;&amp; VER='i386';\n  [ \"$tmpVER\" == '64' -o \"$tmpVER\" == 'amd64' ] &amp;&amp; VER='x86_64';\n}\n[[ -z \"$VER\" ]] &amp;&amp; VER='i386';\n \n[[ -z \"$linuxdists\" ]] &amp;&amp; linuxdists='centos';\n \n[[ \"$isMirror\" == '1' ]] &amp;&amp; [[ -n \"$tmpMirror\" ]] &amp;&amp; {\n  echo \"$tmpMirror\" |grep -q '^http:\/\/';\n  [[ $? == '0' ]] &amp;&amp; {\n    TMPMirror=\"$(echo \"$tmpMirror\" |awk -F':\/\/' '{print $2}')\";\n  } || {\n    echo -en \"\\n\\033[31mInvaild Mirror! \\033[0m\\n\\033[33mexample:\\033[0m http:\/\/mirror.centos.org\/centos\\n\\n\";\n    exit 1\n  }\n  [[ -n \"$TMPMirror\" ]] &amp;&amp; {\n    echo \"$TMPMirror\" |grep -q '\/$';\n    [[ $? == '0' ]] &amp;&amp; {\n      CentOSMirror=\"$(dirname \"$TMPMirror.centos\")\";\n    } || {\n      CentOSMirror=\"$TMPMirror\";\n    }\n  } || {\n    bash $0 error;\n    exit 1\n  }\n} || {\n  CentOSMirror='vault.centos.org';\n}\n \n[[ -z \"$tmpDIST\" ]] &amp;&amp; {\n  [[ \"$linuxdists\" == 'centos' ]] &amp;&amp; tmpDIST='6.4';\n}\n \n[[ -z \"$DIST\" ]] &amp;&amp; {\n  DISTCheck=\"$(echo \"$tmpDIST\" |grep -o '[.0-9]\\{1,\\}')\";\n  ListDIST=\"$(wget --no-check-certificate -qO- \"http:\/\/$CentOSMirror\/dir_sizes\" |cut -f2 |grep '^[0-9]')\"\n  DIST=\"$(echo \"$ListDIST\" |grep \"^$DISTCheck\")\"\n  [[ -z \"$DIST\" ]] &amp;&amp; {\n    echo -ne '\\nThe dists version not found, Please check it! \\n\\n'\n    bash $0 error;\n    exit 1;\n  }\n  wget --no-check-certificate -qO- \"http:\/\/$CentOSMirror\/$DIST\/os\/$VER\/.treeinfo\" |grep -q 'general';\n  [[ $? != '0' ]] &amp;&amp; {\n    echo -ne \"\\nThe version not found in this mirror, Please change mirror try again! \\n\\n\";\n    exit 1;\n  }\n}\n \n[[ -n \"$tmpINS\" ]] &amp;&amp; {\n  [[ \"$tmpINS\" == 'auto' ]] &amp;&amp; inVNC='n';\n  [[ \"$tmpINS\" == 'manual' ]] &amp;&amp; inVNC='y';\n}\n \n[ -n \"$ipAddr\" ] &amp;&amp; [ -n \"$ipMask\" ] &amp;&amp; [ -n \"$ipGate\" ] &amp;&amp; setNet='1';\n[[ -n \"$tmpWORD\" ]] &amp;&amp; myPASSWORD=\"$(openssl passwd -1 \"$tmpWORD\")\";\n[[ -z \"$myPASSWORD\" ]] &amp;&amp; myPASSWORD='$1$0shYGfBd$8v189JOozDO1jPqPO645e1';\n[[ -z \"$INCFW\" ]] &amp;&amp; INCFW='0';\n \nclear &amp;&amp; echo -e \"\\n\\033[36m# Install\\033[0m\\n\"\n \nASKVNC(){\n  inVNC='y';\n  [[ \"$ddMode\" == '0' ]] &amp;&amp; {\n    echo -ne \"\\033[34mCan you login VNC?\\033[0m\\e[33m[\\e[32my\\e[33m\/n]\\e[0m \"\n    read tmpinVNC\n    [[ -n \"$inVNCtmp\" ]] &amp;&amp; inVNC=\"$tmpinVNC\"\n  }\n  [ \"$inVNC\" == 'y' -o \"$inVNC\" == 'Y' ] &amp;&amp; inVNC='y';\n  [ \"$inVNC\" == 'n' -o \"$inVNC\" == 'N' ] &amp;&amp; inVNC='n';\n}\n \n[ \"$inVNC\" == 'y' -o \"$inVNC\" == 'n' ] || ASKVNC;\n[[ \"$linuxdists\" == 'centos' ]] &amp;&amp; LinuxName='CentOS';\n[[ \"$inVNC\" == 'y' ]] &amp;&amp; VNC_WARN='1' &amp;&amp; echo -e \"\\033[34mManual Mode\\033[0m insatll \\033[33m$LinuxName\\033[0m [\\033[33m$DIST\\033[0m] [\\033[33m$VER\\033[0m] in VNC. \"\n[[ \"$inVNC\" == 'n' ]] &amp;&amp; VNC_WARN='0' &amp;&amp; echo -e \"\\033[34mAuto Mode\\033[0m insatll \\033[33m$LinuxName\\033[0m [\\033[33m$DIST\\033[0m] [\\033[33m$VER\\033[0m]. \"\n \nif [[ \"$DIST\" != \"$UNVER\" ]]; then\n  awk 'BEGIN{print '${UNVER}'-'${DIST}'}' |grep -q '^-'\n  if [ $? != '0' ]; then\n    UNKNOWHW='1';\n    echo -en \"\\033[33mThe version lower then \\033[31m$UNVER\\033[33m may not support in auto mode! \\033[0m\\n\";\n    if [[ \"$inVNC\" == 'n' ]]; then\n      echo -en \"\\033[35mYou can connect VNC with \\033[32mPublic IP\\033[35m and port \\033[32m1\\033[35m\/\\033[32m5901\\033[35m in vnc viewer.\\033[0m\\n\"\n      read -n 1 -p \"Press Enter to continue...\" INP\n      [[ \"$INP\" != '' ]] &amp;&amp; echo -ne '\\b \\n\\n';\n    fi\n  fi\n  awk 'BEGIN{print '${UNVER}'-'${DIST}'+0.59}' |grep -q '^-'\n  if [ $? == '0' ]; then\n    echo -en \"\\n\\033[31mThe version higher then \\033[33m6.9 \\033[31mis not support in current! \\033[0m\\n\\n\"\n    exit 1;\n  fi\nfi\n \necho -e \"\\n[\\033[33m$LinuxName\\033[0m] [\\033[33m$DIST\\033[0m] [\\033[33m$VER\\033[0m] Downloading...\"\n[[ -z \"$CentOSMirror\" ]] &amp;&amp; echo -ne \"\\033[31mError! \\033[0mGet debian mirror fail! \\n\" &amp;&amp; exit 1\nwget --no-check-certificate -qO '\/boot\/initrd.img' \"http:\/\/$CentOSMirror\/$DIST\/os\/$VER\/isolinux\/initrd.img\"\n[[ $? -ne '0' ]] &amp;&amp; echo -ne \"\\033[31mError! \\033[0mDownload 'initrd.img' failed! \\n\" &amp;&amp; exit 1\nwget --no-check-certificate -qO '\/boot\/vmlinuz' \"http:\/\/$CentOSMirror\/$DIST\/os\/$VER\/isolinux\/vmlinuz\"\n[[ $? -ne '0' ]] &amp;&amp; echo -ne \"\\033[31mError! \\033[0mDownload 'vmlinux' failed! \\n\" &amp;&amp; exit 1\n \n[[ \"$setNet\" == '1' ]] &amp;&amp; {\n  IPv4=\"$ipAddr\";\n  MASK=\"$ipMask\";\n  GATE=\"$ipGate\";\n} || {\n  DEFAULTNET=\"$(ip route show |grep -o 'default via [0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.*' |head -n1 |sed 's\/proto.*\\|onlink.*\/\/g' |awk '{print $NF}')\";\n  [[ -n \"$DEFAULTNET\" ]] &amp;&amp; IPSUB=\"$(ip addr |grep ''${DEFAULTNET}'' |grep 'global' |grep 'brd' |head -n1 |grep -o '[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}\/[0-9]\\{1,2\\}')\";\n  IPv4=\"$(echo -n \"$IPSUB\" |cut -d'\/' -f1)\";\n  NETSUB=\"$(echo -n \"$IPSUB\" |grep -o '\/[0-9]\\{1,2\\}')\";\n  GATE=\"$(ip route show |grep -o 'default via [0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}' |head -n1 |grep -o '[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}')\";\n  [[ -n \"$NETSUB\" ]] &amp;&amp; MASK=\"$(echo -n '128.0.0.0\/1,192.0.0.0\/2,224.0.0.0\/3,240.0.0.0\/4,248.0.0.0\/5,252.0.0.0\/6,254.0.0.0\/7,255.0.0.0\/8,255.128.0.0\/9,255.192.0.0\/10,255.224.0.0\/11,255.240.0.0\/12,255.248.0.0\/13,255.252.0.0\/14,255.254.0.0\/15,255.255.0.0\/16,255.255.128.0\/17,255.255.192.0\/18,255.255.224.0\/19,255.255.240.0\/20,255.255.248.0\/21,255.255.252.0\/22,255.255.254.0\/23,255.255.255.0\/24,255.255.255.128\/25,255.255.255.192\/26,255.255.255.224\/27,255.255.255.240\/28,255.255.255.248\/29,255.255.255.252\/30,255.255.255.254\/31,255.255.255.255\/32' |grep -o '[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}'${NETSUB}'' |cut -d'\/' -f1)\";\n}\n \n[[ -n \"$GATE\" ]] &amp;&amp; [[ -n \"$MASK\" ]] &amp;&amp; [[ -n \"$IPv4\" ]] || {\necho \"Not found `ip command`, It will use `route command`.\"\nipNum() {\n  local IFS='.';\n  read ip1 ip2 ip3 ip4 &lt;&lt;&lt;\"$1\";\n  echo $((ip1*(1&lt;&lt;24)+ip2*(1&lt;&lt;16)+ip3*(1&lt;&lt;8)+ip4));\n}\n \nSelectMax(){\nii=0;\nfor IPITEM in `route -n |awk -v OUT=$1 '{print $OUT}' |grep '[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}'`\n  do\n    NumTMP=\"$(ipNum $IPITEM)\";\n    eval \"arrayNum[$ii]='$NumTMP,$IPITEM'\";\n    ii=$[$ii+1];\n  done\necho ${arrayNum[@]} |sed 's\/\\s\/\\n\/g' |sort -n -k 1 -t ',' |tail -n1 |cut -d',' -f2;\n}\n \n[[ -z $IPv4 ]] &amp;&amp; IPv4=\"$(ifconfig |grep 'Bcast' |head -n1 |grep -o '[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}.[0-9]\\{1,3\\}' |head -n1)\";\n[[ -z $GATE ]] &amp;&amp; GATE=\"$(SelectMax 2)\";\n[[ -z $MASK ]] &amp;&amp; MASK=\"$(SelectMax 3)\";\n \n[[ -n \"$GATE\" ]] &amp;&amp; [[ -n \"$MASK\" ]] &amp;&amp; [[ -n \"$IPv4\" ]] || {\n  echo \"Error! Not configure network. \";\n  exit 1;\n}\n}\n \n[[ \"$setNet\" != '1' ]] &amp;&amp; [[ -f '\/etc\/network\/interfaces' ]] &amp;&amp; {\n  [[ -z \"$(sed -n '\/iface.*inet static\/p' \/etc\/network\/interfaces)\" ]] &amp;&amp; AutoNet='1' || AutoNet='0';\n  [[ -d \/etc\/network\/interfaces.d ]] &amp;&amp; {\n    ICFGN=\"$(find \/etc\/network\/interfaces.d -name '*.cfg' |wc -l)\" || ICFGN='0';\n    [[ \"$ICFGN\" -ne '0' ]] &amp;&amp; {\n      for NetCFG in `ls -1 \/etc\/network\/interfaces.d\/*.cfg`\n        do \n          [[ -z \"$(cat $NetCFG | sed -n '\/iface.*inet static\/p')\" ]] &amp;&amp; AutoNet='1' || AutoNet='0';\n          [[ \"$AutoNet\" -eq '0' ]] &amp;&amp; break;\n        done\n    }\n  }\n}\n \n[[ \"$setNet\" != '1' ]] &amp;&amp; [[ -d '\/etc\/sysconfig\/network-scripts' ]] &amp;&amp; {\n  ICFGN=\"$(find \/etc\/sysconfig\/network-scripts -name 'ifcfg-*' |grep -v 'lo'|wc -l)\" || ICFGN='0';\n  [[ \"$ICFGN\" -ne '0' ]] &amp;&amp; {\n    for NetCFG in `ls -1 \/etc\/sysconfig\/network-scripts\/ifcfg-* |grep -v 'lo$' |grep -v ':[0-9]\\{1,\\}'`\n      do \n        [[ -n \"$(cat $NetCFG | sed -n '\/BOOTPROTO.*[dD][hH][cC][pP]\/p')\" ]] &amp;&amp; AutoNet='1' || {\n          AutoNet='0' &amp;&amp; . $NetCFG;\n          [[ -n $NETMASK ]] &amp;&amp; MASK=\"$NETMASK\";\n          [[ -n $GATEWAY ]] &amp;&amp; GATE=\"$GATEWAY\";\n        }\n        [[ \"$AutoNet\" -eq '0' ]] &amp;&amp; break;\n      done\n  }\n}\n \n[[ ! -f $GRUBDIR\/$GRUBFILE ]] &amp;&amp; echo \"Error! Not Found $GRUBFILE. \" &amp;&amp; exit 1;\n \n[[ ! -f $GRUBDIR\/$GRUBFILE.old ]] &amp;&amp; [[ -f $GRUBDIR\/$GRUBFILE.bak ]] &amp;&amp; mv -f $GRUBDIR\/$GRUBFILE.bak $GRUBDIR\/$GRUBFILE.old;\nmv -f $GRUBDIR\/$GRUBFILE $GRUBDIR\/$GRUBFILE.bak;\n[[ -f $GRUBDIR\/$GRUBFILE.old ]] &amp;&amp; cat $GRUBDIR\/$GRUBFILE.old &gt;$GRUBDIR\/$GRUBFILE || cat $GRUBDIR\/$GRUBFILE.bak &gt;$GRUBDIR\/$GRUBFILE;\n \n[[ \"$GRUBOLD\" == '0' ]] &amp;&amp; {\n  READGRUB='\/tmp\/grub.read'\n  cat $GRUBDIR\/$GRUBFILE |sed -n '1h;1!H;$g;s\/\\n\/+++\/g;$p' |grep -oPm 1 'menuentry\\ .*\\{.*\\}\\+\\+\\+' |sed 's\/\\+\\+\\+\/\\n\/g' &gt;$READGRUB\n  LoadNum=\"$(cat $READGRUB |grep -c 'menuentry ')\"\n  if [[ \"$LoadNum\" -eq '1' ]]; then\n    cat $READGRUB |sed '\/^$\/d' &gt;\/tmp\/grub.new;\n  elif [[ \"$LoadNum\" -gt '1' ]]; then\n    CFG0=\"$(awk '\/menuentry \/{print NR}' $READGRUB|head -n 1)\";\n    CFG2=\"$(awk '\/menuentry \/{print NR}' $READGRUB|head -n 2 |tail -n 1)\";\n    CFG1=\"\";\n    for tmpCFG in `awk '\/}\/{print NR}' $READGRUB`\n      do\n        [ \"$tmpCFG\" -gt \"$CFG0\" -a \"$tmpCFG\" -lt \"$CFG2\" ] &amp;&amp; CFG1=\"$tmpCFG\";\n      done\n    [[ -z \"$CFG1\" ]] &amp;&amp; {\n      echo \"Error! read $GRUBFILE. \";\n      exit 1;\n    }\n \n    sed -n \"$CFG0,$CFG1\"p $READGRUB &gt;\/tmp\/grub.new;\n    [[ -f \/tmp\/grub.new ]] &amp;&amp; [[ \"$(grep -c '{' \/tmp\/grub.new)\" -eq \"$(grep -c '}' \/tmp\/grub.new)\" ]] || {\n      echo -ne \"\\033[31mError! \\033[0mNot configure $GRUBFILE. \\n\";\n      exit 1;\n    }\n  fi\n  [ ! -f \/tmp\/grub.new ] &amp;&amp; echo \"Error! $GRUBFILE. \" &amp;&amp; exit 1;\n  sed -i \"\/menuentry.*\/c\\menuentry\\ \\'Install OS \\[$DIST\\ $VER\\]\\'\\ --class debian\\ --class\\ gnu-linux\\ --class\\ gnu\\ --class\\ os\\ \\{\" \/tmp\/grub.new\n  sed -i \"\/echo.*Loading\/d\" \/tmp\/grub.new;\n}\n \n[[ \"$GRUBOLD\" == '1' ]] &amp;&amp; {\n  CFG0=\"$(awk '\/title \/{print NR}' $GRUBDIR\/$GRUBFILE|head -n 1)\";\n  CFG1=\"$(awk '\/title \/{print NR}' $GRUBDIR\/$GRUBFILE|head -n 2 |tail -n 1)\";\n  [[ -n $CFG0 ]] &amp;&amp; [ -z $CFG1 -o $CFG1 == $CFG0 ] &amp;&amp; sed -n \"$CFG0,$\"p $GRUBDIR\/$GRUBFILE &gt;\/tmp\/grub.new;\n  [[ -n $CFG0 ]] &amp;&amp; [ -z $CFG1 -o $CFG1 != $CFG0 ] &amp;&amp; sed -n \"$CFG0,$CFG1\"p $GRUBDIR\/$GRUBFILE &gt;\/tmp\/grub.new;\n  [[ ! -f \/tmp\/grub.new ]] &amp;&amp; echo \"Error! configure append $GRUBFILE. \" &amp;&amp; exit 1;\n  sed -i \"\/title.*\/c\\title\\ \\'Install OS \\[$DIST\\ $VER\\]\\'\" \/tmp\/grub.new;\n  sed -i '\/^#\/d' \/tmp\/grub.new;\n}\n \n[[ -n \"$(grep 'linux.*\/\\|kernel.*\/' \/tmp\/grub.new |awk '{print $2}' |tail -n 1 |grep '^\/boot\/')\" ]] &amp;&amp; Type='InBoot' || Type='NoBoot';\n \nLinuxKernel=\"$(grep 'linux.*\/\\|kernel.*\/' \/tmp\/grub.new |awk '{print $1}' |head -n 1)\";\n[[ -z \"$LinuxKernel\" ]] &amp;&amp; echo \"Error! read grub config! \" &amp;&amp; exit 1;\nLinuxIMG=\"$(grep 'initrd.*\/' \/tmp\/grub.new |awk '{print $1}' |tail -n 1)\";\n[ -z \"$LinuxIMG\" ] &amp;&amp; sed -i \"\/$LinuxKernel.*\\\/\/a\\\\\\tinitrd\\ \\\/\" \/tmp\/grub.new &amp;&amp; LinuxIMG='initrd';\n \n[[ \"$Type\" == 'InBoot' ]] &amp;&amp; {\n  sed -i \"\/$LinuxKernel.*\\\/\/c\\\\\\t$LinuxKernel\\\\t\\\/boot\\\/vmlinuz ks=file:\\\/\\\/ks.cfg ksdevice=link\" \/tmp\/grub.new;\n  sed -i \"\/$LinuxIMG.*\\\/\/c\\\\\\t$LinuxIMG\\\\t\\\/boot\\\/initrd.img\" \/tmp\/grub.new;\n}\n \n[[ \"$Type\" == 'NoBoot' ]] &amp;&amp; {\n  sed -i \"\/$LinuxKernel.*\\\/\/c\\\\\\t$LinuxKernel\\\\t\\\/vmlinuz ks=file:\\\/\\\/ks.cfg ksdevice=link\" \/tmp\/grub.new;\n  sed -i \"\/$LinuxIMG.*\\\/\/c\\\\\\t$LinuxIMG\\\\t\\\/initrd.img\" \/tmp\/grub.new;\n}\n \nsed -i '$a\\\\n' \/tmp\/grub.new;\n \n[[ \"$inVNC\" == 'n' ]] &amp;&amp; {\nGRUBPATCH='0';\n \n[ -f '\/etc\/network\/interfaces' -o -d '\/etc\/sysconfig\/network-scripts' ] || {\n  echo \"Error, Not found interfaces config.\";\n  exit 1;\n}\n \nINSERTGRUB=\"$(awk '\/menuentry \/{print NR}' $GRUBDIR\/$GRUBFILE|head -n 1)\"\nsed -i ''${INSERTGRUB}'i\\\\n' $GRUBDIR\/$GRUBFILE;\nsed -i ''${INSERTGRUB}'r \/tmp\/grub.new' $GRUBDIR\/$GRUBFILE;\n[[ -f  $GRUBDIR\/grubenv ]] &amp;&amp; sed -i 's\/saved_entry\/#saved_entry\/g' $GRUBDIR\/grubenv;\n \n[[ -d \/boot\/tmp ]] &amp;&amp; rm -rf \/boot\/tmp;\nmkdir -p \/boot\/tmp;\ncd \/boot\/tmp;\nCOMPTYPE=\"$(file \/boot\/initrd.img |grep -o ':.*compressed data' |cut -d' ' -f2 |sed -r 's\/(.*)\/\\L\\1\/' |head -n1)\"\n[[ -z \"$COMPTYPE\" ]] &amp;&amp; echo \"Detect compressed type fail.\" &amp;&amp; exit 1;\nCompDected='0'\nfor ListCOMP in `echo -en 'lzma\\nxz\\ngzip'`\n  do\n    if [[ \"$COMPTYPE\" == \"$ListCOMP\" ]]; then\n      CompDected='1'\n      if [[ \"$COMPTYPE\" == 'gzip' ]]; then\n        NewIMG=\"initrd.img.gz\"\n      else\n        NewIMG=\"initrd.img.$COMPTYPE\"\n      fi\n      mv -f \"\/boot\/initrd.img\" \"\/boot\/$NewIMG\"\n      break;\n    fi\n  done\n[[ \"$CompDected\" != '1' ]] &amp;&amp; echo \"Detect compressed type not support.\" &amp;&amp; exit 1;\n[[ \"$COMPTYPE\" == 'lzma' ]] &amp;&amp; UNCOMP='xz --format=lzma --decompress';\n[[ \"$COMPTYPE\" == 'xz' ]] &amp;&amp; UNCOMP='xz --decompress';\n[[ \"$COMPTYPE\" == 'gzip' ]] &amp;&amp; UNCOMP='gzip -d';\n \n$UNCOMP &lt; ..\/$NewIMG | cpio --extract --verbose --make-directories --no-absolute-filenames &gt;&gt;\/dev\/null 2&gt;&amp;1\ncat &gt;\/boot\/tmp\/ks.cfg&lt;&lt;EOF\n#platform=x86, AMD64, or Intel EM64T\n# Firewall configuration\nfirewall --enabled --ssh\n# Install OS instead of upgrade\ninstall\n# Use network installation\nurl --url=\"http:\/\/$CentOSMirror\/$DIST\/os\/$VER\/\"\n# Root password\nrootpw --iscrypted $myPASSWORD\n# System authorization information\nauth --useshadow --passalgo=sha512\nfirstboot --disable\n# System language\nlang en_US\n# System keyboard\nkeyboard us\n# SELinux configuration\nselinux --disabled\n# Installation logging level\nlogging --level=info\n# Reboot after installation\nreboot\n# Perform installation mode\ntext\n# Ingore Unsupported Hardware Detected alert\nunsupported_hardware\n# VNC support\nvnc\n# Do not install a graphical environment\nskipx\n# System timezone\ntimezone --isUtc Asia\/Hong_Kong\n# Network information\n#ONDHCP network --bootproto=dhcp --onboot=on\n#NODHCP network --bootproto=static --ip=$IPv4 --netmask=$MASK --gateway=$GATE --nameserver=8.8.8.8 --onboot=on\n# System bootloader configuration\nbootloader --location=mbr --append=\"rhgb quiet crashkernel=auto\"\n# Clear the Master Boot Record\nzerombr\n# Partition clearing information\nclearpart --all --initlabel \n# Disk partitioning information\nautopart\n \n%packages\n \n@base\n%end\n \n \n%post --interpreter=\/bin\/bash\n \nrm -rf \/root\/anaconda-ks.cfg\nrm -rf \/root\/install.*log\n%end\n \n \nEOF\n[[ \"$setNet\" == '0' ]] &amp;&amp; [[ \"$AutoNet\" == '1' ]] &amp;&amp; {\n  sed -i 's\/#ONDHCP\\ \/\/g' \/boot\/tmp\/ks.cfg\n} || {\n  sed -i 's\/#NODHCP\\ \/\/g' \/boot\/tmp\/ks.cfg\n}\n[[ \"$UNKNOWHW\" == '1' ]] &amp;&amp; sed -i 's\/^unsupported_hardware\/#unsupported_hardware\/g' \/boot\/tmp\/ks.cfg\n[[ \"$(echo \"$DIST\" |grep -o '^[0-9]\\{1\\}')\" == '5' ]] &amp;&amp; sed -i '0,\/^%end\/s\/\/#%end\/' \/boot\/tmp\/ks.cfg\nrm -rf ..\/$NewIMG;\nfind . | cpio -H newc --create --verbose | gzip -9 &gt; ..\/initrd.img;\nrm -rf \/boot\/tmp;\n}\n \n[[ \"$inVNC\" == 'y' ]] &amp;&amp; {\n  sed -i '$i\\\\n' $GRUBDIR\/$GRUBFILE\n  sed -i '$r \/tmp\/grub.new' $GRUBDIR\/$GRUBFILE\n  echo -e \"\\n\\033[33m\\033[04mIt will reboot! \\nPlease look at VNC! \\nSelect\\033[0m\\033[32m Install OS [$DIST $VER] \\033[33m\\033[4mto install system.\\033[04m\\n\\n\\033[31m\\033[04mThere is some information for you.\\nDO NOT CLOSE THE WINDOW! \\033[0m\\n\"\n  echo -e \"\\033[35mIPv4\\t\\tNETMASK\\t\\tGATEWAY\\033[0m\"\n  echo -e \"\\033[36m\\033[04m$IPv4\\033[0m\\t\\033[36m\\033[04m$MASK\\033[0m\\t\\033[36m\\033[04m$GATE\\033[0m\\n\\n\"\n \n  read -n 1 -p \"Press Enter to reboot...\" INP\n  [[ \"$INP\" != '' ]] &amp;&amp; echo -ne '\\b \\n\\n';\n}\n \nchown root:root $GRUBDIR\/$GRUBFILE\nchmod 444 $GRUBDIR\/$GRUBFILE\n \nsleep 3 &amp;&amp; reboot &gt;\/dev\/null 2&gt;&amp;1<\/code><\/pre>\n<p>&nbsp;\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\t\t\t\t\t\t&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"http:\/\/www.zhangyijun.com\/?p=139\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.zhangyijun.com\/index.php?rest_route=\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.zhangyijun.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zhangyijun.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zhangyijun.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zhangyijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=139"}],"version-history":[{"count":0,"href":"http:\/\/www.zhangyijun.com\/index.php?rest_route=\/wp\/v2\/posts\/139\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.zhangyijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zhangyijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zhangyijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}