把境外腾讯云轻量云服务器的Windows系统切换成LINUX

原创 鸣金同学  2026-09-21 00:36:42  阅读 278 次 评论 0 条
摘要:

腾讯云轻量应用服务器(Lighthouse)境外节点‌不支持‌在控制台直接通过“重装系统”将 Windows 切换为 Linux,也不支持 Linux 切换为 Windows。这是腾讯云针对非中国大陆地域实例的限制策略。‌‌若当前系统是 Windows,需使用第三方脚本进行底层重装(DD 方式)。以下是基于开源项目 bin456789/reinstall 的操作方案,该方案通过在 Windows 环境下运行脚本引导安装 Linux。操作步骤‌准备工作‌登录腾讯云控制台,确保服务器处于运行状态。通

把境外腾讯云轻量云服务器的Windows系统切换成LINUX 操作系统 第1张

腾讯云轻量应用服务器(Lighthouse)境外节点不支持在控制台直接通过“重装系统”将 Windows 切换为 Linux,也不支持 Linux 切换为 Windows。这是腾讯云针对非中国大陆地域实例的限制策略。‌‌

若当前系统是 Windows,需使用第三方脚本进行底层重装(DD 方式)。以下是基于开源项目 bin456789/reinstall 的操作方案,该方案通过在 Windows 环境下运行脚本引导安装 Linux。

操作步骤

  1. 准备工作

    • 登录腾讯云控制台,确保服务器处于运行状态。

    • 通过远程桌面(RDP)登录 Windows 服务器。

    • 重要‌:暂时关闭 Windows Defender 的实时保护功能,否则可能拦截脚本下载或执行。

    • 备份服务器内所有重要数据,重装将清空系统盘。‌‌

  2. 下载并执行脚本
    以‌管理员身份‌打开 CMD(命令提示符),执行以下命令下载并重命名脚本文件:


当前系统是Linux时

国外服务器:

curl -O https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh || wget -O reinstall.sh $_

国内服务器:

curl -O https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh || wget -O reinstall.sh $_

当前系统是 Windows时

服务器注意,请先关闭 Windows Defender 的 实时保护 功能。该功能会阻止 certutil 下载任何文件。

国外服务器:

certutil -urlcache -f -split 
或者下面这个
certutil -urlcache -f -split https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat reinstall.bat

国内服务器:

certutil -urlcache -f -split https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat

*注:若下载失败,可尝试使用代理地址或手动下载 reinstall.batsetup-x86_64.exe (Cygwin) 到同一目录。*‌‌‌



下载安装环境

我的是国外服务器,当前是window环境,使用:

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系统切换成LINUX 操作系统 第2张
显示命令成功完成才行,这里有可能计算机会有报错,提示文件不安全被拦截,需要关闭Windows Defender 的 实时保护 功能。该功能会阻止 certutil 下载任何文件。

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


把境外腾讯云轻量云服务器的Windows系统切换成LINUX 操作系统 第3张如图所示,我的是在C:\Users\Administrator>目录下
把境外腾讯云轻量云服务器的Windows系统切换成LINUX 操作系统 第4张然后选中以管理员省份运行

这时候就会自动下载了,运行了以后这个.bat文件实际上执行并自己下载了setup-x86.exe这个文件。并且启动这个exe文件下载了环境。
把境外腾讯云轻量云服务器的Windows系统切换成LINUX 操作系统 第5张等待下载中

下载完成,然后就可以去使用命令去切换系统了。
把境外腾讯云轻量云服务器的Windows系统切换成LINUX 操作系统 第6张选择安装的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

bash reinstall.sh anolis      7|8
                  rocky       8|9
                  redhat      8|9   --img='http://xxx.com/xxx.qcow2'
                  almalinux   8|9
                  opencloudos 8|9
                  centos      9|10
                  oracle      7|8|9
                  fedora      40|41
                  nixos       24.11
                  debian      9|10|11|12
                  openeuler   20.03|22.03|24.03
                  alpine      3.18|3.19|3.20|3.21
                  opensuse    15.5|15.6|tumbleweed
                  ubuntu      16.04|18.04|20.04|22.04|24.04 [--minimal]
                  kali
                  arch
                  gentoo


等待一会,直接执行 shutdown /r /t 0 重启主机
把境外腾讯云轻量云服务器的Windows系统切换成LINUX 操作系统 第7张然后使用默认的端口22,用户名root和密码123@@@去连接就能连上了,可能这时候还没完全好

提示:

    To view logs run:

    tail -fn+l /reinstall.log

这个时候等一等,也可以输入上面的命令看一下日志信息
把境外腾讯云轻量云服务器的Windows系统切换成LINUX 操作系统 第8张显示Welcome to Ubuntu这个才是完成了。再去登录之前的window就无法进去了。
把境外腾讯云轻量云服务器的Windows系统切换成LINUX 操作系统 第9张可能遇到的问题

我安装的时候出现了这个问题:

C:\Users\Administrator>C:\Users\Administrator\reinstall.bat
The system cannot execute the specified program.
"Failed to install Cygwin."
C:\Users\Administrator>

把境外腾讯云轻量云服务器的Windows系统切换成LINUX 操作系统 第10张

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

    首先确认当前目录

cd C:\Users\Administrator



    检查setup-x86_64.exe是否存在

dir setup-x86_64.exe

    尝试手动下载Cygwin setup文件

certutil -urlcache -f -split "http://www.cygwin.com/setup-x86_64.exe" "setup-x86_64.exe"



    以管理员身份运行以下命令:

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备份

@echo off
mode con cp select=437 >nul
setlocal EnableDelayedExpansion
 
set confhome=https://raw.githubusercontent.com/bin456789/reinstall/main
set confhome_cn=https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main
rem set confhome_cn=https://jihulab.com/bin456789/reinstall/-/raw/main
 
rem 65001 代码页会乱码
 
rem 不要用 :: 注释
rem 否则可能会出现 系统找不到指定的驱动器
 
rem Windows 7 SP1 winhttp 默认不支持 tls 1.2
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
rem 有些系统根证书没更新
rem 所以不要用https
rem 进入脚本目录
cd /d %~dp0
 
rem 检查是否有管理员权限
fltmc >nul 2>&1
if errorlevel 1 (
    echo Please run as administrator^^!
    exit /b
)
 
rem 有时 %tmp% 带会话 id,且文件夹不存在
rem https://learn.microsoft.com/troubleshoot/windows-server/shell-experience/temp-folder-with-logon-session-id-deleted
if not exist %tmp% (
    md %tmp%
)
 
rem 检查是否国内
if not exist geoip (
    rem 部分地区 www.cloudflare.com 被墙
    call :download http://dash.cloudflare.com/cdn-cgi/trace %~dp0geoip || goto :download_failed
)
findstr /c:"loc=CN" geoip >nul
if not errorlevel 1 (
    rem mirrors.tuna.tsinghua.edu.cn 会强制跳转 https
    set mirror=http://mirror.nju.edu.cn
    if defined confhome_cn (
        set confhome=!confhome_cn!
    ) else if defined github_proxy (
        echo !confhome! | findstr /c:"://raw.githubusercontent.com/" >nul
        if not errorlevel 1 (
            set confhome=!confhome:http://=https://!
            set confhome=!confhome:https://raw.githubusercontent.com=%github_proxy%!
        )
    )
) else (
    rem 服务器在美国 equinix 机房,不是 cdn
    set mirror=http://mirrors.kernel.org
)
 
rem pkgs 改动了才重新运行 Cygwin 安装程序
set pkgs=curl,cpio,p7zip,bind-utils,ipcalc,dos2unix,binutils,jq,xz,gzip,zstd,openssl,libiconv
set tags=%tmp%\cygwin-installed-%pkgs%
if not exist "%tags%" (
    rem win10 arm 支持运行 x86 软件
    rem win11 arm 支持运行 x86 和 x86_64 软件
    rem wmic os get osarchitecture 显示中文
    rem wmic ComputerSystem get SystemType 显示英文
 
    rem SystemType
    rem windows 11 24h2 没有 wmic
    rem 有的系统精简了 powershell
    where wmic >nul 2>&1
    if not errorlevel 1 (
        for /f "tokens=*" %%a in ('wmic ComputerSystem get SystemType ^| find /i "based"') do (
            set "SystemType=%%a"
        )
    ) else (
        for /f "delims=" %%a in ('powershell -NoLogo -NoProfile -NonInteractive -Command "(Get-WmiObject win32_computersystem).SystemType"') do (
            set "SystemType=%%a"
        )
    )
 
    rem BuildNumber
    for /f "tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuildNumber') do (
         set /a BuildNumber=%%a
    )
 
    set CygwinEOL=1
 
    echo !SystemType! | find "ARM" > nul
    if not errorlevel 1 (
        if !BuildNumber! GEQ 22000 (
            set CygwinEOL=0
        )
    ) else (
        echo !SystemType! | find "x64" > nul
        if not errorlevel 1 (
            if !BuildNumber! GEQ 9600 (
                set CygwinEOL=0
            )
        )
    )
 
    rem win7/8 cygwin 已 EOL,不能用最新 cygwin 源,而要用 Cygwin Time Machine 源
    rem 但 Cygwin Time Machine 没有国内源
    rem 为了保证国内下载速度, cygwin EOL 统一使用 cygwin-archive x86 源
    if !CygwinEOL! == 1 (
        set CygwinArch=x86
        set dir=/sourceware/cygwin-archive/20221123
    ) else (
        set CygwinArch=x86_64
        set dir=/sourceware/cygwin
    )
 
    rem 下载 Cygwin
    if not exist setup-!CygwinArch!.exe (
        call :download http://www.cygwin.com/setup-!CygwinArch!.exe %~dp0setup-!CygwinArch!.exe || goto :download_failed
    )
 
    rem 安装 Cygwin
    set site=!mirror!!dir!
    start /wait setup-!CygwinArch!.exe ^
        --allow-unsupported-windows ^
        --quiet-mode ^
        --only-site ^
        --site !site! ^
        --root %SystemDrive%\cygwin ^
        --local-package-dir %tmp%\cygwin-local-package-dir ^
        --packages %pkgs% ^
        && type nul >"%tags%"
 
        if errorlevel 1 (
            echo "Failed to install Cygwin."
            exit /b 1
        )
)
 
rem 在c盘根目录下执行 cygpath -ua . 会得到 /cygdrive/c,因此末尾要有 /
for /f %%a in ('%SystemDrive%\cygwin\bin\cygpath -ua ./') do set thisdir=%%a
 
rem 下载 reinstall.sh
if not exist reinstall.sh (
    call :download_with_curl %confhome%/reinstall.sh %thisdir%reinstall.sh || goto :download_failed
    call :chmod a+x %thisdir%reinstall.sh
)
 
rem 为每个参数添加引号,使参数正确传递到 bash
for %%a in (%*) do (
    set "param=!param! "%%~a""
)
 
rem 方法1
%SystemDrive%\cygwin\bin\dos2unix -q '%thisdir%reinstall.sh'
%SystemDrive%\cygwin\bin\bash -l -c '%thisdir%reinstall.sh !param!'
 
rem 方法2
rem %SystemDrive%\cygwin\bin\bash reinstall.sh %*
rem 再在 reinstall.sh 里运行 source /etc/profile
exit /b
 
 
 
 
 
:download
rem bits 要求有 Content-Length 才能下载
rem 据说如果网络设为“按流量计费” bits 也无法下载
rem https://learn.microsoft.com/en-us/windows/win32/bits/http-requirements-for-bits-downloads
rem certutil 会被 windows Defender 报毒
rem windows server 2019 要用第二条 certutil 命令
echo Download: %~1 %~2
del /q "%~2" 2>nul
if exist "%~2" (echo Cannot delete %~2 & exit /b 1)
if not exist "%~2" certutil -urlcache -f -split "%~1" "%~2" >nul
if not exist "%~2" certutil -urlcache -split "%~1" "%~2" >nul
if not exist "%~2" exit /b 1
exit /b
 
:download_with_curl
rem 加 --insecure 防止以下错误
rem curl: (77) error setting certificate verify locations:
rem   CAfile: /etc/ssl/certs/ca-certificates.crt
rem   CApath: none
echo Download: %~1 %~2
%SystemDrive%\cygwin\bin\curl -L --insecure "%~1" -o "%~2"
exit /b
 
:chmod
%SystemDrive%\cygwin\bin\chmod "%~1" "%~2"
exit /b
 
:download_failed
echo Download failed.
exit /b 1


注意事项

  • 风险警告‌:此操作属于非官方支持的底层重装,存在一定风险,请确保已备份数据。

  • 网络要求‌:服务器需能访问 GitHub 或相关镜像源,若境外服务器网络受限,可能导致下载失败。

  • 驱动兼容‌:大部分腾讯云轻量云实例兼容该脚本,但若遇到驱动问题(如网卡无法识别),可能需要手动注入驱动或选择更通用的发行版(如 Debian)。

  • 后续维护‌:重装后,原 Windows 授权失效,系统将变为纯 Linux 环境,后续可通过控制台正常重装为其他 Linux 发行版。‌‌


本文地址:https://tugouli.exiu.org/3757.html
版权声明:本文为原创文章,版权归 淹不死的狗 所有,欢迎分享本文,转载请保留出处!
NEXT:已经是最新一篇了

评论已关闭!