腾讯云海外服务器Window切换为linux系统(从Window DD 到 Linux) ...

打印 上一主题 下一主题

主题 1875|帖子 1875|积分 5625


   腾讯云提示:不支持重装为该镜像,非中国大陆地域不支持Linux系统和Windows系统之间互转
  买了腾讯云的海外服务器,重装系统的时候发现无法切换,直接dd到linux系统,以下是全过程。记录一下。
主要是用到一个开源项目,可以在系统之间切换。理论上支持所有的云服务器,开源项目地址:ttps://github.com/bin456789/reinstall
根据当前的系统选择命令

当前系统是Linux时

国外服务器:
  1. curl -O https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh || wget -O reinstall.sh $_
复制代码
国内服务器:
  1. curl -O https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh || wget -O reinstall.sh $_
复制代码
当前系统是
Windows时
   服务器注意,请先关闭 Windows Defender 的 实时掩护 功能。该功能会阻止 certutil 下载任何文件。
  国外服务器:
  1. certutil -urlcache -f -split https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat
复制代码
国内服务器:
  1. certutil -urlcache -f -split https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat
复制代码
解决 Windows 7 下无法下载脚本:
由于不支持 TLS 1.2、SHA-256、根证书没有更新等原因,Vista,7 和 Server 2008 (R2) 可能无法自动下载脚本,因此需要手动下载,具体操作如下:
用 IE 下载 (先在 IE 高级设置里启用 TLS 1.2),或者通过长途桌面,将这两个文件保存到同一个目次


  • https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat
  • https://www.cygwin.com/setup-x86.exe
使用时运行下载的 reinstall.bat
下载安装环境

我的是国外服务器,当前是window环境,使用:
  1. curl -O https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh || wget -O reinstall.sh $_
复制代码
最好是管理员启动CMD命令

接着在cmd中输入命令,这个命令其实就是下载reinstall.bat这个文件。
   所以实行这个命令之前最好先看一下当前的cmd是在哪个路径下,最好cd到自己想要下载的目次里再去实行。
  这里趁便提一下,如果切换不已往,直接使用d:这个命令强制切换盘符,然后再去cd d:/test如许子使用
  

显示命令成功完成才行,这里有可能计算机会有报错,提示文件不安全被拦截,需要关闭Windows Defender 的 实时掩护 功能。该功能会阻止 certutil 下载任何文件。

实行完会生成一个bat文件在当前cmd所在的目次下。

如图所示,我的是在C:\Users\Administrator>目次下

然后选中以管理员省份运行

这时候就会自动下载了,运行了以后这个.bat文件实际上实行并自己下载了setup-x86.exe这个文件。而且启动这个exe文件下载了环境。

等候下载中

下载完成,然后就可以去使用命令去切换系统了。

选择安装的linux系统

环境好了这时候就可以再次运行bat,而且携带参数,实行命令选择系统了。众所周知linux有许多发行版本,比我我要安装ubuntu 22.04
   我这里是:C:\Users\Administrator>reinstall.bat ubuntu 22.04 如下图所示
  

  • 用户名 root 默认暗码 123@@@,首次开机可能要等几分钟才气成功登录
  • 安装最新版可不输入版本号
可选参数


  • --password PASSWORD 设置暗码
  • --ssh-port PORT 修改 SSH 端口(安装期间观察日志用,也用于新系统)
  • --web-port PORT 修改 Web 端口(安装期间观察日志用)
  • --hold 2 安装结束后不重启,此时可以 SSH 登录修改系统内容,系统挂载在 /os (此功能不支持 Debian/Kali)
我这里就用默认暗码。

其实这个时候当前目次下已经有reinstall.sh这个脚本了,也可以使用如bash reinstall.sh ubuntu 22如许的方式来安装ubuntu
  1. bash reinstall.sh anolis      7|8
  2.                   rocky       8|9
  3.                   redhat      8|9   --img='http://xxx.com/xxx.qcow2'
  4.                   almalinux   8|9
  5.                   opencloudos 8|9
  6.                   centos      9|10
  7.                   oracle      7|8|9
  8.                   fedora      40|41
  9.                   nixos       24.11
  10.                   debian      9|10|11|12
  11.                   openeuler   20.03|22.03|24.03
  12.                   alpine      3.18|3.19|3.20|3.21
  13.                   opensuse    15.5|15.6|tumbleweed
  14.                   ubuntu      16.04|18.04|20.04|22.04|24.04 [--minimal]
  15.                   kali
  16.                   arch
  17.                   gentoo
复制代码
等候一会,直接实行shutdown /r /t 0重启主机

然后使用默认的端口22,用户名root和暗码123@@@去毗连就能连上了,可能这时候还没完全好
提示:
   To view logs run:
    tail -fn+l /reinstall.log
  这个时候等一等,也可以输入上面的命令看一下日志信息

显示Welcome to Ubuntu这个才是完成了。再去登录之前的window就无法进去了。

可能碰到的问题

我安装的时候出现了这个问题:
  1. C:\Users\Administrator>C:\Users\Administrator\reinstall.bat
  2. The system cannot execute the specified program.
  3. "Failed to install Cygwin."
  4. C:\Users\Administrator>
复制代码

可以尝试以下方案进行解决(手动安装的setup-x86_64.exe,然后在线运行了bat脚本):

  • 首先确认当前目次
  1. cd C:\Users\Administrator
复制代码

  • 查抄setup-x86_64.exe是否存在
  1. dir setup-x86_64.exe
复制代码

  • 尝试手动下载Cygwin setup文件
  1. certutil -urlcache -f -split "http://www.cygwin.com/setup-x86_64.exe" "setup-x86_64.exe"
复制代码

  • 以管理员身份运行以下命令:
  1. setup-x86_64.exe --allow-unsupported-windows --quiet-mode --only-site --site http://mirror.nju.edu.cn/sourceware/cygwin --root C:\cygwin --local-package-dir %tmp%\cygwin-local-package-dir --packages curl,cpio,p7zip,bind-utils,ipcalc,dos2unix,binutils,jq,xz,gzip,zstd,openssl,libiconv
复制代码
别的,请确保:

  • 使用管理员权限运行CMD
  • 临时关闭杀毒软件
reinstall备份
  1. @echo off
  2. mode con cp select=437 >nul
  3. setlocal EnableDelayedExpansion
  4. set confhome=https://raw.githubusercontent.com/bin456789/reinstall/main
  5. set confhome_cn=https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main
  6. rem set confhome_cn=https://jihulab.com/bin456789/reinstall/-/raw/main
  7. rem 65001 代码页会乱码
  8. rem 不要用 :: 注释
  9. rem 否则可能会出现 系统找不到指定的驱动器
  10. rem Windows 7 SP1 winhttp 默认不支持 tls 1.2
  11. rem https://support.microsoft.com/en-us/topic/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-winhttp-in-windows-c4bd73d2-31d7-761e-0178-11268bb10392
  12. rem 有些系统根证书没更新
  13. rem 所以不要用https
  14. rem 进入脚本目录
  15. cd /d %~dp0
  16. rem 检查是否有管理员权限
  17. fltmc >nul 2>&1
  18. if errorlevel 1 (
  19.     echo Please run as administrator^^!
  20.     exit /b
  21. )
  22. rem 有时 %tmp% 带会话 id,且文件夹不存在
  23. rem https://learn.microsoft.com/troubleshoot/windows-server/shell-experience/temp-folder-with-logon-session-id-deleted
  24. if not exist %tmp% (
  25.     md %tmp%
  26. )
  27. rem 检查是否国内
  28. if not exist geoip (
  29.     rem 部分地区 www.cloudflare.com 被墙
  30.     call :download http://dash.cloudflare.com/cdn-cgi/trace %~dp0geoip || goto :download_failed
  31. )
  32. findstr /c:"loc=CN" geoip >nul
  33. if not errorlevel 1 (
  34.     rem mirrors.tuna.tsinghua.edu.cn 会强制跳转 https
  35.     set mirror=http://mirror.nju.edu.cn
  36.     if defined confhome_cn (
  37.         set confhome=!confhome_cn!
  38.     ) else if defined github_proxy (
  39.         echo !confhome! | findstr /c:"://raw.githubusercontent.com/" >nul
  40.         if not errorlevel 1 (
  41.             set confhome=!confhome:http://=https://!
  42.             set confhome=!confhome:https://raw.githubusercontent.com=%github_proxy%!
  43.         )
  44.     )
  45. ) else (
  46.     rem 服务器在美国 equinix 机房,不是 cdn
  47.     set mirror=http://mirrors.kernel.org
  48. )
  49. rem pkgs 改动了才重新运行 Cygwin 安装程序
  50. set pkgs=curl,cpio,p7zip,bind-utils,ipcalc,dos2unix,binutils,jq,xz,gzip,zstd,openssl,libiconv
  51. set tags=%tmp%\cygwin-installed-%pkgs%
  52. if not exist "%tags%" (
  53.     rem win10 arm 支持运行 x86 软件
  54.     rem win11 arm 支持运行 x86 和 x86_64 软件
  55.     rem wmic os get osarchitecture 显示中文
  56.     rem wmic ComputerSystem get SystemType 显示英文
  57.     rem SystemType
  58.     rem windows 11 24h2 没有 wmic
  59.     rem 有的系统精简了 powershell
  60.     where wmic >nul 2>&1
  61.     if not errorlevel 1 (
  62.         for /f "tokens=*" %%a in ('wmic ComputerSystem get SystemType ^| find /i "based"') do (
  63.             set "SystemType=%%a"
  64.         )
  65.     ) else (
  66.         for /f "delims=" %%a in ('powershell -NoLogo -NoProfile -NonInteractive -Command "(Get-WmiObject win32_computersystem).SystemType"') do (
  67.             set "SystemType=%%a"
  68.         )
  69.     )
  70.     rem BuildNumber
  71.     for /f "tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuildNumber') do (
  72.          set /a BuildNumber=%%a
  73.     )
  74.     set CygwinEOL=1
  75.     echo !SystemType! | find "ARM" > nul
  76.     if not errorlevel 1 (
  77.         if !BuildNumber! GEQ 22000 (
  78.             set CygwinEOL=0
  79.         )
  80.     ) else (
  81.         echo !SystemType! | find "x64" > nul
  82.         if not errorlevel 1 (
  83.             if !BuildNumber! GEQ 9600 (
  84.                 set CygwinEOL=0
  85.             )
  86.         )
  87.     )
  88.     rem win7/8 cygwin 已 EOL,不能用最新 cygwin 源,而要用 Cygwin Time Machine 源
  89.     rem 但 Cygwin Time Machine 没有国内源
  90.     rem 为了保证国内下载速度, cygwin EOL 统一使用 cygwin-archive x86 源
  91.     if !CygwinEOL! == 1 (
  92.         set CygwinArch=x86
  93.         set dir=/sourceware/cygwin-archive/20221123
  94.     ) else (
  95.         set CygwinArch=x86_64
  96.         set dir=/sourceware/cygwin
  97.     )
  98.     rem 下载 Cygwin
  99.     if not exist setup-!CygwinArch!.exe (
  100.         call :download http://www.cygwin.com/setup-!CygwinArch!.exe %~dp0setup-!CygwinArch!.exe || goto :download_failed
  101.     )
  102.     rem 安装 Cygwin
  103.     set site=!mirror!!dir!
  104.     start /wait setup-!CygwinArch!.exe ^
  105.         --allow-unsupported-windows ^
  106.         --quiet-mode ^
  107.         --only-site ^
  108.         --site !site! ^
  109.         --root %SystemDrive%\cygwin ^
  110.         --local-package-dir %tmp%\cygwin-local-package-dir ^
  111.         --packages %pkgs% ^
  112.         && type nul >"%tags%"
  113.         if errorlevel 1 (
  114.             echo "Failed to install Cygwin."
  115.             exit /b 1
  116.         )
  117. )
  118. rem 在c盘根目录下执行 cygpath -ua . 会得到 /cygdrive/c,因此末尾要有 /
  119. for /f %%a in ('%SystemDrive%\cygwin\bin\cygpath -ua ./') do set thisdir=%%a
  120. rem 下载 reinstall.sh
  121. if not exist reinstall.sh (
  122.     call :download_with_curl %confhome%/reinstall.sh %thisdir%reinstall.sh || goto :download_failed
  123.     call :chmod a+x %thisdir%reinstall.sh
  124. )
  125. rem 为每个参数添加引号,使参数正确传递到 bash
  126. for %%a in (%*) do (
  127.     set "param=!param! "%%~a""
  128. )
  129. rem 方法1
  130. %SystemDrive%\cygwin\bin\dos2unix -q '%thisdir%reinstall.sh'
  131. %SystemDrive%\cygwin\bin\bash -l -c '%thisdir%reinstall.sh !param!'
  132. rem 方法2
  133. rem %SystemDrive%\cygwin\bin\bash reinstall.sh %*
  134. rem 再在 reinstall.sh 里运行 source /etc/profile
  135. exit /b
  136. :download
  137. rem bits 要求有 Content-Length 才能下载
  138. rem 据说如果网络设为“按流量计费” bits 也无法下载
  139. rem https://learn.microsoft.com/en-us/windows/win32/bits/http-requirements-for-bits-downloads
  140. rem certutil 会被 windows Defender 报毒
  141. rem windows server 2019 要用第二条 certutil 命令
  142. echo Download: %~1 %~2
  143. del /q "%~2" 2>nul
  144. if exist "%~2" (echo Cannot delete %~2 & exit /b 1)
  145. if not exist "%~2" certutil -urlcache -f -split "%~1" "%~2" >nul
  146. if not exist "%~2" certutil -urlcache -split "%~1" "%~2" >nul
  147. if not exist "%~2" exit /b 1
  148. exit /b
  149. :download_with_curl
  150. rem 加 --insecure 防止以下错误
  151. rem curl: (77) error setting certificate verify locations:
  152. rem   CAfile: /etc/ssl/certs/ca-certificates.crt
  153. rem   CApath: none
  154. echo Download: %~1 %~2
  155. %SystemDrive%\cygwin\bin\curl -L --insecure "%~1" -o "%~2"
  156. exit /b
  157. :chmod
  158. %SystemDrive%\cygwin\bin\chmod "%~1" "%~2"
  159. exit /b
  160. :download_failed
  161. echo Download failed.
  162. exit /b 1
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

万有斥力

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表