请叫我峰子:
感受VPS建站的乐趣。

[ Linux Shell ] 通用无限制在 Linux VPS 上一键全自动 dd 安装 Windows 系统

无限制全自动dd安装Windows
突破没有VNC,没有救援模式,内存比dd包小的限制.
使用Debian Live CD中的busybox做中间媒介,经过复杂的处理,
使本机的网络参数传进Windows操作系统中,
即使没有DHCP能够让Windows获取网络参数,
也能让Windows操作系统在开机的第一时间能够连通网络.

  • 更新:
    • [2018.03.25]

优化判断逻辑.
增加手动指定网络参数选项,可有效避免自动获取网络参数无效造成无法直接联网的问题.

  • 背景:

1.带Windows的为什么就卖得那么贵?
2.当然是为了更自由的使用自己的机器.

1234#Debian/Ubuntu## 一般自带#RedHat/CentOSyum install glibc–common
1wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && bash DebianNET.sh –dd ‘[Windows dd包直连地址]’
  • 萌咖提供的demo包(1.19G;已激活):
123https://moeclub.org/get-win7embx86-auto# 该包只添加了VirtIO驱动,理论上仅能在KVM,Hyper-V构架下正常运行.# 如需在其他虚拟化构架下运行,请自行添加相关虚拟化驱动.

使用的是Windows Embedded Standard 7(Thin PC)作为底包,官方精简.
如需其他组件,例如:完整的桌面特征,Windows照片查看器等.
请参考: Thin PC (Win7 Embedded) 安装组件

  • 使用示例:
1234#在你的机器上全新安装,如果你有VNC,可以看到全部过程.#在dd的过程中,会卡在分区的界面上,不会走进度条.完成后将会自动重启.wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && bash DebianNET.sh –dd ‘https://moeclub.org/get-win7embx86-auto’
  • 使用示例(指定网络参数):
12345# 将X.X.X.X替换为自己的网络参数.# –ip-addr :IP Address/IP地址# –ip-mask :Gateway   /网关# –ip-gate :Netmask   /子网掩码# wget –no-check-certificate -qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && bash DebianNET.sh –ip-addr X.X.X.X –ip-mask X.X.X.X –ip-gate X.X.X.X -dd ‘https://moeclub.org/get-win7embx86-auto’
《[ Linux Shell ] 通用无限制在 Linux VPS 上一键全自动 dd 安装 Windows》
  • 注意事项:
    1. 远程登陆账号为: Administrator
    2. 远程登陆密码为: Vicer
    3. 仅修改了主机名,可放心使用.(建议自己制作.)
    4. 使用的公用网盘,如需长期/大量使用此包请自行备份.
    5. 如果因此违反了TOS,萌咖不负任何责任.
  • 可能用到的命令:
1234567891011121314::以管理员身份运行CMD::::更改用户的密码net user [用户名] [密码]::激活 Administrator 账户net user Administrator /active:yes::设置 Administrator 账户密码net user Administrator [新密码]::添加用户net user [用户名] [密码] /add::将用户添加至 Administrator 组net localgroup Administrators [用户名] /add::删除用户net user [用户名] /del
  • 温馨提示:

磁盘管理中,点击’C‘盘,右键选择’扩展卷‘,可以直接’增加‘C盘的空间.
激活相关请参考: https://moeclub.org/kms

全新安装!!! 全新安装!!! 全新安装!!!

    • Windows Embedded 8.1 Industry Pro x64 (2.87G;KVM;XEN;Hyper-V;未激活)
1https://moeclub.org/get-win8embx64-auto
  • 预览:
    1. #!/bin/bash

    2. export tmpVER=”
    3. export tmpDIST=”
    4. export tmpURL=”
    5. export tmpWORD=”
    6. export tmpMirror=”
    7. export tmpSSL=”
    8. export tmpINS=”
    9. export tmpFW=”
    10. export ipAddr=”
    11. export ipMask=”
    12. export ipGate=”
    13. export linuxdists=”
    14. export ddMode=’0′
    15. export setNet=’0′
    16. export isMirror=’0′
    17. export FindDists=’0′

    18. while [[ $# -ge 1 ]]; do
    19. case $1 in
    20. -v|–ver)
    21. shift
    22. tmpVER=”$1″
    23. shift
    24. ;;
    25. -d|–debian)
    26. shift
    27. linuxdists=’debian’
    28. tmpDIST=”$1″
    29. shift
    30. ;;
    31. -u|–ubuntu)
    32. shift
    33. linuxdists=’ubuntu’
    34. tmpDIST=”$1″
    35. shift
    36. ;;
    37. -dd|–image)
    38. shift
    39. ddMode=’1′
    40. tmpURL=”$1″
    41. shift
    42. ;;
    43. -p|–password)
    44. shift
    45. tmpWORD=”$1″
    46. shift
    47. ;;
    48. –ip-addr)
    49. shift
    50. ipAddr=”$1″
    51. shift
    52. ;;
    53. –ip-mask)
    54. shift
    55. ipMask=”$1″
    56. shift
    57. ;;
    58. –ip-gate)
    59. shift
    60. ipGate=”$1″
    61. shift
    62. ;;
    63. -a|–auto)
    64. shift
    65. tmpINS=’auto’
    66. ;;
    67. -m|–manual)
    68. shift
    69. tmpINS=’manual’
    70. ;;
    71. -apt|–mirror)
    72. shift
    73. isMirror=’1′
    74. tmpMirror=”$1″
    75. shift
    76. ;;
    77. -ssl)
    78. shift
    79. tmpSSL=”$1″
    80. shift
    81. ;;
    82. –firmware)
    83. shift
    84. tmpFW=’1′
    85. ;;
    86. *)
    87. echo -ne ” Usage:ntbash DebianNET.sht-d/–debian [33[33m33[04mdists-name33[0m]ntttt-u/–ubuntu [33[04mdists-name33[0m]ntttt-v/–ver [32/33[33m33[04mi38633[0m|64/amd64]ntttt–ip-addr/–ip-gate/–ip-maskntttt-apt/–mirrorntttt-dd/–imagentttt-a/–autontttt-m/–manualn”
    88. exit 1;
    89. ;;
    90. esac
    91. done

    92. [[ “$EUID” -ne ‘0’ ]] && echo “Error:This script must be run as root!” && exit 1;
    93. [[ -f ‘/boot/grub/grub.cfg’ ]] && GRUBOLD=’0′ && GRUBDIR=’/boot/grub’ && GRUBFILE=’grub.cfg’;
    94. [[ -z “$GRUBDIR” ]] && [[ -f ‘/boot/grub2/grub.cfg’ ]] && GRUBOLD=’0′ && GRUBDIR=’/boot/grub2′ && GRUBFILE=’grub.cfg’;
    95. [[ -z “$GRUBDIR” ]] && [[ -f ‘/boot/grub/grub.conf’ ]] && GRUBOLD=’1′ && GRUBDIR=’/boot/grub’ && GRUBFILE=’grub.conf’;
    96. [ -z “$GRUBDIR” -o -z “$GRUBFILE” ] && echo -ne “Error! nNot Found grub path.n” && exit 1;

    97. [[ -n “$tmpVER” ]] && {
    98. [ “$tmpVER” == ’32’ -o “$tmpVER” == ‘i386′ ] && VER=’i386’;
    99. [ “$tmpVER” == ’64’ -o “$tmpVER” == ‘amd64′ ] && VER=’amd64’;
    100. }
    101. [[ -z “$VER” ]] && VER=’i386′;

    102. [[ -z “$linuxdists” ]] && linuxdists=’debian’;

    103. [[ “$isMirror” == ‘1’ ]] && [[ -n “$tmpMirror” ]] && {
    104. tmpDebianMirror=”$(echo -n “$tmpMirror” |grep -Eo ‘.*.(w+)’)”;
    105. echo -n “$tmpDebianMirror” |grep -q ‘://’;
    106. [[ $? -eq ‘0’ ]] && {
    107. DebianMirror=”$(echo -n “$tmpDebianMirror” |awk -F’://’ ‘{print $2}’)”;
    108. } || {
    109. DebianMirror=”$(echo -n “$tmpDebianMirror”)”;
    110. }
    111. } || {
    112. [[ “$linuxdists” == ‘debian’ ]] && DebianMirror=’httpredir.debian.org’;
    113. [[ “$linuxdists” == ‘ubuntu’ ]] && DebianMirror=’archive.ubuntu.com’;
    114. }

    115. [[ -z “$DebianMirrorDirectory” ]] && [[ -n “$DebianMirror” ]] && [[ -n “$tmpMirror” ]] && {
    116. DebianMirrorDirectory=”$(echo -n “$tmpMirror” |awk -F”${DebianMirror}” ‘{print $2}’ |sed ‘s//$//g’)”;
    117. }

    118. [[ -n “$DebianMirror” ]] && {
    119. [[ “$DebianMirrorDirectory” == ‘/’ ]] && {
    120. [[ “$linuxdists” == ‘debian’ ]] && DebianMirrorDirectory=’/debian’;
    121. [[ “$linuxdists” == ‘ubuntu’ ]] && DebianMirrorDirectory=’/ubuntu’;
    122. }
    123. [[ -z “$DebianMirrorDirectory” ]] && {
    124. [[ “$linuxdists” == ‘debian’ ]] && DebianMirrorDirectory=’/debian’;
    125. [[ “$linuxdists” == ‘ubuntu’ ]] && DebianMirrorDirectory=’/ubuntu’;
    126. }
    127. }

    128. [[ -z “$tmpDIST” ]] && {
    129. [[ “$linuxdists” == ‘debian’ ]] && DIST=’wheezy’;
    130. [[ “$linuxdists” == ‘ubuntu’ ]] && DIST=’trusty’;
    131. }

    132. [[ -z “$DIST” ]] && {
    133. DIST=”$(echo “$tmpDIST” |sed -r ‘s/(.*)/L1/’)”;
    134. echo “$DIST” |grep -q ‘[0-9]’;
    135. [[ $? -eq ‘0’ ]] && {
    136. isDigital=”$(echo “$DIST” |grep -o ‘[0-9.]{1,}’ |sed -n ‘1h;1!H;$g;s/n//g;$p’ |cut -d’.’ -f1)”;
    137. [[ -n $isDigital ]] && {
    138. [[ “$isDigital” == ‘7’ ]] && DIST=’wheezy’;
    139. [[ “$isDigital” == ‘8’ ]] && DIST=’jessie’;
    140. [[ “$isDigital” == ‘9’ ]] && DIST=’stretch’;
    141. [[ “$isDigital” == ’10’ ]] && DIST=’buster’;
    142. }
    143. }
    144. }

    145. [[ “$ddMode” == ‘1’ ]] && {
    146. [[ -n “$tmpURL” ]] && {
    147. linuxdists=’debian’;
    148. DIST=’jessie’;
    149. VER=’amd64′;
    150. tmpINS=’auto’;
    151. DDURL=”$tmpURL”
    152. echo “$DDURL” |grep -q ‘^http://|^ftp://|^https://’;
    153. [[ $? -ne ‘0’ ]] && echo ‘Please input vaild URL,Only support http://, ftp:// and https:// !’ && exit 1;
    154. [[ -n “$tmpSSL” ]] && SSL_SUPPORT=”$tmpSSL”;
    155. [[ -z “$SSL_SUPPORT” ]] && SSL_SUPPORT=’https://moeclub.org/get-wget_udeb_amd64′;
    156. } || {
    157. echo ‘Please input vaild URL! ‘;
    158. exit 1;
    159. }
    160. }

    161. DistsList=”$(wget –no-check-certificate -qO- “http://$DebianMirror$DebianMirrorDirectory/dists/” |grep -o ‘href=.*/”‘ |cut -d'”‘ -f2 |sed ‘/-|old|Debian|experimental|stable|test|sid|devel/d’ |grep ‘^[^/]’ |sed -n ‘1h;1!H;$g;s/n//g;s///;/g;$p’)”;
    162. for CheckDEB in `echo “$DistsList” |sed ‘s/;/n/g’`
    163. do
    164. [[ “$CheckDEB” == “$DIST” ]] && FindDists=’1′;
    165. [[ “$FindDists” == ‘1’ ]] && break;
    166. done
    167. [[ “$FindDists” == ‘0’ ]] && {
    168. echo -ne ‘nThe dists version not found, Please check it! nn’
    169. bash $0 error;
    170. exit 1;
    171. }

    172. [[ -n “$tmpINS” ]] && {
    173. [[ “$tmpINS” == ‘auto’ ]] && inVNC=’n’;
    174. [[ “$tmpINS” == ‘manual’ ]] && inVNC=’y’;
    175. }

    176. [ -n “$ipAddr” ] && [ -n “$ipMask” ] && [ -n “$ipGate” ] && setNet=’1′;
    177. [[ -n “$tmpWORD” ]] && myPASSWORD=”$tmpWORD”;
    178. [[ -n “$tmpFW” ]] && INCFW=”$tmpFW”;
    179. [[ -z “$myPASSWORD” ]] && myPASSWORD=’Vicer’;
    180. [[ -z “$INCFW” ]] && INCFW=’0′;

    181. clear && echo -e “n33[36m# Install33[0mn”

    182. ASKVNC(){
    183. inVNC=’y’;
    184. [[ “$ddMode” == ‘0’ ]] && {
    185. echo -ne “33[34mCan you login VNC?33[0me[33m[e[32mye[33m/n]e[0m “
    186. read tmpinVNC
    187. [[ -n “$inVNCtmp” ]] && inVNC=”$tmpinVNC”
    188. }
    189. [ “$inVNC” == ‘y’ -o “$inVNC” == ‘Y’ ] && inVNC=’y’;
    190. [ “$inVNC” == ‘n’ -o “$inVNC” == ‘N’ ] && inVNC=’n’;
    191. }

    192. [ “$inVNC” == ‘y’ -o “$inVNC” == ‘n’ ] || ASKVNC;
    193. [[ “$linuxdists” == ‘debian’ ]] && LinuxName=’Debian’;
    194. [[ “$linuxdists” == ‘ubuntu’ ]] && LinuxName=’Ubuntu’;
    195. [[ “$ddMode” == ‘0’ ]] && {
    196. [[ “$inVNC” == ‘y’ ]] && echo -e “33[34mManual Mode33[0m insatll 33[33m$LinuxName33[0m [33[33m$DIST33[0m] [33[33m$VER33[0m] in VNC. “
    197. [[ “$inVNC” == ‘n’ ]] && echo -e “33[34mAuto Mode33[0m insatll 33[33m$LinuxName33[0m [33[33m$DIST33[0m] [33[33m$VER33[0m]. “
    198. }
    199. [[ “$ddMode” == ‘1’ ]] && {
    200. echo -ne “33[34mAuto Mode33[0m insatll 33[33mWindows33[0mn[33[33m$DDURL33[0m]n”
    201. }

    202. echo -e “n[33[33m$DIST33[0m] [33[33m$VER33[0m] Downloading…”
    203. [[ -z “$DebianMirror” ]] && echo -ne “33[31mError! 33[0mGet debian mirror fail! n” && exit 1
    204. [[ -z “$DebianMirrorDirectory” ]] && echo -ne “33[31mError! 33[0mGet debian mirror directory fail! n” && exit 1
    205. wget –no-check-certificate -qO ‘/boot/initrd.gz’ “http://$DebianMirror$DebianMirrorDirectory/dists/$DIST/main/installer-$VER/current/images/netboot/$linuxdists-installer/$VER/initrd.gz”
    206. [[ $? -ne ‘0’ ]] && echo -ne “33[31mError! 33[0mDownload ‘initrd.gz’ failed! n” && exit 1
    207. wget –no-check-certificate -qO ‘/boot/linux’ “http://$DebianMirror$DebianMirrorDirectory/dists/$DIST/main/installer-$VER/current/images/netboot/$linuxdists-installer/$VER/linux”
    208. [[ $? -ne ‘0’ ]] && echo -ne “33[31mError! 33[0mDownload ‘linux’ failed! n” && exit 1
    209. [[ “$INCFW” == ‘1’ ]] && [[ “$linuxdists” == ‘debian’ ]] && {
    210. wget –no-check-certificate -qO ‘/boot/firmware.cpio.gz’ “http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/$DIST/current/firmware.cpio.gz”
    211. [[ $? -ne ‘0’ ]] && echo -ne “33[31mError! 33[0mDownload ‘firmware’ failed! n” && exit 1
    212. }


    213. [[ “$setNet” == ‘1’ ]] && {
    214. IPv4=”$ipAddr”;
    215. MASK=”$ipMask”;
    216. GATE=”$ipGate”;
    217. } || {
    218. 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}’)”;
    219. [[ -n “$DEFAULTNET” ]] && 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}’)”;
    220. IPv4=”$(echo -n “$IPSUB” |cut -d’/’ -f1)”;
    221. NETSUB=”$(echo -n “$IPSUB” |grep -o ‘/[0-9]{1,2}’)”;
    222. 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}’)”;
    223. [[ -n “$NETSUB” ]] && 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)”;
    224. }

    225. [[ -n “$GATE” ]] && [[ -n “$MASK” ]] && [[ -n “$IPv4” ]] || {
    226. echo “Not found `ip command`, It will use `route command`.”
    227. ipNum() {
    228. local IFS=’.’;
    229. read ip1 ip2 ip3 ip4 <<<“$1”;
    230. echo $((ip1*(1<<24)+ip2*(1<<16)+ip3*(1<<8)+ip4));
    231. }

    232. SelectMax(){
    233. ii=0;
    234. for 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}’`
    235. do
    236. NumTMP=”$(ipNum $IPITEM)”;
    237. eval “arrayNum[$ii]=’$NumTMP,$IPITEM'”;
    238. ii=$[$ii+1];
    239. done
    240. echo ${arrayNum[@]} |sed ‘s/s/n/g’ |sort -n -k 1 -t ‘,’ |tail -n1 |cut -d’,’ -f2;
    241. }

    242. [[ -z $IPv4 ]] && 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)”;
    243. [[ -z $GATE ]] && GATE=”$(SelectMax 2)”;
    244. [[ -z $MASK ]] && MASK=”$(SelectMax 3)”;

    245. [[ -n “$GATE” ]] && [[ -n “$MASK” ]] && [[ -n “$IPv4” ]] || {
    246. echo “Error! Not configure network. “;
    247. exit 1;
    248. }
    249. }

    250. [[ “$setNet” != ‘1’ ]] && [[ -f ‘/etc/network/interfaces’ ]] && {
    251. [[ -z “$(sed -n ‘/iface.*inet static/p’ /etc/network/interfaces)” ]] && AutoNet=’1′ || AutoNet=’0′;
    252. [[ -d /etc/network/interfaces.d ]] && {
    253. ICFGN=”$(find /etc/network/interfaces.d -name ‘*.cfg’ |wc -l)” || ICFGN=’0′;
    254. [[ “$ICFGN” -ne ‘0’ ]] && {
    255. for NetCFG in `ls -1 /etc/network/interfaces.d/*.cfg`
    256. do
    257. [[ -z “$(cat $NetCFG | sed -n ‘/iface.*inet static/p’)” ]] && AutoNet=’1′ || AutoNet=’0′;
    258. [[ “$AutoNet” -eq ‘0’ ]] && break;
    259. done
    260. }
    261. }
    262. }

    263. [[ “$setNet” != ‘1’ ]] && [[ -d ‘/etc/sysconfig/network-scripts’ ]] && {
    264. ICFGN=”$(find /etc/sysconfig/network-scripts -name ‘ifcfg-*’ |grep -v ‘lo’|wc -l)” || ICFGN=’0’;
    265. [[ “$ICFGN” -ne ‘0’ ]] && {
    266. for NetCFG in `ls -1 /etc/sysconfig/network-scripts/ifcfg-* |grep -v ‘lo$’ |grep -v ‘:[0-9]{1,}’`
    267. do
    268. [[ -n “$(cat $NetCFG | sed -n ‘/BOOTPROTO.*[dD][hH][cC][pP]/p’)” ]] && AutoNet=’1′ || {
    269. AutoNet=’0′ && . $NetCFG;
    270. [[ -n $NETMASK ]] && MASK=”$NETMASK”;
    271. [[ -n $GATEWAY ]] && GATE=”$GATEWAY”;
    272. }
    273. [[ “$AutoNet” -eq ‘0’ ]] && break;
    274. done
    275. }
    276. }

    277. [[ ! -f $GRUBDIR/$GRUBFILE ]] && echo “Error! Not Found $GRUBFILE. ” && exit 1;

    278. [[ ! -f $GRUBDIR/$GRUBFILE.old ]] && [[ -f $GRUBDIR/$GRUBFILE.bak ]] && mv -f $GRUBDIR/$GRUBFILE.bak $GRUBDIR/$GRUBFILE.old;
    279. mv -f $GRUBDIR/$GRUBFILE $GRUBDIR/$GRUBFILE.bak;
    280. [[ -f $GRUBDIR/$GRUBFILE.old ]] && cat $GRUBDIR/$GRUBFILE.old >$GRUBDIR/$GRUBFILE || cat $GRUBDIR/$GRUBFILE.bak >$GRUBDIR/$GRUBFILE;

    281. [[ “$GRUBOLD” == ‘0’ ]] && {
    282. CFG0=”$(awk ‘/menuentry /{print NR}’ $GRUBDIR/$GRUBFILE|head -n 1)”;
    283. CFG2=”$(awk ‘/menuentry /{print NR}’ $GRUBDIR/$GRUBFILE|head -n 2 |tail -n 1)”;
    284. CFG1=””;
    285. for tmpCFG in `awk ‘/}/{print NR}’ $GRUBDIR/$GRUBFILE`
    286. do
    287. [ “$tmpCFG” -gt “$CFG0” -a “$tmpCFG” -lt “$CFG2″ ] && CFG1=”$tmpCFG”;
    288. done
    289. [[ -z “$CFG1” ]] && {
    290. echo “Error! read $GRUBFILE. “;
    291. exit 1;
    292. }

    293. sed -n “$CFG0,$CFG1″p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
    294. [[ -f /tmp/grub.new ]] && [[ “$(grep -c ‘{‘ /tmp/grub.new)” -eq “$(grep -c ‘}’ /tmp/grub.new)” ]] || {
    295. echo -ne “33[31mError! 33[0mNot configure $GRUBFILE. n”;
    296. exit 1;
    297. }

    298. sed -i “/menuentry.*/cmenuentry ‘Install OS [$DIST $VER]’ –class debian –class gnu-linux –class gnu –class os {” /tmp/grub.new
    299. [[ “$(grep -c ‘{‘ /tmp/grub.new)” -eq “$(grep -c ‘}’ /tmp/grub.new)” ]] || {
    300. echo “Error! configure append $GRUBFILE. “;
    301. exit 1;
    302. }
    303. sed -i “/echo.*Loading/d” /tmp/grub.new;
    304. }

    305. [[ “$GRUBOLD” == ‘1’ ]] && {
    306. CFG0=”$(awk ‘/title /{print NR}’ $GRUBDIR/$GRUBFILE|head -n 1)”;
    307. CFG1=”$(awk ‘/title /{print NR}’ $GRUBDIR/$GRUBFILE|head -n 2 |tail -n 1)”;
    308. [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 == $CFG0 ] && sed -n “$CFG0,$”p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
    309. [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 != $CFG0 ] && sed -n “$CFG0,$CFG1″p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
    310. [[ ! -f /tmp/grub.new ]] && echo “Error! configure append $GRUBFILE. ” && exit 1;
    311. sed -i “/title.*/ctitle ‘Install OS [$DIST $VER]'” /tmp/grub.new;
    312. sed -i ‘/^#/d’ /tmp/grub.new;
    313. }

    314. [[ -n “$(grep ‘initrd.*/’ /tmp/grub.new |awk ‘{print $2}’ |tail -n 1 |grep ‘^/boot/’)” ]] && Type=’InBoot’ || Type=’NoBoot’;

    315. LinuxKernel=”$(grep ‘linux.*/’ /tmp/grub.new |awk ‘{print $1}’ |head -n 1)”;
    316. [[ -z $LinuxKernel ]] && LinuxKernel=”$(grep ‘kernel.*/’ /tmp/grub.new |awk ‘{print $1}’ |head -n 1)”;
    317. LinuxIMG=”$(grep ‘initrd.*/’ /tmp/grub.new |awk ‘{print $1}’ |tail -n 1)”;

    318. [[ “$Type” == ‘InBoot’ ]] && {
    319. sed -i “/$LinuxKernel.*//ct$LinuxKernelt/boot/linux auto=true hostname=$linuxdists domain= — quiet” /tmp/grub.new;
    320. sed -i “/$LinuxIMG.*//ct$LinuxIMGt/boot/initrd.gz” /tmp/grub.new;
    321. }

    322. [[ “$Type” == ‘NoBoot’ ]] && {
    323. sed -i “/$LinuxKernel.*//ct$LinuxKernelt/linux auto=true hostname=$linuxdists domain= — quiet” /tmp/grub.new;
    324. sed -i “/$LinuxIMG.*//ct$LinuxIMGt/initrd.gz” /tmp/grub.new;
    325. }

    326. sed -i ‘$an’ /tmp/grub.new;

    327. [[ “$inVNC” == ‘n’ ]] && {
    328. GRUBPATCH=’0′;

    329. [ -f ‘/etc/network/interfaces’ -o -d ‘/etc/sysconfig/network-scripts’ ] || {
    330. echo “Error, Not found interfaces config.”;
    331. exit 1;
    332. }

    333. sed -i ”${CFG0}’in’ $GRUBDIR/$GRUBFILE;
    334. sed -i ”${CFG0}’r /tmp/grub.new’ $GRUBDIR/$GRUBFILE;
    335. [[ -f $GRUBDIR/grubenv ]] && sed -i ‘s/saved_entry/#saved_entry/g’ $GRUBDIR/grubenv;

    336. [[ -d /boot/tmp ]] && rm -rf /boot/tmp;
    337. mkdir -p /boot/tmp;
    338. cd /boot/tmp;
    339. gzip -d < ../initrd.gz | cpio –extract –verbose –make-directories –no-absolute-filenames >>/dev/null 2>&1

    340. cat >/boot/tmp/preseed.cfg<<EOF
    341. d-i debian-installer/locale string en_US
    342. d-i console-setup/layoutcode string us

    343. d-i keyboard-configuration/xkb-keymap string us

    344. d-i netcfg/choose_interface select auto

    345. d-i netcfg/disable_autoconfig boolean true
    346. d-i netcfg/dhcp_failed note
    347. d-i netcfg/dhcp_options select Configure network manually
    348. d-i netcfg/get_ipaddress string $IPv4
    349. d-i netcfg/get_netmask string $MASK
    350. d-i netcfg/get_gateway string $GATE
    351. d-i netcfg/get_nameservers string 8.8.8.8
    352. d-i netcfg/no_default_route boolean true
    353. d-i netcfg/confirm_static boolean true

    354. d-i hw-detect/load_firmware boolean true

    355. d-i mirror/country string manual
    356. d-i mirror/http/hostname string $DebianMirror
    357. d-i mirror/http/directory string $DebianMirrorDirectory
    358. d-i mirror/http/proxy string

    359. d-i passwd/root-login boolean ture
    360. d-i passwd/make-user boolean false
    361. d-i passwd/root-password password $myPASSWORD
    362. d-i passwd/root-password-again password $myPASSWORD
    363. d-i user-setup/allow-password-weak boolean true
    364. d-i user-setup/encrypt-home boolean false

    365. d-i clock-setup/utc boolean true
    366. d-i time/zone string US/Eastern
    367. d-i clock-setup/ntp boolean true

    368. d-i preseed/early_command string anna-install libfuse2-udeb fuse-udeb ntfs-3g-udeb fuse-modules-3.16.0-4-amd64-di
    369. d-i partman/early_command string
    370. debconf-set partman-auto/disk “$(list-devices disk |head -n1)”;
    371. wget -qO- ‘$DDURL’ |gunzip -dc |/bin/dd of=$(list-devices disk |head -n1);
    372. mount.ntfs-3g $(list-devices partition |head -n1) /mnt;
    373. cd ‘/mnt/ProgramData/Microsoft/Windows/Start Menu/Programs’;
    374. cd Start* || cd start*;
    375. cp -f ‘https://7xlpwglucc.r.worldssl.net/net.bat’ ‘./net.bat’;
    376. /sbin/reboot;

    377. debconf-set grub-installer/bootdev string “$(list-devices disk |head -n1)”;
    378. umount /media || true;


    379. d-i partman/mount_style select uuid
    380. d-i partman-auto/init_automatically_partition select Guided – use entire disk
    381. d-i partman-auto/method string regular
    382. d-i partman-lvm/device_remove_lvm boolean true
    383. d-i partman-md/device_remove_md boolean true
    384. d-i partman-auto/choose_recipe select atomic
    385. d-i partman-partitioning/confirm_write_new_label boolean true
    386. d-i partman/choose_partition select finish
    387. d-i partman-lvm/confirm boolean true
    388. d-i partman-lvm/confirm_nooverwrite boolean true
    389. d-i partman/confirm boolean true
    390. d-i partman/confirm_nooverwrite boolean true

    391. d-i debian-installer/allow_unauthenticated boolean true

    392. tasksel tasksel/first multiselect minimal
    393. d-i pkgsel/update-policy select none
    394. d-i pkgsel/include string openssh-server
    395. d-i pkgsel/upgrade select none

    396. popularity-contest popularity-contest/participate boolean false

    397. d-i grub-installer/only_debian boolean true
    398. d-i grub-installer/bootdev string default
    399. d-i finish-install/reboot_in_progress note
    400. d-i debian-installer/exit/reboot boolean true
    401. d-i preseed/late_command string
    402. sed -ri ‘s/^#?PermitRootLogin.*/PermitRootLogin yes/g’ /target/etc/ssh/sshd_config;
    403. sed -ri ‘s/^#?PasswordAuthentication.*/PasswordAuthentication yes/g’ /target/etc/ssh/sshd_config;
    404. EOF

    405. [[ “$setNet” == ‘0’ ]] && [[ “$AutoNet” == ‘1’ ]] && {
    406. sed -i ‘/netcfg/disable_autoconfig/d’ /boot/tmp/preseed.cfg
    407. sed -i ‘/netcfg/dhcp_options/d’ /boot/tmp/preseed.cfg
    408. sed -i ‘/netcfg/get_.*/d’ /boot/tmp/preseed.cfg
    409. sed -i ‘/netcfg/confirm_static/d’ /boot/tmp/preseed.cfg
    410. }

    411. [[ “$DIST” == ‘trusty’ ]] && GRUBPATCH=’1′
    412. [[ “$DIST” == ‘wily’ ]] && GRUBPATCH=’1′

    413. [[ “$GRUBPATCH” == ‘1’ ]] && {
    414. sed -i ‘s/^d-i grub-installer/bootdev string default//g’ /boot/tmp/preseed.cfg
    415. }
    416. [[ “$GRUBPATCH” == ‘0’ ]] && {
    417. sed -i ‘s/debconf-set grub-installer/bootdev.*”;//g’ /boot/tmp/preseed.cfg
    418. }
    419. [[ “$DIST” == ‘xenial’ ]] && {
    420. sed -i ‘s/^d-i clock-setup/ntp boolean true/d-i clock-setup/ntp boolean false/g’ /boot/tmp/preseed.cfg
    421. }

    422. [[ “$linuxdists” == ‘debian’ ]] && {
    423. sed -i ‘/user-setup/allow-password-weak/d’ /boot/tmp/preseed.cfg
    424. sed -i ‘/user-setup/encrypt-home/d’ /boot/tmp/preseed.cfg
    425. sed -i ‘/pkgsel/update-policy/d’ /boot/tmp/preseed.cfg
    426. sed -i ‘s/umount /media.*true; //g’ /boot/tmp/preseed.cfg
    427. }

    428. [[ “$ddMode” == ‘1’ ]] && {
    429. WinDHCP(){
    430. echo -ne “@ECHO OFFrncd4057d404245ProgramData4557Microsoft57Windows57Start40Menu57Programs57Startup42rndel4057f4057q40net56batrnrn” >’/boot/tmp/net.tmp’;
    431. }
    432. WinNoDHCP(){
    433. echo -ne “@ECHO OFFrncd567645windir45GetAdminrnif40exist4045windir45GetAdmin4050del4057f4057q404245windir45GetAdmin425140else4050rnecho40CreateObject^5042Shell56Application42^5156ShellExecute404245~s04254404245524254404242544042runas42544061407676404245temp45Admin56vbs42rn4245temp45Admin56vbs42rndel4057f4057q404245temp45Admin56vbs42rnexit4057b406251rnfor4057f4042tokens=635242404545i40in405047netsh40interface40show40interface40^|more40+340^|findstr4057R4042u672cu5730565240u4ee5u592a565240Local565240Ethernet42475140do4050set40EthName=4545j51rnnetsh40-c40interface40ip40set40address40name=4245EthName454240source=static40address=$IPv440mask=$MASK40gateway=$GATErnnetsh40-c40interface40ip40add40dnsservers40name=4245EthName454240address=7056705670567040index=140validate=nornnetsh40-c40interface40ip40add40dnsservers40name=4245EthName454240address=7056705664566440index=240validate=norncd4057d404245ProgramData4557Microsoft57Windows57Start40Menu57Programs57Startup42rndel4057f4057q40net56batrnrn” >’/boot/tmp/net.tmp’;
    434. }
    435. [[ “$setNet” == ‘1’ ]] && WinNoDHCP;
    436. [[ “$setNet” == ‘0’ ]] && {
    437. [[ “$AutoNet” -eq ‘1’ ]] && WinDHCP;
    438. [[ “$AutoNet” -eq ‘0’ ]] && WinNoDHCP;
    439. }
    440. iconv -f ‘UTF-8’ -t ‘GBK’ ‘/boot/tmp/net.tmp’ -o ‘/boot/tmp/net.bat’
    441. rm -rf ‘/boot/tmp/net.tmp’
    442. echo “$DDURL” |grep -q ‘^https://’
    443. [[ $? -eq ‘0’ ]] && {
    444. echo -ne ‘nAdd ssl support…n’
    445. [[ -n $SSL_SUPPORT ]] && {
    446. wget –no-check-certificate -qO- “$SSL_SUPPORT” |tar -x
    447. [[ ! -f /boot/tmp/usr/bin/wget ]] && echo ‘Error! SSL_SUPPORT.’ && exit 1;
    448. sed -i ‘s/wget -qO-//usr/bin/wget –no-check-certificate –retry-connrefused –tries=7 –continue -qO-/g’ /boot/tmp/preseed.cfg
    449. [[ $? -eq ‘0’ ]] && echo -ne ‘Success! nn’
    450. } || {
    451. echo -ne ‘Not ssl support package! nn’;
    452. exit 1;
    453. }
    454. }
    455. }

    456. [[ “$ddMode” == ‘0’ ]] && {
    457. sed -i ‘/anna-install/d’ /boot/tmp/preseed.cfg
    458. sed -i ‘s/wget.*/sbin/reboot; //g’ /boot/tmp/preseed.cfg
    459. }
    460. [[ “$INCFW” == ‘1’ ]] && [[ “$linuxdists” == ‘debian’ ]] && [[ -f ‘/boot/firmware.cpio.gz’ ]] && {
    461. gzip -d < ../firmware.cpio.gz | cpio –extract –verbose –make-directories –no-absolute-filenames >>/dev/null 2>&1
    462. }
    463. rm -rf ../initrd.gz;
    464. find . | cpio -H newc –create –verbose | gzip -9 > ../initrd.gz;
    465. rm -rf /boot/tmp;
    466. }

    467. [[ “$inVNC” == ‘y’ ]] && {
    468. sed -i ‘$in’ $GRUBDIR/$GRUBFILE
    469. sed -i ‘$r /tmp/grub.new’ $GRUBDIR/$GRUBFILE
    470. echo -e “n33[33m33[04mIt will reboot! nPlease look at VNC! nSelect33[0m33[32m Install OS [$DIST $VER] 33[33m33[4mto install system.33[04mnn33[31m33[04mThere is some information for you.nDO NOT CLOSE THE WINDOW! 33[0mn”
    471. echo -e “33[35mIPv4ttNETMASKttGATEWAY33[0m”
    472. echo -e “33[36m33[04m$IPv433[0mt33[36m33[04m$MASK33[0mt33[36m33[04m$GATE33[0mnn”

    473. read -n 1 -p “Press Enter to reboot…” INP
    474. [[ “$INP” != ” ]] && echo -ne ‘b nn’;
    475. }

    476. chown root:root $GRUBDIR/$GRUBFILE
    477. chmod 444 $GRUBDIR/$GRUBFILE

    478. sleep 3 && reboot >/dev/null 2>&1

无限制全自动dd安装Windows
突破没有VNC,没有救援模式,内存比dd包小的限制.
使用Debian Live CD中的busybox做中间媒介,经过复杂的处理,
使本机的网络参数传进Windows操作系统中,
即使没有DHCP能够让Windows获取网络参数,
也能让Windows操作系统在开机的第一时间能够连通网络.

 
全文转载自 Vicer 的博客 萌咖,一字未改(因为也不会改 )。

赞(1) 打赏
转载请注明:峰网博客 » [ Linux Shell ] 通用无限制在 Linux VPS 上一键全自动 dd 安装 Windows 系统

评论 抢沙发

评论前必须登录!

 

网站建设

企业专线联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏