本文最后更新于 2019-09-12【63 天前】,文中所描述的信息可能已发生改变,请谨慎使用。如有问题或建议,欢迎在文章底部留言参与讨论!

有时候,可能因为种种原因需要更换 VPS 的系统,而商家提供的系统非常有限,亦或者商家提供的系统里有内鬼,这时就需要一个纯净的系统、可定义的系统,那么,利用 dd 来进行重装、更换系统是你最好的选择。

Linux Windows转换 - Quanyin说:imtqy.com

Linux to Windows/Linux

前提

dd 命令是 Linux 下用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换的一个命令。通过 dd 命令,我们可以将指定文件覆盖到指定位置,包括启动引导和内核等,这正是 dd 安装系统的核心。

此方法仅限于初始系统为 Linux 系统

为了顺利的进行,需要安装一些必要的软件,需在 root 用户下进行,如不在,请切换到 root 或者使用 sudo

## Debian/Ubuntu 系
apt-get update
apt-get install -y xz-utils openssl gawk file wget screen

## RedHat/CentOS 系
yum update
yum install -y glibc-common xz openssl gawk file glibc-common wget screen

进入到 screen 模式,防止因连接、网络原因中断:

screen -S DD
适用于由 GRUB 引导的 CentOS,Ubuntu,Debian 系统

MoeClub 版

原文参考:https://moeclub.org/2018/04/03/603/

下载及说明

wget --no-check-certificate -qO InstallNET.sh 'https://moeclub.org/attachment/LinuxShell/InstallNET.sh' && chmod a+x InstallNET.sh
Usage:
  bash InstallNET.sh    -d/--debian [dist-name]
                        -u/--ubuntu [dist-name]
                        -c/--centos [dist-version]
                        -v/--ver [32/i386|64/amd64]
                        --ip-addr/--ip-gate/--ip-mask
                        -apt/-yum/--mirror
                        -dd/--image
                        -a/-m

# dist-name: 发行版本代号
# dist-version: 发行版本号
# -apt/-yum/--mirror : 使用定义镜像
# -a/-m : 询问是否能进入VNC自行操作. -a 为不提示(一般用于全自动安装), -m 为提示.

使用方法

#使用默认镜像全自动安装
bash InstallNET.sh -d 8 -v 64 -a

#使用自定义镜像全自动安装
bash InstallNET.sh -c 6.10 -v 64 -a --mirror 'http://mirror.centos.org/centos'

# 以下示例中,将X.X.X.X替换为自己的网络参数.
# --ip-addr :IP Address/IP地址
# --ip-gate :Gateway   /网关
# --ip-mask :Netmask   /子网掩码

#使用自定义镜像全自动安装
#bash InstallNET.sh -u 9 -v 64 -a --mirror 'http://mirrors.ustc.edu.cn/debian/'

#使用自定义镜像自定义网络参数全自动安装
#bash InstallNET.sh -u 16.04 -v 64 -a --ip-addr x.x.x.x --ip-gate x.x.x.x --ip-mask x.x.x.x --mirror 'http://archive.ubuntu.com/ubuntu'

#使用自定义网络参数全自动dd方式安装
#bash InstallNET.sh --ip-addr x.x.x.x --ip-gate x.x.x.x --ip-mask x.x.x.x -dd 'https://moeclub.org/onedrive/IMAGE/Windows/win7emb_x86.tar.gz'

#使用自定义网络参数全自动dd方式安装存储在谷歌网盘中的镜像(调用文件ID的方式)
#bash InstallNET.sh --ip-addr x.x.x.x --ip-gate x.x.x.x --ip-mask x.x.x.x -dd "https://image.moeclub.org/GoogleDrive/1cqVl2wSGx92UTdhOxU9pW3wJgmvZMT_J"

#使用自定义网络参数全自动dd方式安装存储在谷歌网盘中的镜像
#bash InstallNET.sh --ip-addr x.x.x.x --ip-gate x.x.x.x --ip-mask x.x.x.x -dd "https://image.moeclub.org/GoogleDrive/1cqVl2wSGx92UTdhOxU9pW3wJgmvZMT_J"

#国内推荐使用USTC源
#--mirror 'http://mirrors.ustc.edu.cn/debian/'

可用镜像地址

# 推荐使用带有 /GoogleDrive/ 链接, 速度更快.
# 当然也可以使用自己GoogleDrive中储存的镜像,使用方式:
  https://image.moeclub.org/GoogleDrive/

# win7emb_x86.tar.gz:
  https://image.moeclub.org/GoogleDrive/1srhylymTjYS-Ky8uLw4R6LCWfAo1F3s7 
  https://moeclub.org/onedrive/IMAGE/Windows/win7emb_x86.tar.gz

# win8.1emb_x64.tar.gz:
  https://image.moeclub.org/GoogleDrive/1cqVl2wSGx92UTdhOxU9pW3wJgmvZMT_J
  https://moeclub.org/onedrive/IMAGE/Windows/win8.1emb_x64.tar.gz

# win10ltsc_x64.tar.gz:
  https://image.moeclub.org/GoogleDrive/1OVA3t-ZI2arkM4E4gKvofcBN9aoVdneh
  https://moeclub.org/onedrive/IMAGE/Windows/win10ltsc_x64.tar.gz

说明

  • 全自动安装默认root密码: MoeClub.org,安装完成后请立即更改密码
  • 远程登陆账号为: Administrator,远程登陆密码为: Vicer
  • 建议通过加参数 -p 密码 的方式自定义密码

Meowlove 版

源站已挂,使用 github 链接:https://github.com/MeowLove/Network-Reinstall-System-Modify

使用方法

### 下载脚本
wget --no-check-certificate -qO ~/Network-Reinstall-System-Modify.sh https://github.com/MeowLove/Network-Reinstall-System-Modify/raw/master/Network-Reinstall-System-Modify.sh && chmod a+x ~/Network-Reinstall-System-Modify.sh

### 两种方案
#### 安装裸机系统部署平台
#### 仅适用于高端用户,手动安装任意系统。可通过网络 ISO 或 iPXE 安装任意系统。
bash ~/Network-Reinstall-System-Modify.sh -CXT_Bare-metal_System_Deployment_Platform

#### 安装DD系统
#### 如果您不了解这意味着什么,请不要进行操作。%ULR% 应该替换为您自己的映像地址。
bash ~/Network-Reinstall-System-Modify.sh -DD "%URL%"
通用解决方案
一键网络重装纯净CentOS 7(推荐)
bash ~/Network-Reinstall-System-Modify.sh -CentOS_7

一键网络重装纯净Debian 9(推荐)
bash ~/Network-Reinstall-System-Modify.sh -Debian_9

一键网络重装纯净Ubuntu 18.04(推荐)
bash ~/Network-Reinstall-System-Modify.sh -Ubuntu_18.04

一键网络重装纯净Windows Server 2019(推荐)
bash ~/Network-Reinstall-System-Modify.sh -Windows_Server_2019

说明

  • 注意:重复重装此系统前,在主机上面板重装一次系统,在一些主机商上安装的成功率似乎并不是很高。
  • 如果安装成功无法联网,vnc 手动修改为静态 ip :vi /etc/sysconfig/network-scripts/ifcfg-eth0,修改之后保存并重启:

    BOOTPROTO=static #dhcp改为static
    IPADDR=192.168.1.100 #静态IP
    GATEWAY=192.168.1.255 #默认网关
    NETMASK=255.255.255.0 #子网掩码
  • 默认系统账号:Administrator 默认系统密码:cxthhhhh.com 默认远程端口:3389

Teddysun 版

参考:https://teddysun.com/545.html

使用方法

wget -qO DebianNET.sh qiu.sh/dd && bash DebianNET.sh -dd "DD download URL"
### 后面跟的是 dd 包直链地址

镜像地址

https://delivery.yuntu.moe/teddysun/cn_windows2019.gz
https://delivery.yuntu.moe/teddysun/en_windows2019.gz
https://delivery.yuntu.moe/teddysun/ja_windows2019.gz
https://delivery.yuntu.moe/teddysun/cn_windows2016.gz
https://delivery.yuntu.moe/teddysun/en_windows2016.gz
https://delivery.yuntu.moe/teddysun/ja_windows2016.gz
https://delivery.yuntu.moe/teddysun/cn_windows2012r2.gz
https://delivery.yuntu.moe/teddysun/en_windows2012r2.gz
https://delivery.yuntu.moe/teddysun/ja_windows2012r2.gz

说明

远程桌面的默认用户名为 administrator,密码为 Password147

Laosiji 版

老司机:https://www.hostloc.com/space-uid-23758.html

汇总版

原文参考:https://www.hostloc.com/thread-583956-1-1.html

集合了 Linux 和 WIN 包,Linux 版本包括 CentOS6-7、Ubuntu 14 16 18、Debian 7-10,Windows 系统集合了萌咖大佬、老司机、MeowLove等人的系统,包含 win7 2003 2006 2012 2008 2016 2019等,同时也支持自定义

使用方法

##镜像文件在OneDrive
wget -N --no-check-certificate https://raw.githubusercontent.com/veip007/dd/master/dd-od.sh && chmod +x dd-od.sh && ./dd-od.sh

##镜像文件在GoogleDrive
wget -N --no-check-certificate https://raw.githubusercontent.com/veip007/dd/master/dd-gd.sh && chmod +x dd-gd.sh && ./dd-gd.sh

初始默认密码在命令开始时有提示,linux 默认密码:MoeClub.orgcxthhhhh.com

Windows to Linux

参考:https://moeclub.org/2018/10/31/670/
把下面的命令保存为 win32loader.bat 后执行即可:

@ECHO OFF&@PUSHD %~DP0 &TITLE Win32Loader
setlocal enabledelayedexpansion
::Author MoeClub.org
color 87
cd.>%windir%\GetAdmin
if exist %windir%\GetAdmin (del /f /q "%windir%\GetAdmin") else (
echo CreateObject^("Shell.Application"^).ShellExecute "%~s0", "%*", "", "runas", 1 >> "%temp%\Admin.vbs"
"%temp%\Admin.vbs"
del /s /q "%temp%\Admin.vbs"
exit /b 2)
cls

echo * Init Win32Loader.
set download=0
set try_download=1
set URL=https://moeclub.org/attachment/WindowsSoftware

:InitCheck
mkdir "%SystemDrive%\win32-loader" >NUL 2>NUL
if exist "%SystemDrive%\Windows\System32\WindowsPowerShell" (
set use_ps=1
) else (
set use_ps=0
echo Not found PowerShell.
)

:Init
if %use_ps% equ 1 (
goto InitIt
) else (
goto InitFail
)

:InitIt
set try_download=0
call:DownloadFile "!URL!/g2ldr/g2ldr","%SystemDrive%\g2ldr"
call:DownloadFile "!URL!/g2ldr/g2ldr.mbr","%SystemDrive%\g2ldr.mbr"
call:DownloadFile "!URL!/g2ldr/grub.cfg","%SystemDrive%\win32-loader\grub.cfg"
goto InitDone

:InitFail
echo.
echo Go to "!URL!/g2ldr",
echo Please download them by yourself.
echo '%SystemDrive%\g2ldr'
echo '%SystemDrive%\g2ldr.mbr'
echo '%SystemDrive%\win32-loader\grub.cfg'
echo Press [ENTER] when you finished.
pause >NUL 2>NUL
goto InitDone

:InitDone
if !try_download! equ 0 (
set InitOption=InitFail
) else (
set InitOption=Init
)
if not exist "%SystemDrive%\g2ldr" goto !InitOption!
if not exist "%SystemDrive%\g2ldr.mbr" goto !InitOption!
if not exist "%SystemDrive%\win32-loader\grub.cfg" goto !InitOption!

:Image
echo.
echo * Please select initrd mode.
echo     [1] Online download
echo     [2] Local file
choice /n /c 12 /m Select:
if errorlevel 2 goto LocalMode
if errorlevel 1 goto OnlineMode
goto Image

:OnlineMode
echo.
echo * Please select source.
echo     [1] by MoeClub [Linux](Debian8, DHCP or VNC Support)
echo     [2] by MoeClub [Windows](Win7EMB, DHCP or VNC Support)
echo     [3] by MoeClub [Windows](Win8.1EMB, DHCP or VNC Support)
echo     [4] by yourself
choice /n /c 1234 /m Select:
if errorlevel 4 goto Yourself
if errorlevel 3 goto MoeClub_Win8.1EMB
if errorlevel 2 goto MoeClub_Win7EMB
if errorlevel 1 goto MoeClub
goto OnlineMode
:Yourself
echo.
echo if 'initrd.img' URL is 'https://moeclub.org/onedrive/IMAGE/Loader/DebianJessie/initrd.img', 
echo Please input 'https://moeclub.org/onedrive/IMAGE/Loader/DebianJessie'.
set /p IMG_URL_TMP=URL :
if defined IMG_URL_TMP (
set IMG_URL=%IMG_URL_TMP%
goto Download
) else (
goto MoeClub
)
:MoeClub_Win8.1EMB
set IMG_URL=https://moeclub.org/onedrive/IMAGE/Loader/Win8.1EMB
set INITRD_SHA1=473617320316CCB5A88EDE72CBA6AF501B148071
set VMLINUZ_SHA1=C84BF89869868B0325F56F1C0E62604A83B9443F
goto Download
:MoeClub_Win7EMB
set IMG_URL=https://moeclub.org/onedrive/IMAGE/Loader/Win7EMB
set INITRD_SHA1=C1BF2A50802BC23A7EC7373AB4CB8F5A905D5860
set VMLINUZ_SHA1=C84BF89869868B0325F56F1C0E62604A83B9443F
goto Download
:MoeClub
set IMG_URL=https://moeclub.org/onedrive/IMAGE/Loader/DebianJessie
set INITRD_SHA1=934CFCD5DC855F360AE72AFCB8E6276FABFBCDD5
set VMLINUZ_SHA1=C84BF89869868B0325F56F1C0E62604A83B9443F
goto Download
:Download
if %use_ps% equ 1 (
echo.
echo Downloading 'initrd.img'...
call:DownloadFile "!IMG_URL!/initrd.img","%SystemDrive%\win32-loader\initrd.img"
call:CheckFile "%SystemDrive%\win32-loader\initrd.img"
call:CheckSUM "%SystemDrive%\win32-loader\initrd.img","%INITRD_SHA1%"
echo Downloading 'vmlinuz'...
call:DownloadFile "!IMG_URL!/vmlinuz","%SystemDrive%\win32-loader\vmlinuz"
call:CheckFile "%SystemDrive%\win32-loader\vmlinuz"
call:CheckSUM "%SystemDrive%\win32-loader\vmlinuz","%VMLINUZ_SHA1%"
set download=1
) else (
echo Not support online download, auto change Local initrd.
goto LocalMode
)

:LocalMode
if !download! equ 0 (
echo.
echo Please put 'initrd.img' and 'vmlinuz' to '%SystemDrive%\win32-loader' .
echo Press [ENTER] when you finished.
pause >NUL 2>NUL
)

:Done0
set download=0
if exist "%SystemDrive%\win32-loader\initrd.img" (
goto Done1
) else (
echo Not found '%SystemDrive%\win32-loader\initrd.img' .
goto LocalMode
)

:Done1
set download=0
if exist "%SystemDrive%\win32-loader\vmlinuz" (
goto Done
) else (
echo Not found '%SystemDrive%\win32-loader\vmlinuz' .
goto LocalMode
)

:Done
echo.
echo Press [ENTER] to continue...
echo IT WILL REBOOT IMMEDIATELY
pause >NUL 2>NUL
echo.
call:CheckFile "%SystemDrive%\g2ldr"
call:CheckFile "%SystemDrive%\g2ldr.mbr"
call:CheckFile "%SystemDrive%\win32-loader\grub.cfg"
call:CheckFile "%SystemDrive%\win32-loader\initrd.img"
call:CheckFile "%SystemDrive%\win32-loader\vmlinuz"
call:CheckSUM "%SystemDrive%\g2ldr","2FCB1009A64C127AD3CC39FF0B5E068B38CBA772"
call:CheckSUM "%SystemDrive%\g2ldr.mbr","29401C8BC951F0AEFD30DC370A3797D1055D64B4"
call:CheckSUM "%SystemDrive%\win32-loader\grub.cfg","58C499EFEE7E60790B3FE2166B536C04B6717B14"
set id={01234567-89ab-cdef-fedc-ba9876543210}
bcdedit /create %id% /d "Debian GUN/Linux" /application bootsector >NUL 2>NUL
bcdedit /set %id% device partition=%SystemDrive% >NUL 2>NUL
bcdedit /set %id% path \g2ldr.mbr >NUL 2>NUL
bcdedit /displayorder %id% /addlast >NUL 2>NUL
bcdedit /bootsequence %id% /addfirst >NUL 2>NUL
shutdown -r -t 0

:CheckSUM
for /f "delims=: tokens=2" %%i in ('powershell.exe "& {Get-FileHash -Algorithm SHA1 -Path %1|Format-List -Property HASH}"') do (set tmp_var=%%i)
set var=%tmp_var:~1%
if "%var%" == %2 (
echo Check %1 SHA1 OK.
) else (
if "%var%" == "CommandNotFoundException" (
echo Check %1 SHA1 SKIP.
) else (
echo Check %1 SHA1 FAIL.
call:ErrorExit
)
)
GOTO:EOF

:CheckFile
if not exist %1 (
echo Not found %1 .
call:ErrorExit
)
GOTO:EOF

:DownloadFile
powershell.exe -command "& {$client = new-object System.Net.WebClient; $client.DownloadFile('%1','%2')}" >NUL 2>NUL
GOTO:EOF

:ErrorExit
echo. 
echo Error, Clear CACHE...
del /S /F /Q "%SystemDrive%\g2ldr" >NUL 2>NUL
del /S /F /Q "%SystemDrive%\g2ldr.mbr" >NUL 2>NUL
rd /S /Q "%SystemDrive%\win32-loader" >NUL 2>NUL
echo Press [ENTER] to exit.
pause >NUL 2>NUL
exit 1
GOTO:EOF

Windows 系统 KMS 激活

管理员身份打开命令提示符,执行

slmgr /skms kms.03k.org
slmgr /ato
slmgr /xpr

第一个命令也可以更换为其它的 KMS 激活服务器。

文章目录

推荐使用:阿里云 云翼计划学生优惠、ECS、轻量应用等产品与服务【 点击注册

本文作者:Quanyin Tang

本文链接:网络重装系统一键脚本,在 Linux 和 Windows 之间轻松转换 - https://www.imtqy.com/network-reinstall-system.html

版权声明:如无特别声明,本文即为原创文章,仅代表个人观点,版权归 Quanyin 所有,未经允许禁止转载,经授权转载请注明出处!