Debian 网络重装脚本
简介
此脚本用于将 VPS/VM 重装为最小化 Debian 系统。
支持平台
- ✔ KVM 或物理机 ❌ 容器
- ✔ 原系统为 Debian、Ubuntu 或 Red Hat Linux,且使用 GRUB 2 引导加载程序
- ✔ MBR 或 GPT 分区表
- ✔ 多磁盘或 LVM
- ✔ IPv4 或 IPv6
- ✔ 传统 BIOS 或 UEFI 启动
- ✔ 大多数 VPS 或云服务提供商
- ⚠️ Google 计算引擎 - 必须手动指定 VPC 的 IP/CIDR 和网关
- ⚠️ AWS EC2 或 Lightsail - 不支持 UEFI 启动
工作原理
- 生成预设文件以自动化安装过程
- 将"Debian 安装程序"下载到
/boot
目录 - 在 GRUB2 配置文件中添加安装程序的菜单条目
使用方法
1. 下载
使用 curl 下载脚本:
curl -fLO https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh
或使用 wget:
wget -O debi.sh https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh
2. 运行
以 root 身份或使用 sudo 运行脚本:
chmod a+rx debi.sh
sudo ./debi.sh
默认情况下,安装过程中会创建一个具有 sudo 权限的管理员用户 debian
。如果您更喜欢 root 用户,请使用 --user root
选项。
3. 重启
如果一切正常,重启机器:
sudo shutdown -r now
否则,您可以运行以下命令撤销脚本所做的所有更改:
sudo rm -rf debi.sh /etc/default/grub.d/zz-debi.cfg /boot/debian-* && { sudo update-grub || sudo grub2-mkconfig -o /boot/grub2/grub.cfg; }
可用选项
预设
地区 | 别名 | 镜像 | DNS | NTP |
---|---|---|---|---|
全球 | 默认 | https://deb.debian.org | time.google.com | |
全球 | --cloudflare | https://deb.debian.org | Cloudflare | time.cloudflare.com |
全球 | --aws | https://cdn-aws.deb.debian.org | time.aws.com | |
中国 | --ustc | https://mirrors.ustc.edu.cn | DNSPod | time.amazonaws.cn |
中国 | --tuna | https://mirrors.tuna.tsinghua.edu.cn | DNSPod | time.amazonaws.cn |
中国 | --aliyun | https://mirrors.aliyun.com | AliDNS | time.amazonaws.cn |
--interface <字符串>
手动选择网络接口,例如 eth1--ethx
禁用一致网络设备命名,恢复使用 ethX 这样的接口名称--ip <字符串>
禁用自动网络配置(DHCP)并配置静态 IP 地址,例如10.0.0.2
、1.2.3.4/24
、2001:2345:6789:abcd::ef/48
--netmask <字符串>
例如255.255.255.0
、ffff:ffff:ffff:ffff::
--gateway <字符串>
例如10.0.0.1
,如果没有网关则为none
--dns '8.8.8.8 8.8.4.4'
--dns6 '2001:4860:4860::8888 2001:4860:4860::8844'
(仅在指定 IPv6 时有效)--hostname <字符串>
完全限定域名(FQDN)主机名(包含域名),例如server1.example.com
--network-console
启用安装程序的网络控制台。使用ssh installer@ip
连接--version 12
支持:10
、11
、12
、13
--suite bullseye
如果没有特殊需求,请使用--version
。 例如stable
、testing
、sid
--release-d-i
已发布版本的 d-i (Debian 安装程序):12 (bookworm)、11 (bullseye) 和 10 (buster)--daily-d-i
使用未发布版本的最新每日构建 d-i (Debian 安装程序):13 (trixie)、sid (不稳定版)--mirror-protocol http
或https
或ftp
--https
等同于--mirror-protocol https
--reuse-proxy
重用http(s)_proxy
环境变量的值作为镜像代理--proxy, --mirror-proxy
为 APT 和下载设置 HTTP 代理--mirror-host deb.debian.org
--mirror-directory /debian
--security-repository http://security.debian.org/debian-security
魔法值:'mirror' = <mirror-protocol>://<mirror-host>/<mirror-directory>/../debian-security
--no-account-setup, --no-user
(手动安装) 在 VNC 或远程控制台中手动进行帐户设置--username, --user debian
具有sudo
权限的新用户或root
--password <字符串>
新用户的密码。如果您选择不在此处指定,将会提示您输入--authorized-keys-url <字符串>
用于 SSH 认证的授权密钥 URL。例如https://github.com/torvalds.keys
--sudo-with-password
用户执行sudo
命令时需要密码--timezone UTC
例如中国 (UTC+8) 使用Asia/Shanghai
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List--ntp time.google.com
--no-disk-partitioning, --no-part
(手动安装) 在 VNC 或远程控制台中手动进行磁盘分区--disk <字符串>
手动选择安装磁盘。当有多个磁盘可用时,请记得指定此选项! 例如/dev/sda
--no-force-gpt
默认情况下会创建 GPT 而非 MBR 分区表。此选项禁用该行为。--bios
不创建 EFI 系统分区。如果使用 GPT,则创建 BIOS 引导分区(bios_grub
分区)。当/sys/firmware/efi
不存在时为默认选项。参见--efi
创建 EFI 系统分区。当/sys/firmware/efi
存在时为默认选项--esp 106
EFI 系统分区 的大小。例如106
、538
和1075
分别对应 100 MiB、512 MiB、1 GiB--filesystem ext4
--kernel <字符串>
选择内核镜像包--cloud-kernel
选择linux-image-cloud-amd64
或...arm64
作为内核镜像--bpo-kernel
从 Debian Backports 选择内核镜像(来自下一个 Debian 发行版的较新版本)--no-install-recommends
--apt-non-free-firmware
,--apt-non-free
,--apt-contrib
,--apt-src
,--apt-backports
--no-apt-non-free-firmware
,--no-apt-non-free
,--no-apt-contrib
,--no-apt-src
,--no-apt-backports
--install 'ca-certificates libpam-systemd'
安装额外的 APT 软件包。用空格分隔并加引号。--safe-upgrade
(默认)apt upgrade --with-new-pkgs
。参见--full-upgrade
apt dist-upgrade
--no-upgrade
--bbr
启用 TCP BBR 拥塞控制--ssh-port <整数>
SSH 端口--hold
安装后不重启或关机--power-off
安装后关机而不是重启--architecture <字符串>
例如amd64
、i386
、arm64
、armhf
等--firmware
加载额外的非自由固件--no-force-efi-extra-removable
参见--grub-timeout 5
GRUB 菜单在进入安装程序前显示的秒数--force-lowmem <整数>
有效值:0、1、2。强制设置低内存级别。如果您的机器内存少于500M,设置为级别2可能会有用(参见问题#45)。--force-lowmem 1
可能会解决这个问题。--dry-run
打印生成的预设和GRUB条目,而不下载安装程序和实际保存它们--cidata ./cidata-example
用于cloud-init的自定义数据。**虚拟机提供商的数据源将被忽略。**请参见示例。
中文说明
下载脚本:
curl -fLO https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh && chmod a+rx debi.sh
运行脚本:
sudo ./debi.sh --cdn --network-console --ethx --bbr --user root --password <新系统用户密码>
--bbr
启用 BBR--ethx
使用传统形式的网卡名称,如eth0
而非ens3
--cloud-kernel
安装占用空间较小的cloud
内核,但可能导致 UEFI 启动的机器(如 Oracle、Azure 及 Hyper-V、Google Cloud 等)VNC 黑屏。BIOS 启动的普通 VPS 则不存在此问题。- 默认时区为 UTC,添加
--timezone Asia/Shanghai
可设置为中国时区。 - 默认使用 Debian 官方 CDN 镜像源(deb.debian.org),添加
--ustc
可使用中科大镜像源。
如无错误报告,可以重启:
sudo shutdown -r now
大约 30 秒后可尝试以 installer
用户身份 SSH 登录,密码与之前设置的相同。连接成功后,可按 Ctrl-A 然后再按 4 查看安装日志。安装完成后系统将自动重启进入新系统。