Author SHA1 Message Date
Brent YangandGitHub e5fd6e74c8 Cloud-init: override ConfigDrive on OpenStack Nova 2025-07-12 19:43:34 +09:00
Brent YangandGitHub 41b56c2fad Merge pull request #136 from bohanyang/july-2025-update
July 2025 Update
2025-07-12 18:01:59 +09:00
Brent YangandGitHub b67c340954 DNS: Cloudflare by default; Cloud-init: disable ds-identify and force NoCloud 2025-07-12 17:59:15 +09:00
cha0sCatGitHubAnonymous <>Brent, Yang Bohan <youthdna@live.com>
4807410541 feat: add --static-ipv4 option, auto parse current network settings. (#131)
* feat: use static ip without manually typing it

* fix(cidr_to_netmask): rewrite to support sh

* refactor: remove cidr_to_netmask(), set cidr directly

https://lists.debian.org/debian-boot/2012/09/msg00239.html

* refactor: rename option --static-ip to --static-ipv4

* Add --static-ipv4 doc

---------

Co-authored-by: Anonymous <>
Co-authored-by: Brent, Yang Bohan <youthdna@live.com>
2025-02-22 21:54:04 +09:00
Eric-2369andBrent Yang 8e779c7999 fix: correct Debian version mapping for Trixie 2024-10-17 20:21:42 +09:00
Brent YangandGitHub 88cb473795 Update README.md 2024-05-18 16:29:56 +09:00
Brent YangandGitHub e856aca7c3 Update README.md 2024-05-10 23:06:08 +09:00
Brent YangandGitHub 2de8a1a23d Update README.md 2024-05-10 23:03:38 +09:00
Brent YangandGitHub 1282ca8593 Fix disk path 2024-04-23 16:25:52 +09:00
Brent YangandGitHub 0c7bad1e42 Fix default disk 2024-04-23 15:03:36 +09:00
Brent YangandGitHub ab6c04b571 Support RHEL 2024-04-23 14:21:25 +09:00
Brent Yang 7844eb5a37 Fixes #120 - Add grub.cfg path for RedHat on UEFI 2024-04-23 14:14:47 +09:00
Brent Yang e384a10dc9 Force remove existing LVM data 2024-04-23 13:58:52 +09:00
Brent Yang 4ea2f8b3a2 Set default disk to the device mounted to root 2024-04-23 13:58:23 +09:00
2 changed files with 61 additions and 58 deletions
+41 -53
View File
@@ -1,60 +1,22 @@
# Debian Network Reinstall Script # Debian Network Reinstall Script
[General description in English ↓](#introduction) [中文说明 ↓](#中文说明)
## VPS 网络重装 Debian 12 脚本
**暂不支持 Oracle Linux 作为原系统。创建新机器时请选择 Ubuntu 系统模板。**
下载脚本:
```
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 秒后可以尝试 SSH 登录 `installer` 用户,密码与之前设置的相同。如果成功连接,可以按 Ctrl-A 然后再按 4 监控安装日志。安装完成后会自动重启进入新系统。
### [Oracle 自动获取 IPv6](https://github.com/bohanyang/debi/wiki/%E7%94%B2%E9%AA%A8%E6%96%87%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%87%AA%E5%8A%A8%E8%8E%B7%E5%8F%96-IPv6)
### [Oracle 纯 IPv6 网络(无公网 IPv4)下安装方法](https://github.com/bohanyang/debi/wiki/%E7%94%B2%E9%AA%A8%E6%96%87%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%BA%AF-IPv6-%E7%BD%91%E7%BB%9C%EF%BC%88%E6%97%A0%E5%85%AC%E7%BD%91-IPv4%EF%BC%89%E4%B8%8B%E5%AE%89%E8%A3%85%E6%96%B9%E6%B3%95)
## Introduction ## Introduction
This script is written to reinstall a VPS/virtual machine to minimal Debian 10/11/12. This script is written to reinstall VPS/VMs to minimal Debian.
## Should Work On ## Platforms
### Virtualization Platform - ✔ KVM or physical machines ❌ Containers
- ✔ Debian or Ubuntu or Red Hat Linux as original OS with GRUB 2 bootloader
* SolusVM/OpenStack/DigitalOcean/Vultr/Linode/Proxmox/QEMU KVM (BIOS boot) - ✔ MBR or GPT partition table
* Oracle Cloud Infrastructure (UEFI boot) - ✔ Multiple disks or LVM
* Google Cloud Compute Engine (**Must manually configure the VPC internal IP and the gateway.** UEFI boot with Secure Boot support) - ✔ IPv4 or IPv6
* AWS EC2 & Lightsail (BIOS boot) - ✔ Legacy BIOS or UEFI boot
* Hyper-V & Azure (Generation 1 BIOS boot & Generation 2 UEFI boot) - ✔ Most VPS or cloud providers
- ⚠️ Google Compute Engine - **MUST** manually specify IP/CIDR and gateway of VPC
### Original OS - ⚠️ AWS EC2 or Lightsail - Does **NOT** work with UEFI boot
* Debian 8 or later
* Ubuntu 14.04 or later
* CentOS 7 or later
## How It Works ## How It Works
@@ -69,9 +31,6 @@ This script is written to reinstall a VPS/virtual machine to minimal Debian 10/1
Download the script with curl: Download the script with curl:
curl -fLO https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh curl -fLO https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh
# for IPv6-only machines
curl -fLO --resolve 'raw.githubusercontent.com:443:2a04:4e42::133' https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh
or wget: or wget:
@@ -112,6 +71,7 @@ Otherwise, you can run this command to revert all changes made by the script:
* `--interface <string>` Manually select a network interface, e.g. eth1 * `--interface <string>` Manually select a network interface, e.g. eth1
* `--ethx` Disable *Consistent Network Device Naming* to get interface names like *ethX* back * `--ethx` Disable *Consistent Network Device Naming* to get interface names like *ethX* back
* `--ip <string>` Disable the auto network config (DHCP) and configure a static IP address, e.g. `10.0.0.2`, `1.2.3.4/24`, `2001:2345:6789:abcd::ef/48` * `--ip <string>` Disable the auto network config (DHCP) and configure a static IP address, e.g. `10.0.0.2`, `1.2.3.4/24`, `2001:2345:6789:abcd::ef/48`
* `--static-ipv4` Disable the auto network config (DHCP) and configure with the current IPv4 address and gateway detected automatically
* `--netmask <string>` e.g. `255.255.255.0`, `ffff:ffff:ffff:ffff::` * `--netmask <string>` e.g. `255.255.255.0`, `ffff:ffff:ffff:ffff::`
* `--gateway <string>` e.g. `10.0.0.1`, `none` if no gateway * `--gateway <string>` e.g. `10.0.0.1`, `none` if no gateway
* `--dns '8.8.8.8 8.8.4.4'` * `--dns '8.8.8.8 8.8.4.4'`
@@ -164,3 +124,31 @@ Otherwise, you can run this command to revert all changes made by the script:
* `--force-lowmem <integer>` Valid values: 0, 1, 2. Force [low memory level](https://salsa.debian.org/installer-team/lowmem). Useful if your machine has memory less than 500M where level 2 is set (see issue #45). `--force-lowmem 1` may solve it. * `--force-lowmem <integer>` Valid values: 0, 1, 2. Force [low memory level](https://salsa.debian.org/installer-team/lowmem). Useful if your machine has memory less than 500M where level 2 is set (see issue #45). `--force-lowmem 1` may solve it.
* `--dry-run` Print generated preseed and GRUB entry without downloading the installer and actually saving them * `--dry-run` Print generated preseed and GRUB entry without downloading the installer and actually saving them
* `--cidata ./cidata-example` Custom data for cloud-init. **VM provider's data source will be IGNORED.** See example. * `--cidata ./cidata-example` Custom data for cloud-init. **VM provider's data source will be IGNORED.** See example.
## 中文说明
下载脚本:
```
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 秒后可以尝试 SSH 登录 `installer` 用户,密码与之前设置的相同。如果成功连接,可以按 Ctrl-A 然后再按 4 监控安装日志。安装完成后会自动重启进入新系统。
+20 -5
View File
@@ -156,7 +156,7 @@ set_debian_version() {
set_suite bookworm set_suite bookworm
;; ;;
13|trixie|testing) 13|trixie|testing)
set_suite bookworm set_suite trixie
;; ;;
sid|unstable) sid|unstable)
set_suite sid set_suite sid
@@ -196,8 +196,9 @@ interface=auto
ip= ip=
netmask= netmask=
gateway= gateway=
dns='8.8.8.8 8.8.4.4' dns='1.1.1.1 1.0.0.1'
dns6='2001:4860:4860::8888 2001:4860:4860::8844' dns6='2606:4700:4700::1111 2606:4700:4700::1001'
dns10='1.1.1.1 2606:4700:4700::1111'
hostname= hostname=
network_console=false network_console=false
set_debian_version 12 set_debian_version 12
@@ -214,7 +215,7 @@ sudo_with_password=false
timezone=UTC timezone=UTC
ntp=time.google.com ntp=time.google.com
disk_partitioning=true disk_partitioning=true
disk= disk="/dev/$(lsblk -no PKNAME "$(df /boot | grep -Eo '/dev/[a-z0-9]+')")"
force_gpt=true force_gpt=true
efi= efi=
esp=106 esp=106
@@ -274,6 +275,14 @@ while [ $# -gt 0 ]; do
mirror_host=mirrors.tuna.tsinghua.edu.cn mirror_host=mirrors.tuna.tsinghua.edu.cn
ntp=time.amazonaws.cn ntp=time.amazonaws.cn
;; ;;
--static-ipv4)
ip=$(ip r get 1.1.1.1 | awk '/src/ {print $7}')
gateway=$(ip r get 1.1.1.1 | awk '/via/ {print $3}')
_cidr=$(ip -o -f inet addr show | grep -w "$ip" | awk '{print $4}' | cut -d'/' -f2)
ip="$ip/$_cidr"
hostname=$(hostname)
interface=$(ip r get 1.1.1.1 | awk '/dev/ {print $5}')
;;
--interface) --interface)
interface=$2 interface=$2
shift shift
@@ -588,6 +597,10 @@ EOF
echo 'd-i netcfg/confirm_static boolean true' | $save_preseed echo 'd-i netcfg/confirm_static boolean true' | $save_preseed
} }
[ -z "$ip" ] && {
echo "d-i netcfg/get_nameservers string $dns10" | $save_preseed
}
if [ -n "$hostname" ]; then if [ -n "$hostname" ]; then
echo "d-i netcfg/hostname string $hostname" | $save_preseed echo "d-i netcfg/hostname string $hostname" | $save_preseed
hostname=debian hostname=debian
@@ -791,6 +804,7 @@ d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish d-i partman/choose_partition select finish
d-i partman/confirm boolean true d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true d-i partman/confirm_nooverwrite boolean true
d-i partman-lvm/device_remove_lvm boolean true
EOF EOF
} }
@@ -864,7 +878,7 @@ EOF
[ "$bbr" = true ] && in_target '{ echo "net.core.default_qdisc=fq"; echo "net.ipv4.tcp_congestion_control=bbr"; } > /etc/sysctl.d/bbr.conf' [ "$bbr" = true ] && in_target '{ echo "net.core.default_qdisc=fq"; echo "net.ipv4.tcp_congestion_control=bbr"; } > /etc/sysctl.d/bbr.conf'
[ -n "$cidata" ] && in_target 'echo "{ datasource_list: [ NoCloud ], datasource: { NoCloud: { fs_label: ~ } } }" > /etc/cloud/cloud.cfg.d/99_debi.cfg' [ -n "$cidata" ] && in_target 'echo "{ datasource_list: [ NoCloud ], datasource: { ConfigDrive: { dsmode: disabled }, NoCloud: { fs_label: ~, dsmode: local } } }" > /etc/cloud/cloud.cfg.d/99_mandate_nocloud.cfg'
late_command='true' late_command='true'
[ -n "$in_target_script" ] && late_command="$late_command; in-target sh -c '$in_target_script'" [ -n "$in_target_script" ] && late_command="$late_command; in-target sh -c '$in_target_script'"
@@ -914,6 +928,7 @@ EOF
# shellcheck disable=SC2016 # shellcheck disable=SC2016
echo 'zz_debi=/etc/default/grub.d/zz-debi.cfg; if [ -f "$zz_debi" ]; then . "$zz_debi"; fi' >> /etc/default/grub echo 'zz_debi=/etc/default/grub.d/zz-debi.cfg; if [ -f "$zz_debi" ]; then . "$zz_debi"; fi' >> /etc/default/grub
grub_cfg=/boot/grub2/grub.cfg grub_cfg=/boot/grub2/grub.cfg
[ -d /sys/firmware/efi ] && grub_cfg=/boot/efi/EFI/*/grub.cfg
grub2-mkconfig -o "$grub_cfg" grub2-mkconfig -o "$grub_cfg"
elif command_exists grub-mkconfig; then elif command_exists grub-mkconfig; then
tmp=$(mktemp) tmp=$(mktemp)