【宅技术】[Linux] 网络脚本一键重装 Ubuntu/CentOS/Debian

发布于 2021-08-03  13517 次阅读


【更新:补充重装成 CentOS 7 的方法】

适用于由 GRUB 引导的系统,使用官方发行版去掉模板预装的软件,同时也可以解决内核版本与软件不兼容的问题。
只要有 root 权限,还您一个纯净的系统。

网络重装 Ubuntu/CentOS/Debian 一键脚本

  • 能够全自动重装 Debian/Ubuntu/CentOS 等系统
  • 同时提供dd安装镜像功能,例如:全自动无救援dd安装windows系统
  • 全自动安装 CentOS 时默认提供 VNC 功能,可使用 VNC Viewer 查看进度,VNC 端口为1或者5901,可自行尝试连接(成功后 VNC 功能会消失)
  • 目前 CentOS 系统只支持任意版本重装为 CentOS 6.9 及以下版本(欲重装成 CentOS 7 请看后续补充内容)

全自动安装模式的默认 root 密码为MoeClub.org,安装完成后请立即使用passwd命令更改密码。[/scode]此脚本不能用于 OpenVZ 虚拟化的机子!

准备

确保安装了脚本所需软件

#Debian/Ubuntu:
apt-get install -y xz-utils openssl gawk file

#RedHat/CentOS:
yum install -y xz openssl gawk file

如果报错,请运行下面的命令后再试

#Debian/Ubuntu:
apt-get update

#RedHat/CentOS:
yum update

下载一键脚本

wget --no-check-certificate -qO InstallNET.sh 'https://moeclub.org/attachment/LinuxShell/InstallNET.sh' && chmod a+x InstallNET.sh

然后根据你需要重装到的系统和下文给出的说明执行对应命令即可。

重装过程需要10~30分钟,请耐心等待。

使用

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 为提示。

示例

一般

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

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

进阶

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

#使用自定义镜像自定义网络参数全自动安装
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/get-win7embx86-auto'

#使用自定义网络参数全自动dd方式安装存储在谷歌网盘中的镜像(调用文件ID的方式)
bash InstallNET.sh --ip-addr x.x.x.x --ip-gate x.x.x.x --ip-mask x.x.x.x -dd "$(echo "11fr_LcgY_qSEDbWvBel0S0fjYAX_lKL0" |xargs -n1 bash <(wget --no-check-certificate -qO- 'https://moeclub.org/get-gdlink'))"

#使用自定义网络参数全自动dd方式安装存储在谷歌网盘中的镜像
bash InstallNET.sh --ip-addr x.x.x.x --ip-gate x.x.x.x --ip-mask x.x.x.x -dd "$(echo "https://drive.google.com/open?id=11fr_LcgY_qSEDbWvBel0S0fjYAX_lKL0" |xargs -n1 bash <(wget --no-check-certificate -qO- 'https://moeclub.org/get-gdlink'))"

注意

在 VNC 手动安装 Ubuntu 时,可能会遇到:
Getting the time form a network time server...
界面进度条很长时间不会动,可以等待它超时或者更换别的版本
该问题是Ubuntu系统的问题

在全自动安装CentOS时:
如果看到“Starting graphical installation”或者类似表达,则表示正在安装
正常情况下只需要耐心等待安装完成即可
如果需要查看进度,使用 VNC Viewer(或者其他 VNC 连接工具)
连接提示中的IP地址:端口进行连接(端口一般为1或者5901

【补充】如何重装成 CentOS 7

wget --no-check-certificate -qO ~/Network-Reinstall-System-Modify.sh 'https://tech.cxthhhhh.com/tech-tools/Network-Reinstall-System-Modify/Network-Reinstall-System-Modify.sh' && chmod a+x ~/Network-Reinstall-System-Modify.sh && bash ~/Network-Reinstall-System-Modify.sh -CentOS_7

使用此方法须知

  1. root 密码为cxthhhhh.com
  2. 安装需耗时 15-45 分钟,并且系统首次启动后,请等待自动安装完成,系统将自动重启,然后才能使用(安装过程中的手动干预可能会导致错误)【一句话:耐心等就完事了(。】
  3. IPv4 和 IPv6 为 DHCP 获取 IP 的模式(如果用在必须手动指定 IP 信息的机器上,你也许需要使用 VNC 修改网络配置,或者使用 VPS 面板的“重置网络配置”,如果有的话)
  4. 系统 DNS 为1.1.1.18.8.8.8
  5. 系统使用官方 CentOS 镜像
  6. 登录信息标准化,易于管理,您需要在登录后修改它
  7. 默认分配磁盘大小为 4.5G,你需要扩展磁盘(请看下方)

磁盘扩容

Vicer 的脚本声明不支持自动安装 CentOS 7 的原因是 7 只能使用grub2引导,与我们常见的其他系统的grub不同

而此方法是直接使用dd镜像的方式安装,即实际上是直接拿一个装有 CentOS 7 的磁盘镜像来覆写硬盘(与dd安装 Win 同理),解决了这个问题

由于分区表也会被覆写,因此安装完成后你会发现硬盘分区大小小于原本的大小,只需使用fdisk修改分区大小扩容即可

其他一键安装脚本

被DD的机器原系统尽量请选择Ubuntu16。

(当然也支持 Debian9+/Ubuntu16+/Centos7+)

3.为什么不支持 debian8 或更低?

低版本网卡驱动原因。

4.为什么不支持DD新版Centos?

要折腾Centos7不是太好用,建议使用此脚本DD Centos7系列

5.默认root密码是什么?

GeekN.net

示例:

安装Debian9  (甲骨文机器需要后加 -firmware 额外的驱动支持)

bash <(wget --no-check-certificate -qO- 'https://file.geekn.net/OnedriveE3/linux/InstallNET.sh') -d 9 -v 64 -a -firmware

安装Debian10

bash <(wget --no-check-certificate -qO- 'https://file.geekn.net/OnedriveE3/linux/InstallNET.sh') -d 10 -v 64 -a -firmware

中国大陆镜像源:

华为云/Huaweicloud:

Debian10

bash <(wget --no-check-certificate -qO- 'https://file.geekn.net/OnedriveE3/linux/InstallNET.sh') -d 10 -v 64 -a --mirror 'https://mirrors.huaweicloud.com/debian/'

Debian9

bash <(wget --no-check-certificate -qO- 'https://file.geekn.net/OnedriveE3/linux/InstallNET.sh') -d 9 -v 64 -a --mirror 'https://mirrors.huaweicloud.com/debian/'

阿里云/Aliyun:

Debian10

bash <(wget --no-check-certificate -qO- 'https://file.geekn.net/OnedriveE3/linux/InstallNET.sh') -d 10 -v 64 -a --mirror 'https://mirrors.aliyun.com/debian/'

Debian9

bash <(wget --no-check-certificate -qO- 'https://file.geekn.net/OnedriveE3/linux/InstallNET.sh') -d 9 -v 64 -a --mirror 'https://mirrors.aliyun.com/debian/'

腾讯云/Tencentcloud:

Debian10

bash <(wget --no-check-certificate -qO- 'https://file.geekn.net/OnedriveE3/linux/InstallNET.sh') -d 10 -v 64 -a --mirror 'https://mirrors.cloud.tencent.com/debian/'

Debian9

bash <(wget --no-check-certificate -qO- 'https://file.geekn.net/OnedriveE3/linux/InstallNET.sh') -d 9 -v 64 -a --mirror 'https://mirrors.cloud.tencent.com/debian/'