在云服务商提供的操作系统镜像过于陈旧,抑或者提供镜像包含一些监控组件,想拥有一个纯净的操作系统。此时就可以通过脚本重装系统。
示例
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 <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 秒后可以尝试 SSH 登录 installer 用户,密码与之前设置的相同。如果成功连接,可以按 Ctrl-A 然后再按 4 监控安装日志。安装完成后会自动重启进入新系统。
兼容性
虚拟化平台
- SolusVM/OpenStack/DigitalOcean/Vultr/Linode/Proxmox/QEMU KVM (BIOS boot)
- Oracle Cloud Infrastructure (UEFI boot)
- Google Cloud Compute Engine (Must manually configure the VPC internal IP and the gateway. UEFI boot with Secure Boot support)
- AWS EC2 & Lightsail (BIOS boot)
- Hyper-V & Azure (Generation 1 BIOS boot & Generation 2 UEFI boot)
原操作系统
- Debian 8 or later
- Ubuntu 14.04 or later
- CentOS 7 or later
工作原理
- 创建一个预先设定的脚本来完成自动安装
- 下载'Debian-Installer'到/boot目录
- 在grub2引导配置中添加一个安装器的启动项
使用方法
1. 下载
使用curl下载脚本:
curl -fLO https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh
# 仅支持IPv6的机器
curl -fLO --resolve 'raw.githubusercontent.com:443:2a04:4e42::133' https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh或者使用wget:
wget -O debi.sh https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh2. 运行脚本
使用root用户或者sudo执行脚本:
chmod a+rx debi.sh
sudo ./debi.sh默认情况下,在安装期间会创建一个admin用户,并带有sudo权限。如果不想使用这个用户,只需要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 |
|---|---|---|---|---|
| Global | Default | https://deb.debian.org | time.google.com | |
| Global | --cloudflare | https://deb.debian.org | Cloudflare | time.cloudflare.com |
| Global | --aws | https://cdn-aws.deb.debian.org | time.aws.com | |
| China | --ustc | https://mirrors.ustc.edu.cn | DNSPod | time.amazonaws.cn |
| China | --tuna | https://mirrors.tuna.tsinghua.edu.cn | DNSPod | time.amazonaws.cn |
| China | --aliyun | https://mirrors.aliyun.com | AliDNS | time.amazonaws.cn |
--interface <string>手动选择一个网卡,例如“eth1”--ethx禁用一致性网络设备命名(Consistent Network Device Naming),使用ethX的命名方式--ip <string>禁用自动网络配置(DHCP)并且配置一个静态的IP地址,例如10.0.0.2,1.2.3.4/24,2001:2345:6789:abcd::ef/48--netmask <string>子网掩码,例如255.255.255.0,ffff:ffff:ffff:ffff::--gateway <string>默认网关,例如10.0.0.1, 无网关none--dns '8.8.8.8 8.8.4.4'DNS解析--dns6 '2001:4860:4860::8888 2001:4860:4860::8844'仅在指定IPv6时有效--hostname <string>FQDN主机名 (包含域名), 例如server1.example.com--network-console启用安装程序的网络控制台,在安装时可通过ssh installer@ip连接--version 12支持的版本:10,11,12,13--suite bullseye如果没有特殊需求,使用--version替代. 例如:stable,testing,sid--release-d-id-i (Debian Installer) for the released versions: 12 (bookworm), 11 (bullseye) and 10 (buster)--daily-d-iUse latest daily build of d-i (Debian Installer) for the unreleased version: 13 (trixie), sid (unstable)--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-securityMagic value:'mirror' = <mirror-protocol>://<mirror-host>/<mirror-directory>/../debian-security--no-account-setup, --no-user(手动安装) 在VNC或者远程控制台中手动初始化账户--username, --user debian创建具有sudo权限的新用户或者root用户--password <string>新用户的密码 如果此处没有设定,会有输入提示--authorized-keys-url <string>用于SSH身份验证的密钥对应的URL,例如:https://github.com/torvalds.keys--sudo-with-password在使用sudo执行命令的时候需要输入密码--timezone UTC例如中国时区(UTC+8):Asia/Shanghaihttps://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List--ntp time.google.com--no-disk-partitioning, --no-part(手动安装) 在VNC或者远程控制台中手动分区--disk <string>手动选择一个磁盘进行安装请记住在有多个磁盘可用的情况下指定!,例如:/dev/sda--no-force-gpt默认创建GPT分区表,而不是MBR,可通过这个选项禁用。--bios不要创建EFI system partition。如果正在使用GPT分区表,创建一个BIOS boot partition (bios_grub分区),默认当/sys/firmware/efi不存在时创建 See--efi创建一个EFI system partition,如果/sys/firmware/efi存在则默认创建--esp 106设置EFI system partition分区大小,例如106,538,1075分别代表100MiB,512MiB,1GiB--filesystem ext4--kernel <string>Choose an package for the kernel image--cloud-kernel使用linux-image-cloud-amd64或者...arm64作为内核--bpo-kernelChoose the kernel image from Debian Backports (newer version from the next Debian release)--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. See--full-upgradeapt dist-upgrade--no-upgrade--bbr启用TCP BBR拥塞算法--ssh-port <integer>SSH端口--hold安装完成后不要重启,也不要关机--power-off安装完成后关机,而不是重启--architecture <string>例如:amd64,i386,arm64,armhf等--firmwareLoad additional non-free firmwares--no-force-efi-extra-removableSee--grub-timeout 5在grub进入安装程序前等待的秒数--force-lowmem <integer>合法值:0,1,2。 Force low memory level. Useful if your machine has memory less than 500M where level 2 is set (see issue #45).--force-lowmem 1may solve it.--dry-run打印预设脚本和grub启动项,但是并不真正的下载安装程序和保存这些配置。--cidata ./cidata-exampleCustom data for cloud-init. VM provider's data source will be IGNORED. See example.