mirror of
https://github.com/bohanyang/debi.git
synced 2026-09-27 14:36:20 +00:00
Compare commits
47
Commits
cd95b6624a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cdd2d6f5b | ||
|
|
2c028de296 | ||
|
|
a49899d060 | ||
|
|
702411aab3 | ||
|
|
804b2e05a1 | ||
|
|
1f735da114 | ||
|
|
d227d91ff3 | ||
|
|
a4b00e56d8 | ||
|
|
117f878e18 | ||
|
|
5dde42a9c2 | ||
|
|
83f27e9331 | ||
|
|
666508b962 | ||
|
|
ce794e924f | ||
|
|
31e14d1935 | ||
|
|
fe28cea5fe | ||
|
|
e1db2c4d52 | ||
|
|
e5fd6e74c8 | ||
|
|
41b56c2fad | ||
|
|
b67c340954 | ||
|
|
4807410541 | ||
|
|
8e779c7999 | ||
|
|
88cb473795 | ||
|
|
e856aca7c3 | ||
|
|
2de8a1a23d | ||
|
|
1282ca8593 | ||
|
|
0c7bad1e42 | ||
|
|
ab6c04b571 | ||
|
|
7844eb5a37 | ||
|
|
e384a10dc9 | ||
|
|
4ea2f8b3a2 | ||
|
|
b853e09987 | ||
|
|
a4772230b2 | ||
|
|
887d3c4a23 | ||
|
|
47ce372bb6 | ||
|
|
b5b37cbf44 | ||
|
|
e4c84ac328 | ||
|
|
8b42031edf | ||
|
|
b9b5203202 | ||
|
|
212de4be3b | ||
|
|
88ee869a6e | ||
|
|
e5452a93e4 | ||
|
|
7c654c13d4 | ||
|
|
f66bb5bc2e | ||
|
|
fc20b1b263 | ||
|
|
058edd7904 | ||
|
|
5cc4efb4e4 | ||
|
|
005754ffe8 |
@@ -0,0 +1,100 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
|
||||||
|
Debi is a Debian Network Reinstall Script that allows reinstalling any VPS or physical machine to minimal Debian via network boot. It's a single POSIX-compliant shell script that automates the entire Debian installation process.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
### Running the Script
|
||||||
|
```bash
|
||||||
|
# Basic execution (requires root)
|
||||||
|
sudo ./debi.sh
|
||||||
|
|
||||||
|
# With options
|
||||||
|
sudo ./debi.sh --user debian --timezone UTC --cloudflare
|
||||||
|
|
||||||
|
# Dry run (generate config without installing)
|
||||||
|
sudo ./debi.sh --dry-run
|
||||||
|
|
||||||
|
# With cloud-init configuration
|
||||||
|
sudo ./debi.sh --cidata ./cidata-example/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Testing Changes
|
||||||
|
```bash
|
||||||
|
# Check shell script syntax
|
||||||
|
sh -n debi.sh
|
||||||
|
|
||||||
|
# Run shellcheck for linting (if available)
|
||||||
|
shellcheck debi.sh
|
||||||
|
|
||||||
|
# Test in a VM environment (recommended)
|
||||||
|
# No automated test suite exists - manual testing required
|
||||||
|
```
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
The script operates in distinct phases:
|
||||||
|
|
||||||
|
1. **Configuration Phase**: Parses command-line arguments and validates environment
|
||||||
|
2. **Download Phase**: Fetches Debian installer components to `/boot/debian-$VERSION/`
|
||||||
|
3. **Preseed Generation**: Creates automated installation configuration
|
||||||
|
4. **GRUB Modification**: Adds installer entry to bootloader menu
|
||||||
|
5. **Initramfs Injection**: Embeds preseed and network configuration into installer
|
||||||
|
6. **Execution**: Updates GRUB and prepares for reboot
|
||||||
|
|
||||||
|
Key architectural decisions:
|
||||||
|
- Single-file design for easy distribution
|
||||||
|
- POSIX compliance for maximum compatibility
|
||||||
|
- No external dependencies beyond standard Linux utilities
|
||||||
|
- Modular function design with clear separation of concerns
|
||||||
|
- Extensive error handling with rollback capabilities
|
||||||
|
|
||||||
|
## Key Functions and Their Purposes
|
||||||
|
|
||||||
|
- `download()`: Handles file downloads with proxy support and multiple backend options (wget/curl/busybox)
|
||||||
|
- `set_debian_version()` / `set_suite()`: Manages Debian version selection and mirror URLs
|
||||||
|
- `configure_sshd()`: Sets up SSH access during installation for remote monitoring
|
||||||
|
- `in_target()`: Executes commands within the target installation environment
|
||||||
|
- `prompt_password()`: Securely handles password input with validation
|
||||||
|
|
||||||
|
## Important Configuration Variables
|
||||||
|
|
||||||
|
The script uses 80+ configuration options. Key ones include:
|
||||||
|
- `$suite`: Debian version (bookworm, bullseye, etc.)
|
||||||
|
- `$mirror_protocol` / `$mirror_host`: APT repository configuration
|
||||||
|
- `$disk`: Target installation disk
|
||||||
|
- `$authorized_keys_url`: SSH key provisioning
|
||||||
|
- `$cidata`: Cloud-init configuration directory
|
||||||
|
|
||||||
|
## Development Guidelines
|
||||||
|
|
||||||
|
1. **Maintain POSIX compliance** - Script must work with dash/sh, not just bash
|
||||||
|
2. **Test on real systems** - No test suite exists; changes require VM or physical testing
|
||||||
|
3. **Preserve backward compatibility** - Many users rely on specific option behaviors
|
||||||
|
4. **Document all options** - Update README.md for any new configuration options
|
||||||
|
5. **Handle errors gracefully** - Always provide rollback paths for critical operations
|
||||||
|
|
||||||
|
## Common Development Tasks
|
||||||
|
|
||||||
|
### Adding New Configuration Options
|
||||||
|
1. Add option to the case statement in the argument parsing section
|
||||||
|
2. Define corresponding variable with sensible default
|
||||||
|
3. Implement logic in appropriate phase function
|
||||||
|
4. Update README.md documentation
|
||||||
|
|
||||||
|
### Debugging Installation Issues
|
||||||
|
1. Use `--dry-run` to generate and inspect preseed configuration
|
||||||
|
2. Enable network console with `--ssh` for remote debugging
|
||||||
|
3. Check `/boot/debian-$VERSION/` for downloaded components
|
||||||
|
4. Review GRUB configuration changes in `/boot/grub/grub.cfg`
|
||||||
|
|
||||||
|
### Testing Platform Compatibility
|
||||||
|
Focus areas for testing:
|
||||||
|
- Network configuration (static IP vs DHCP)
|
||||||
|
- Disk detection and partitioning
|
||||||
|
- GRUB installation and boot entries
|
||||||
|
- Architecture-specific installer components
|
||||||
+354
@@ -0,0 +1,354 @@
|
|||||||
|
<div lang="ja-JP">
|
||||||
|
|
||||||
|
# Debian Network Reinstall Script
|
||||||
|
|
||||||
|
## このスクリプトについて
|
||||||
|
|
||||||
|
これは、あらゆるVPSや物理マシンを、ネットワークブート経由で最小構成のDebianに再インストールするためのスクリプトです。GRUBにDebianインストーラーを組み込み、インストールプロセスを自動的に設定することで動作します。
|
||||||
|
|
||||||
|
**主な用途:**
|
||||||
|
- Oracle CloudのUbuntuイメージをDebianに変換
|
||||||
|
- クラウドプロバイダーの監視エージェントの削除
|
||||||
|
- クリーンで最小限のDebian環境の構築
|
||||||
|
- Preseedやcloud-initを使用したインストールの自動化
|
||||||
|
- 破損したシステムのレスキュー
|
||||||
|
|
||||||
|
## クイックスタート
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# スクリプトをダウンロード
|
||||||
|
curl -fLO [https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh](https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh)
|
||||||
|
chmod +x debi.sh
|
||||||
|
|
||||||
|
# 基本的なインストール(sudo権限を持つ 'debian' ユーザーを作成)
|
||||||
|
sudo ./debi.sh
|
||||||
|
|
||||||
|
# もしくは、rootユーザーとしてインストール
|
||||||
|
sudo ./debi.sh --user root
|
||||||
|
|
||||||
|
# 準備ができたら再起動
|
||||||
|
sudo reboot
|
||||||
|
````
|
||||||
|
|
||||||
|
**デフォルト設定:** Debian 13 (trixie)、DHCPによるネットワーク設定、sudo権限を持つ`debian`ユーザーが作成され、パスワードの入力を求められます。
|
||||||
|
|
||||||
|
## プラットフォームサポート
|
||||||
|
|
||||||
|
| プラットフォーム | ステータス | 備考 |
|
||||||
|
|---|---|---|
|
||||||
|
| ✅ **KVM/物理マシン** | フルサポート | 全ての機能が動作します |
|
||||||
|
| ✅ **ほとんどのVPS** | フルサポート | DigitalOcean, Vultr, Linodeなど |
|
||||||
|
| ⚠️ **Google Cloud** | 手動でのネットワーク設定が必要 | DHCPが機能しないため`--ip`, `--gateway`が必須 |
|
||||||
|
| ⚠️ **AWS EC2** | BIOSのみ | UEFIブートはまだサポートされていません |
|
||||||
|
| ❌ **コンテナ** | サポート対象外 | GRUBブートローダーが必要です |
|
||||||
|
|
||||||
|
**要件:**
|
||||||
|
|
||||||
|
- KVMまたは物理マシン(コンテナは不可)
|
||||||
|
- GRUB 2 ブートローダー
|
||||||
|
- rootアクセス権限
|
||||||
|
|
||||||
|
## 地域別プリセット
|
||||||
|
|
||||||
|
| プリセット | ミラー | DNS | NTP | 最適な環境 |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| *Default* | deb.debian.org | Google DNS | time.google.com | グローバル |
|
||||||
|
| `--cloudflare` | deb.debian.org | Cloudflare | time.cloudflare.com | グローバル (プライバシー重視) |
|
||||||
|
| `--aws` | cdn-aws.deb.debian.org | Google DNS | time.aws.com | AWSインスタンス |
|
||||||
|
| `--aliyun` | mirrors.aliyun.com | AliDNS | time.amazonaws.cn | 中国 |
|
||||||
|
| `--ustc` | mirrors.ustc.edu.cn | DNSPod | time.amazonaws.cn | 中国 |
|
||||||
|
| `--tuna` | mirrors.tuna.tsinghua.edu.cn | DNSPod | time.amazonaws.cn | 中国 |
|
||||||
|
|
||||||
|
## 全オプションリファレンス
|
||||||
|
|
||||||
|
### システムとユーザー設定
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--version 13` | `13` | Debianのバージョン: `10`, `11`, `12`, `13`, `14` |
|
||||||
|
| `--suite trixie` | `trixie` | Debianのスイート: `stable`, `testing`, `sid` など |
|
||||||
|
| `--user debian` | `debian` | ユーザー名 (`root`を指定するとrootユーザーのみ) |
|
||||||
|
| `--password PASSWORD` | *プロンプト* | ユーザーのパスワード(指定しない場合はプロンプト表示) |
|
||||||
|
| `--authorized-keys-url URL` | *パスワード認証* | URLからSSH公開鍵を設定 (例: `https://github.com/user.keys`) |
|
||||||
|
| `--no-account-setup` | *ユーザー作成* | ユーザー作成をスキップ(コンソールでの手動設定が必要) |
|
||||||
|
| `--sudo-with-password` | *パスワード不要* | sudoコマンド実行時にパスワードを要求する |
|
||||||
|
| `--timezone UTC` | `UTC` | システムのタイムゾーン (例: `Asia/Tokyo`) |
|
||||||
|
| `--hostname NAME` | *現在の値* | システムのホスト名 |
|
||||||
|
|
||||||
|
### ネットワーク設定
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--interface auto` | `auto` | ネットワークインターフェース (例: `eth0`, `eth1`) |
|
||||||
|
| `--ip ADDRESS` | *DHCP* | 静的IP: `10.0.0.100`, `1.2.3.4/24`, `2001:db8::1/64` |
|
||||||
|
| `--static-ipv4` | *DHCP* | 現在のIPv4設定を自動的に使用 |
|
||||||
|
| `--netmask MASK` | *auto* | ネットマスク: `255.255.255.0`, `ffff:ffff:ffff:ffff::` |
|
||||||
|
| `--gateway ADDRESS` | *auto* | ゲートウェイIP (`none`でゲートウェイなし) |
|
||||||
|
| `--dns '8.8.8.8 8.8.4.4'` | `1.1.1.1 1.0.0.1` | IPv4用のDNSサーバー |
|
||||||
|
| `--dns6 '2001:4860:4860::8888'` | `2606:4700:4700::1111` | IPv6用のDNSサーバー |
|
||||||
|
| `--ethx` | *予測可能な名前* | `enp0s3`形式の代わりに`eth0`/`eth1`を使用 |
|
||||||
|
| `--ntp time.google.com` | `time.google.com` | NTPサーバー |
|
||||||
|
|
||||||
|
### ネットワークコンソール(リモートインストール)
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--network-console` | *無効* | インストール中にSSHアクセスを有効化 |
|
||||||
|
|
||||||
|
**ネットワークコンソールの使い方:**
|
||||||
|
|
||||||
|
1. `--network-console` を付けて有効化し、再起動します
|
||||||
|
2. Debianインストーラーがコンポーネントをロードするまで2〜3分待ちます
|
||||||
|
3. サーバーにSSH接続します: `ssh installer@YOUR_IP`
|
||||||
|
4. 複数のターミナルを利用できます:
|
||||||
|
- **Alt+F1**: メインのインストーラー画面
|
||||||
|
- **Alt+F2**: シェルアクセス
|
||||||
|
- **Alt+F3**: 追加のシェル
|
||||||
|
- **Alt+F4**: システムログ(自動インストールの進捗を監視)
|
||||||
|
- Alt+Left/Alt+Rightで画面を切り替え
|
||||||
|
|
||||||
|
**⚠️ 注意事項**
|
||||||
|
|
||||||
|
`--authorized-keys-url` を使用した場合、SSHのパスワード認証は無効になります(SSHキーが必須)。**ただし、ユーザーパスワードの設定が必要です(VNCコンソールやsudoでのアクセスのため)。**
|
||||||
|
|
||||||
|
### ストレージとパーティショニング
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--disk /dev/sda` | *自動検出* | 対象ディスク(複数ディスクがある場合は**必須**) |
|
||||||
|
| `--no-disk-partitioning` | *自動パーティション* | コンソールで手動パーティショニングを行う |
|
||||||
|
| `--filesystem ext4` | `ext4` | ルートファイルシステムのタイプ |
|
||||||
|
| `--force-gpt` | *有効* | GPTパーティションテーブルを作成 |
|
||||||
|
| `--no-force-gpt` | *GPTを使用* | 代わりにMBRパーティションテーブルを使用 |
|
||||||
|
| `--bios` | *自動検出* | BIOSブートを強制(BIOSブートパーティションを作成) |
|
||||||
|
| `--efi` | *自動検出* | EFIブートを強制(EFIシステムパーティションを作成) |
|
||||||
|
| `--esp 106` | `106` | EFIシステムパーティションのサイズ (106=100MB, 538=512MB, 1075=1GB) |
|
||||||
|
|
||||||
|
### ミラーとリポジトリの設定
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--mirror-protocol https` | `https` | ミラーのプロトコル: `http`, `https`, `ftp` |
|
||||||
|
| `--https` | *有効* | `--mirror-protocol https` のエイリアス |
|
||||||
|
| `--mirror-host deb.debian.org` | `deb.debian.org` | ミラーのホスト名 |
|
||||||
|
| `--mirror-directory /debian` | `/debian` | ミラーのディレクトリパス |
|
||||||
|
| `--mirror-proxy URL` | *なし* | ダウンロードとAPT用のHTTPプロキシ |
|
||||||
|
| `--reuse-proxy` | *なし* | 既存の`http_proxy`環境変数を使用 |
|
||||||
|
| `--security-repository URL` | *auto* | セキュリティアップデート用リポジトリ (`mirror`でメインミラーを使用) |
|
||||||
|
|
||||||
|
### APTリポジトリコンポーネント
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--apt-non-free-firmware` | *有効* | non-free-firmwareを含める (Debian 12以降) |
|
||||||
|
| `--apt-non-free` | *無効* | non-freeリポジトリを有効化 |
|
||||||
|
| `--apt-contrib` | *無効* | contribリポジトリを有効化 |
|
||||||
|
| `--apt-src` | *有効* | ソースリポジトリを有効化 |
|
||||||
|
| `--apt-backports` | *有効* | backportsリポジトリを有効化 |
|
||||||
|
| `--no-apt-non-free-firmware` | *デフォルトを使用* | non-free-firmwareを無効化 |
|
||||||
|
| `--no-apt-non-free` | *デフォルトを使用* | non-freeを無効化 |
|
||||||
|
| `--no-apt-contrib` | *デフォルトを使用* | contribを無効化 |
|
||||||
|
| `--no-apt-src` | *デフォルトを使用* | ソースリポジトリを無効化 |
|
||||||
|
| `--no-apt-backports` | *デフォルトを使用* | backportsを無効化 |
|
||||||
|
|
||||||
|
### パッケージインストール
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--install 'pkg1 pkg2'` | *最小構成* | 追加パッケージ(スペース区切り、引用符で囲む) |
|
||||||
|
| `--install-recommends` | *有効* | 推奨パッケージをインストール |
|
||||||
|
| `--no-install-recommends` | *推奨をインストール* | 推奨パッケージをスキップ |
|
||||||
|
| `--upgrade safe-upgrade` | `safe-upgrade` | パッケージのアップグレードモード |
|
||||||
|
| `--safe-upgrade` | *デフォルト* | インストール中に安全なパッケージアップグレードを実行 |
|
||||||
|
| `--full-upgrade` | *safe upgrade* | フルシステムアップグレード (`dist-upgrade`) |
|
||||||
|
| `--no-upgrade` | *safe upgrade* | パッケージのアップグレードを完全にスキップ |
|
||||||
|
|
||||||
|
### カーネルオプション
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--kernel PACKAGE` | `linux-image-ARCH` | カーネルパッケージ名 |
|
||||||
|
| `--cloud-kernel` | *標準* | クラウド最適化カーネルを使用 |
|
||||||
|
| `--bpo-kernel` | *stable* | backportsから新しいカーネルを使用 |
|
||||||
|
| `--firmware` | *自動検出* | ハードウェア用のnon-freeファームウェアを含める |
|
||||||
|
|
||||||
|
### 詳細オプション
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--ssh-port 2222` | `22` | カスタムSSHポート |
|
||||||
|
| `--bbr` | *無効* | TCP BBR輻輳制御アルゴリズムを有効化 |
|
||||||
|
| `--architecture amd64` | *自動検出* | 対象アーキテクチャ: `amd64`, `arm64`, `i386` など |
|
||||||
|
| `--force-lowmem 1` | *auto* | 低メモリモードを強制: `0`, `1`, `2` (512MB未満のRAM用) |
|
||||||
|
| `--no-force-efi-extra-removable` | *有効* | EFIの追加リムーバブルメディアパスを無効化 |
|
||||||
|
| `--grub-timeout 5` | `5` | GRUBメニューのタイムアウト秒数 |
|
||||||
|
|
||||||
|
### Debianインストーラーオプション
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--release-d-i` | *auto* | リリース版のdebian-installerを使用 |
|
||||||
|
| `--daily-d-i` | *auto* | デイリービルド版のdebian-installerを使用 |
|
||||||
|
|
||||||
|
### Cloud-Init連携
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--cidata /path/to/dir` | *なし* | カスタムcloud-initデータディレクトリ |
|
||||||
|
|
||||||
|
**Cloud-Initの使い方:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# cloud-init設定を作成
|
||||||
|
mkdir my-cloud-config
|
||||||
|
echo "instance-id: my-server" > my-cloud-config/meta-data
|
||||||
|
cat > my-cloud-config/user-data << 'EOF'
|
||||||
|
#cloud-config
|
||||||
|
hostname: my-server
|
||||||
|
packages:
|
||||||
|
- htop
|
||||||
|
- git
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# インストール時に使用
|
||||||
|
sudo ./debi.sh --cidata my-cloud-config
|
||||||
|
```
|
||||||
|
|
||||||
|
### 開発とテスト
|
||||||
|
|
||||||
|
| オプション | デフォルト値 | 説明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--dry-run` | *実行* | インストールは行わず、設定ファイルのみ生成 |
|
||||||
|
| `--hold` | *再起動* | インストール後に再起動しない |
|
||||||
|
| `--power-off` | *再起動* | 再起動の代わりに電源をオフにする |
|
||||||
|
|
||||||
|
## 使用例
|
||||||
|
|
||||||
|
### Oracle Cloud (Ubuntu → Debian)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --cloudflare --user debian
|
||||||
|
```
|
||||||
|
|
||||||
|
### Google Cloud Platform
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# GCPでは手動でのネットワーク設定が必要(お使いのVPC設定に置き換えてください)
|
||||||
|
sudo ./debi.sh --ip 10.128.0.100/24 --gateway 10.128.0.1
|
||||||
|
```
|
||||||
|
|
||||||
|
### 最小構成でのインストール
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --no-install-recommends --install 'curl git vim' --no-upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
### 中国向けデプロイ
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --ustc --timezone Asia/Shanghai --dns '119.29.29.29'
|
||||||
|
```
|
||||||
|
|
||||||
|
### ネットワークコンソールでのインストール
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# インストール中にリモートアクセスを有効化(ネットワーク接続はSSHキー、VNC/sudoはパスワードが引き続き必要)
|
||||||
|
sudo ./debi.sh --network-console --authorized-keys-url [https://github.com/yourusername.keys](https://github.com/yourusername.keys)
|
||||||
|
# 再起動後、SSH接続: ssh installer@YOUR_IP
|
||||||
|
```
|
||||||
|
|
||||||
|
### 静的IPとCloud-Initを使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --ip 192.168.1.100/24 --gateway 192.168.1.1 --cidata ./cloud-config/
|
||||||
|
```
|
||||||
|
|
||||||
|
### 高度なカスタム設定
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh \
|
||||||
|
--version 13 \
|
||||||
|
--user admin \
|
||||||
|
--timezone Europe/London \
|
||||||
|
--disk /dev/nvme0n1 \
|
||||||
|
--filesystem btrfs \
|
||||||
|
--cloud-kernel \
|
||||||
|
--bbr \
|
||||||
|
--ssh-port 2222 \
|
||||||
|
--install 'htop iotop ncdu'
|
||||||
|
```
|
||||||
|
|
||||||
|
## トラブルシューティング
|
||||||
|
|
||||||
|
### 全ての変更を元に戻す
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 全ての変更を削除し、元のGRUB設定を復元
|
||||||
|
sudo rm -rf /etc/default/grub.d/zz-debi.cfg /boot/debian-*
|
||||||
|
sudo update-grub || sudo grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||||
|
```
|
||||||
|
|
||||||
|
### よくある問題
|
||||||
|
|
||||||
|
**複数のディスクが検出された場合:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 利用可能なディスクをリスト表示
|
||||||
|
lsblk
|
||||||
|
# 対象ディスクを指定
|
||||||
|
sudo ./debi.sh --disk /dev/sda
|
||||||
|
```
|
||||||
|
|
||||||
|
**低メモリのVPS (\<512MB) の場合:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --force-lowmem 1
|
||||||
|
```
|
||||||
|
|
||||||
|
**ネットワーク設定に失敗する場合:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 現在のネットワーク設定を使用
|
||||||
|
sudo ./debi.sh --static-ipv4
|
||||||
|
|
||||||
|
# または手動で設定
|
||||||
|
sudo ./debi.sh --ip YOUR_IP/CIDR --gateway YOUR_GATEWAY
|
||||||
|
```
|
||||||
|
|
||||||
|
**ネットワークカードにファームウェアが必要な場合:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --firmware
|
||||||
|
```
|
||||||
|
|
||||||
|
**インストールのデバッグ:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# preseedファイルのみを生成
|
||||||
|
sudo ./debi.sh --dry-run
|
||||||
|
|
||||||
|
# リモートアクセス用にネットワークコンソールを有効化(リモートはSSHキー、VNC/sudoはパスワードが必要)
|
||||||
|
sudo ./debi.sh --network-console --authorized-keys-url YOUR_KEYS_URL
|
||||||
|
```
|
||||||
|
|
||||||
|
## 動作の仕組み
|
||||||
|
|
||||||
|
1. **Debianインストーラーをダウンロード**し、`/boot/debian-$VERSION/`に配置します
|
||||||
|
2. 指定された設定で**preseedファイルを生成**します
|
||||||
|
3. **GRUBの設定を変更**し、インストーラーのメニューエントリを追加します
|
||||||
|
4. インストーラーのinitramfsに**設定を注入**します
|
||||||
|
5. **GRUBを更新**し、新しいブートオプションを反映させます
|
||||||
|
|
||||||
|
**システムに加えられる変更:**
|
||||||
|
|
||||||
|
- `/boot/debian-*/` にファイルが追加されます
|
||||||
|
- `/etc/default/grub.d/zz-debi.cfg` にGRUB設定が追加されます
|
||||||
|
- GRUBメニューが更新されます
|
||||||
|
|
||||||
|
**これらの変更は安全であり、再起動前であれば上記の「元に戻す」コマンドで取り消すことが可能です。**
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
|
*Created by [@bohanyang](https://github.com/bohanyang) • [Issues](https://github.com/bohanyang/debi/issues) • [GitHub](https://github.com/bohanyang/debi)*
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -1,175 +1,323 @@
|
|||||||
# Debian Network Reinstall Script
|
# Debian Network Reinstall Script
|
||||||
|
|
||||||
[General description in English ↓](#introduction)
|
- <span lang="zh-CN">[中文版在这里](./README.zh-CN.md)</span>
|
||||||
|
- <span lang="ja-JP">[日本語はこちら](./README.ja-JP.md)</span>
|
||||||
|
|
||||||
## VPS 网络重装 Debian 12 脚本
|
## What is this?
|
||||||
|
|
||||||
**暂不支持 Oracle Linux 作为原系统。创建新机器时请选择 Ubuntu 系统模板。**
|
A script that reinstalls any VPS or physical machine to minimal Debian via network boot. Works by injecting the Debian installer into GRUB and automatically configuring the installation process.
|
||||||
|
|
||||||
下载脚本:
|
**Perfect for:**
|
||||||
|
- Converting Oracle Cloud's Ubuntu images to Debian
|
||||||
|
- Removing cloud provider surveillance agents
|
||||||
|
- Creating minimal, clean Debian environments
|
||||||
|
- Automating installations with preseed/cloud-init
|
||||||
|
- Rescuing broken systems
|
||||||
|
|
||||||
```
|
## Quick Start
|
||||||
curl -fLO https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh && chmod a+rx debi.sh
|
|
||||||
|
```bash
|
||||||
|
# Download the script
|
||||||
|
curl -fLO https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh
|
||||||
|
chmod +x debi.sh
|
||||||
|
|
||||||
|
# Basic installation (creates user 'debian' with sudo access)
|
||||||
|
sudo ./debi.sh
|
||||||
|
|
||||||
|
# Or install as root user instead
|
||||||
|
sudo ./debi.sh --user root
|
||||||
|
|
||||||
|
# Reboot when ready
|
||||||
|
sudo reboot
|
||||||
```
|
```
|
||||||
|
|
||||||
运行脚本:
|
**Default settings:** Debian 13 (trixie), DHCP networking, user `debian` with sudo access, you'll be prompted for password.
|
||||||
|
|
||||||
```
|
## Platform Support
|
||||||
sudo ./debi.sh --cdn --network-console --ethx --bbr --user root --password <新系统用户密码>
|
|
||||||
|
| Platform | Status | Notes |
|
||||||
|
|----------|---------|-------|
|
||||||
|
| ✅ **KVM/Physical** | Full support | All features work |
|
||||||
|
| ✅ **Most VPS** | Full support | DigitalOcean, Vultr, Linode, etc. |
|
||||||
|
| ⚠️ **Google Cloud** | Requires manual network | Must use `--ip`, `--gateway` (DHCP broken) |
|
||||||
|
| ⚠️ **AWS EC2** | BIOS only | UEFI boot not yet supported |
|
||||||
|
| ❌ **Containers** | Not supported | Requires GRUB bootloader |
|
||||||
|
|
||||||
|
**Requirements:**
|
||||||
|
- KVM or physical machine (not containers)
|
||||||
|
- GRUB 2 bootloader
|
||||||
|
- Root access
|
||||||
|
|
||||||
|
## Regional Presets
|
||||||
|
|
||||||
|
| Preset | Mirror | DNS | NTP | Best for |
|
||||||
|
|--------|---------|-----|-----|----------|
|
||||||
|
| *Default* | deb.debian.org | Google DNS | time.google.com | Global |
|
||||||
|
| `--cloudflare` | deb.debian.org | Cloudflare | time.cloudflare.com | Global (privacy) |
|
||||||
|
| `--aws` | cdn-aws.deb.debian.org | Google DNS | time.aws.com | AWS instances |
|
||||||
|
| `--aliyun` | mirrors.aliyun.com | AliDNS | time.amazonaws.cn | China |
|
||||||
|
| `--ustc` | mirrors.ustc.edu.cn | DNSPod | time.amazonaws.cn | China |
|
||||||
|
| `--tuna` | mirrors.tuna.tsinghua.edu.cn | DNSPod | time.amazonaws.cn | China |
|
||||||
|
|
||||||
|
## Complete Options Reference
|
||||||
|
|
||||||
|
### System & User Configuration
|
||||||
|
| Option | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| `--version 13` | `13` | Debian version: `10`, `11`, `12`, `13`, `14` |
|
||||||
|
| `--suite trixie` | `trixie` | Debian suite: `stable`, `testing`, `sid`, etc. |
|
||||||
|
| `--user debian` | `debian` | Username (use `root` for root-only) |
|
||||||
|
| `--password PASSWORD` | *prompt* | User password (prompted if not specified) |
|
||||||
|
| `--authorized-keys-url URL` | *password auth* | SSH keys from URL (e.g., `https://github.com/user.keys`) |
|
||||||
|
| `--no-account-setup` | *create user* | Skip user creation (manual setup via console) |
|
||||||
|
| `--sudo-with-password` | *no password* | Require password for sudo commands |
|
||||||
|
| `--timezone UTC` | `UTC` | System timezone (e.g., `Asia/Shanghai`) |
|
||||||
|
| `--hostname NAME` | *current* | System hostname |
|
||||||
|
|
||||||
|
### Network Configuration
|
||||||
|
| Option | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| `--interface auto` | `auto` | Network interface (e.g., `eth0`, `eth1`) |
|
||||||
|
| `--ip ADDRESS` | *DHCP* | Static IP: `10.0.0.100`, `1.2.3.4/24`, `2001:db8::1/64` |
|
||||||
|
| `--static-ipv4` | *DHCP* | Use current IPv4 settings automatically |
|
||||||
|
| `--netmask MASK` | *auto* | Network mask: `255.255.255.0`, `ffff:ffff:ffff:ffff::` |
|
||||||
|
| `--gateway ADDRESS` | *auto* | Gateway IP (use `none` for no gateway) |
|
||||||
|
| `--dns '8.8.8.8 8.8.4.4'` | `1.1.1.1 1.0.0.1` | DNS servers for IPv4 |
|
||||||
|
| `--dns6 '2001:4860:4860::8888'` | `2606:4700:4700::1111` | DNS servers for IPv6 |
|
||||||
|
| `--ethx` | *consistent naming* | Use `eth0`/`eth1` instead of `enp0s3` style |
|
||||||
|
| `--ntp time.google.com` | `time.google.com` | NTP server |
|
||||||
|
|
||||||
|
### Network Console (Remote Installation)
|
||||||
|
| Option | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| `--network-console` | *disabled* | Enable SSH access during installation |
|
||||||
|
|
||||||
|
**Network Console Usage:**
|
||||||
|
1. Enable with `--network-console` and reboot
|
||||||
|
2. Wait 2-3 minutes for Debian installer to load components
|
||||||
|
3. SSH to your server: `ssh installer@YOUR_IP`
|
||||||
|
4. Use multiple terminals:
|
||||||
|
- **Alt+F1**: Main installer interface
|
||||||
|
- **Alt+F2**: Shell access
|
||||||
|
- **Alt+F3**: Additional shell
|
||||||
|
- **Alt+F4**: System logs (monitor automated installation progress)
|
||||||
|
- Navigate with Alt+Left/Alt+Right
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> If `--authorized-keys-url` is used, SSH password authentication is disabled (SSH keys required), **but you still need to set a user password for VNC console and sudo access.**
|
||||||
|
|
||||||
|
### Storage & Partitioning
|
||||||
|
| Option | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| `--disk /dev/sda` | *auto-detect* | Target disk (**required** if multiple disks) |
|
||||||
|
| `--no-disk-partitioning` | *auto partition* | Manual partitioning via console |
|
||||||
|
| `--filesystem ext4` | `ext4` | Root filesystem type |
|
||||||
|
| `--force-gpt` | *enabled* | Create GPT partition table |
|
||||||
|
| `--no-force-gpt` | *use GPT* | Use MBR partition table instead |
|
||||||
|
| `--bios` | *auto-detect* | Force BIOS boot (creates BIOS boot partition) |
|
||||||
|
| `--efi` | *auto-detect* | Force EFI boot (creates EFI system partition) |
|
||||||
|
| `--esp 106` | `106` | EFI system partition size (106=100MB, 538=512MB, 1075=1GB) |
|
||||||
|
|
||||||
|
### Mirror & Repository Configuration
|
||||||
|
| Option | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| `--mirror-protocol https` | `https` | Mirror protocol: `http`, `https`, `ftp` |
|
||||||
|
| `--https` | *enabled* | Alias for `--mirror-protocol https` |
|
||||||
|
| `--mirror-host deb.debian.org` | `deb.debian.org` | Mirror hostname |
|
||||||
|
| `--mirror-directory /debian` | `/debian` | Mirror directory path |
|
||||||
|
| `--mirror-proxy URL` | *none* | HTTP proxy for downloads and APT |
|
||||||
|
| `--reuse-proxy` | *none* | Use existing `http_proxy` environment variable |
|
||||||
|
| `--security-repository URL` | *auto* | Security updates repo (use `mirror` for main mirror) |
|
||||||
|
|
||||||
|
### APT Repository Components
|
||||||
|
| Option | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| `--apt-non-free-firmware` | *enabled* | Include non-free firmware (Debian 12+) |
|
||||||
|
| `--apt-non-free` | *disabled* | Enable non-free repository |
|
||||||
|
| `--apt-contrib` | *disabled* | Enable contrib repository |
|
||||||
|
| `--apt-src` | *enabled* | Enable source repositories |
|
||||||
|
| `--apt-backports` | *enabled* | Enable backports repository |
|
||||||
|
| `--no-apt-non-free-firmware` | *use default* | Disable non-free firmware |
|
||||||
|
| `--no-apt-non-free` | *use default* | Disable non-free |
|
||||||
|
| `--no-apt-contrib` | *use default* | Disable contrib |
|
||||||
|
| `--no-apt-src` | *use default* | Disable source repositories |
|
||||||
|
| `--no-apt-backports` | *use default* | Disable backports |
|
||||||
|
|
||||||
|
### Package Installation
|
||||||
|
| Option | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| `--install 'pkg1 pkg2'` | *minimal* | Additional packages (space-separated, quoted) |
|
||||||
|
| `--install-recommends` | *enabled* | Install recommended packages |
|
||||||
|
| `--no-install-recommends` | *install recommends* | Skip recommended packages |
|
||||||
|
| `--upgrade safe-upgrade` | `safe-upgrade` | Package upgrade mode |
|
||||||
|
| `--safe-upgrade` | *default* | Safe package upgrades during install |
|
||||||
|
| `--full-upgrade` | *safe upgrade* | Full system upgrade (`dist-upgrade`) |
|
||||||
|
| `--no-upgrade` | *safe upgrade* | Skip package upgrades entirely |
|
||||||
|
|
||||||
|
### Kernel Options
|
||||||
|
| Option | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| `--kernel PACKAGE` | `linux-image-ARCH` | Kernel package name |
|
||||||
|
| `--cloud-kernel` | *standard* | Use cloud-optimized kernel |
|
||||||
|
| `--bpo-kernel` | *stable* | Use newer kernel from backports |
|
||||||
|
| `--firmware` | *auto-detect* | Include non-free firmware for hardware |
|
||||||
|
|
||||||
|
### Advanced Options
|
||||||
|
| Option | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| `--ssh-port 2222` | `22` | Custom SSH port |
|
||||||
|
| `--bbr` | *disabled* | Enable TCP BBR congestion control |
|
||||||
|
| `--architecture amd64` | *auto-detect* | Target architecture: `amd64`, `arm64`, `i386`, etc. |
|
||||||
|
| `--force-lowmem 1` | *auto* | Force low memory mode: `0`, `1`, `2` (for <512MB RAM) |
|
||||||
|
| `--no-force-efi-extra-removable` | *enabled* | Disable EFI extra removable media path |
|
||||||
|
| `--grub-timeout 5` | `5` | GRUB menu timeout in seconds |
|
||||||
|
|
||||||
|
### Debian Installer Options
|
||||||
|
| Option | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| `--release-d-i` | *auto* | Use release version of debian-installer |
|
||||||
|
| `--daily-d-i` | *auto* | Use daily build of debian-installer |
|
||||||
|
|
||||||
|
### Cloud-Init Integration
|
||||||
|
| Option | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| `--cidata /path/to/dir` | *none* | Custom cloud-init data directory |
|
||||||
|
|
||||||
|
**Cloud-Init Usage:**
|
||||||
|
```bash
|
||||||
|
# Create cloud-init configuration
|
||||||
|
mkdir my-cloud-config
|
||||||
|
echo "instance-id: my-server" > my-cloud-config/meta-data
|
||||||
|
cat > my-cloud-config/user-data << 'EOF'
|
||||||
|
#cloud-config
|
||||||
|
hostname: my-server
|
||||||
|
packages:
|
||||||
|
- htop
|
||||||
|
- git
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Use with installation
|
||||||
|
sudo ./debi.sh --cidata my-cloud-config
|
||||||
```
|
```
|
||||||
|
|
||||||
* `--bbr` 开启 BBR
|
### Development & Testing
|
||||||
* `--ethx` 网卡名称使用传统形式,如 `eth0` 而不是 `ens3`
|
| Option | Default | Description |
|
||||||
* `--cloud-kernel` 安装占用空间较小的 `cloud` 内核,但可能会导致 UEFI 启动的机器(如 Oracle、Azure 及 Hyper-V、Google Cloud 等)VNC 黑屏。BIOS 启动的普通 VPS 则没有此问题。
|
|--------|---------|-------------|
|
||||||
* 默认时区为 UTC,添加 `--timezone Asia/Shanghai` 可使用中国时区。
|
| `--dry-run` | *execute* | Generate configuration without installing |
|
||||||
* 默认使用 Debian 官方 CDN 镜像源(deb.debian.org),添加 `--china` 可使用阿里云镜像源。
|
| `--hold` | *reboot* | Don't reboot after installation |
|
||||||
|
| `--power-off` | *reboot* | Power off instead of reboot |
|
||||||
|
|
||||||
如果没有报错可以重启:
|
## Examples
|
||||||
|
|
||||||
```
|
### Oracle Cloud (Ubuntu → Debian)
|
||||||
sudo shutdown -r now
|
```bash
|
||||||
|
sudo ./debi.sh --cloudflare --user debian
|
||||||
```
|
```
|
||||||
|
|
||||||
约 30 秒后可以尝试 SSH 登录 `installer` 用户,密码与之前设置的相同。如果成功连接,可以按 Ctrl-A 然后再按 4 监控安装日志。安装完成后会自动重启进入新系统。
|
### Google Cloud Platform
|
||||||
|
```bash
|
||||||
|
# GCP requires manual network (replace with your VPC settings)
|
||||||
|
sudo ./debi.sh --ip 10.128.0.100/24 --gateway 10.128.0.1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Minimal Installation
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --no-install-recommends --install 'curl git vim' --no-upgrade
|
||||||
|
```
|
||||||
|
|
||||||
### [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)
|
### China Deployment
|
||||||
### [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)
|
```bash
|
||||||
|
sudo ./debi.sh --ustc --timezone Asia/Shanghai --dns '119.29.29.29'
|
||||||
|
```
|
||||||
|
|
||||||
## Introduction
|
### Network Console Installation
|
||||||
|
```bash
|
||||||
|
# Enable remote access during install (SSH keys for network, password still needed for VNC/sudo)
|
||||||
|
sudo ./debi.sh --network-console --authorized-keys-url https://github.com/yourusername.keys
|
||||||
|
# After reboot, SSH: ssh installer@YOUR_IP
|
||||||
|
```
|
||||||
|
|
||||||
This script is written to reinstall a VPS/virtual machine to minimal Debian 10/11/12.
|
### Static Network with Cloud-Init
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --ip 192.168.1.100/24 --gateway 192.168.1.1 --cidata ./cloud-config/
|
||||||
|
```
|
||||||
|
|
||||||
## Should Work On
|
### Advanced Custom Configuration
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh \
|
||||||
|
--version 13 \
|
||||||
|
--user admin \
|
||||||
|
--timezone Europe/London \
|
||||||
|
--disk /dev/nvme0n1 \
|
||||||
|
--filesystem btrfs \
|
||||||
|
--cloud-kernel \
|
||||||
|
--bbr \
|
||||||
|
--ssh-port 2222 \
|
||||||
|
--install 'htop iotop ncdu'
|
||||||
|
```
|
||||||
|
|
||||||
### Virtualization Platform
|
## Troubleshooting
|
||||||
|
|
||||||
* SolusVM/OpenStack/DigitalOcean/Vultr/Linode/Proxmox/QEMU KVM (BIOS boot)
|
### Revert All Changes
|
||||||
* Oracle Cloud Infrastructure (UEFI boot)
|
```bash
|
||||||
* Google Cloud Compute Engine (**Must manually configure the VPC internal IP and the gateway.** UEFI boot with Secure Boot support)
|
# Remove all modifications and restore original GRUB
|
||||||
* AWS EC2 & Lightsail (BIOS boot)
|
sudo rm -rf /etc/default/grub.d/zz-debi.cfg /boot/debian-*
|
||||||
* Hyper-V & Azure (Generation 1 BIOS boot & Generation 2 UEFI boot)
|
sudo update-grub || sudo grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||||
|
```
|
||||||
|
|
||||||
### Original OS
|
### Common Issues
|
||||||
|
|
||||||
* Debian 8 or later
|
**Multiple disks detected:**
|
||||||
* Ubuntu 14.04 or later
|
```bash
|
||||||
* CentOS 7 or later
|
# List available disks
|
||||||
|
lsblk
|
||||||
|
# Specify target disk
|
||||||
|
sudo ./debi.sh --disk /dev/sda
|
||||||
|
```
|
||||||
|
|
||||||
|
**Low memory VPS (<512MB):**
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --force-lowmem 1
|
||||||
|
```
|
||||||
|
|
||||||
|
**Network configuration fails:**
|
||||||
|
```bash
|
||||||
|
# Use current network settings
|
||||||
|
sudo ./debi.sh --static-ipv4
|
||||||
|
|
||||||
|
# Or configure manually
|
||||||
|
sudo ./debi.sh --ip YOUR_IP/CIDR --gateway YOUR_GATEWAY
|
||||||
|
```
|
||||||
|
|
||||||
|
**Need firmware for network card:**
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --firmware
|
||||||
|
```
|
||||||
|
|
||||||
|
**Installation debugging:**
|
||||||
|
```bash
|
||||||
|
# Generate preseed file only
|
||||||
|
sudo ./debi.sh --dry-run
|
||||||
|
|
||||||
|
# Enable network console for remote access (SSH keys for remote, password for VNC/sudo)
|
||||||
|
sudo ./debi.sh --network-console --authorized-keys-url YOUR_KEYS_URL
|
||||||
|
```
|
||||||
|
|
||||||
## How It Works
|
## How It Works
|
||||||
|
|
||||||
1. Generate a preseed file to automate installation
|
1. **Downloads Debian installer** to `/boot/debian-$VERSION/`
|
||||||
2. Download the 'Debian-Installer' to the `/boot` directory
|
2. **Generates preseed file** with your configuration
|
||||||
3. Append a menu entry of the installer to the GRUB2 configuration file
|
3. **Modifies GRUB configuration** (adds installer menu entry)
|
||||||
|
4. **Injects configuration** into installer initramfs
|
||||||
|
5. **Updates GRUB** to include new boot option
|
||||||
|
|
||||||
## Usage
|
**Changes made to your system:**
|
||||||
|
- Files added to `/boot/debian-*/`
|
||||||
|
- GRUB configuration in `/etc/default/grub.d/zz-debi.cfg`
|
||||||
|
- Updated GRUB menu
|
||||||
|
|
||||||
### 1. Download
|
**These changes are safe and reversible** before reboot using the revert command above.
|
||||||
|
|
||||||
Download the script with curl:
|
---
|
||||||
|
|
||||||
curl -fLO https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh
|
*Created by [@bohanyang](https://github.com/bohanyang) • [Issues](https://github.com/bohanyang/debi/issues) • [GitHub](https://github.com/bohanyang/debi)*
|
||||||
|
|
||||||
# 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:
|
|
||||||
|
|
||||||
wget -O debi.sh https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh
|
|
||||||
|
|
||||||
### 2. Run
|
|
||||||
|
|
||||||
Run the script under root or using sudo:
|
|
||||||
|
|
||||||
chmod a+rx debi.sh
|
|
||||||
sudo ./debi.sh
|
|
||||||
|
|
||||||
By default, an admin user `debian` with sudo privilege will be created during the installation. Use `--user root` if you prefer.
|
|
||||||
|
|
||||||
### 3. Reboot
|
|
||||||
|
|
||||||
If everything looks good, reboot the machine:
|
|
||||||
|
|
||||||
sudo shutdown -r now
|
|
||||||
|
|
||||||
Otherwise, you can run this command to revert all changes made by the script:
|
|
||||||
|
|
||||||
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; }
|
|
||||||
|
|
||||||
## Available Options
|
|
||||||
|
|
||||||
* `--interface <string>` Manually select a network interface, e.g. eth1
|
|
||||||
* `--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`
|
|
||||||
* `--netmask <string>` e.g. `255.255.255.0`, `ffff:ffff:ffff:ffff::`
|
|
||||||
* `--gateway <string>` e.g. `10.0.0.1`, `none` if no gateway
|
|
||||||
* `--dns '8.8.8.8 8.8.4.4'` (Default IPv6 DNS: `2001:4860:4860::8888 2001:4860:4860::8844`)
|
|
||||||
* `--hostname <string>` FQDN hostname (includes the domain name), e.g. `server1.example.com`
|
|
||||||
* `--network-console` Enable the network console of the installer. `ssh installer@ip` to connect
|
|
||||||
* `--version 12` Supports: `10`, `11`, `12`, `13`
|
|
||||||
* `--suite bullseye` **Please use `--version` instead if you don't have special needs.** e.g. `stable`, `testing`, `sid`
|
|
||||||
* `--release-d-i` d-i (Debian Installer) for the released versions: 12 (bookworm), 11 (bullseye) and 10 (buster)
|
|
||||||
* `--daily-d-i` Use latest daily build of d-i (Debian Installer) for the unreleased version: 13 (trixie), sid (unstable)
|
|
||||||
* `--mirror-protocol http` or `https` or `ftp`
|
|
||||||
* `--https` alias to `--mirror-protocol https`
|
|
||||||
* `--reuse-proxy` Reuse the value of `http(s)_proxy` environment variable as the mirror proxy
|
|
||||||
* `--proxy, --mirror-proxy` Set an HTTP proxy for APT and downloads
|
|
||||||
* `--mirror-host deb.debian.org`
|
|
||||||
* `--mirror-directory /debian`
|
|
||||||
* `--security-repository http://security.debian.org/debian-security` Magic value: `'mirror' = <mirror-protocol>://<mirror-host>/<mirror-directory>/../debian-security`
|
|
||||||
* `--no-account-setup, --no-user` **(Manual installation)** Proceed account setup manually in VNC or remote console.
|
|
||||||
* `--username, --user debian` New user with `sudo` privilege or `root`
|
|
||||||
* `--password <string>` Password of the new user. **You'll be prompted if you choose to not specify it here**
|
|
||||||
* `--authorized-keys-url <string>` URL to your authorized keys for SSH authentication. e.g. `https://github.com/torvalds.keys`
|
|
||||||
* `--sudo-with-password` Require password when the user invokes `sudo` command
|
|
||||||
* `--timezone UTC` e.g. `Asia/Shanghai` for China (UTC+8) https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
|
|
||||||
* `--ntp 0.debian.pool.ntp.org`
|
|
||||||
* `--no-disk-partitioning, --no-part` **(Manual installation)** Proceed disk partitioning manually in VNC or remote console
|
|
||||||
* `--disk <string>` Manually select a disk for installation. **Please remember to specify this when more than one disk is available!** e.g. `/dev/sda`
|
|
||||||
* `--no-force-gpt` By default, GPT rather than MBR partition table will be created. This option disables it.
|
|
||||||
* `--bios` Don't create *EFI system partition*. If GPT is being used, create a *BIOS boot partition* (`bios_grub` partition). Default if `/sys/firmware/efi` is absent. [See](https://askubuntu.com/a/501360)
|
|
||||||
* `--efi` Create an *EFI system partition*. Default if `/sys/firmware/efi` exists
|
|
||||||
* `--esp 106` Size of the *EFI system partition*. e.g. `106`, `538` and `1075` result to 100 MiB, 512 MiB, 1 GiB respectively
|
|
||||||
* `--filesystem ext4`
|
|
||||||
* `--kernel <string>` Choose an package for the kernel image
|
|
||||||
* `--cloud-kernel` Choose `linux-image-cloud-amd64` or `...arm64` as the kernel image
|
|
||||||
* `--bpo-kernel` Choose the kernel image from Debian Backports (newer version from the next Debian release)
|
|
||||||
* `--no-install-recommends`
|
|
||||||
* `--apt-non-free-firmware` (Debian 12 or later), `--apt-non-free`, `--apt-contrib`, `--apt-src`, `--apt-backports`
|
|
||||||
* `--no-apt-non-free-firmware` (Debian 12 or later), `--no-apt-non-free`, `--no-apt-contrib`, `--no-apt-src`, `--no-apt-backports`
|
|
||||||
* `--install 'ca-certificates libpam-systemd'` Install additional APT packages. Space-separated and quoted.
|
|
||||||
* `--safe-upgrade` **(Default)** `apt upgrade --with-new-pkgs`. [See](https://salsa.debian.org/installer-team/pkgsel/-/blob/master/debian/postinst)
|
|
||||||
* `--full-upgrade` `apt dist-upgrade`
|
|
||||||
* `--no-upgrade`
|
|
||||||
* `--bbr` Enable TCP BBR congestion control
|
|
||||||
* `--ssh-port <integer>` SSH port
|
|
||||||
* `--hold` Don't reboot or power off after installation
|
|
||||||
* `--power-off` Power off after installation rather than reboot
|
|
||||||
* `--architecture <string>` e.g. `amd64`, `i386`, `arm64`, `armhf`, etc.
|
|
||||||
* `--firmware` Load additional [non-free firmwares](https://wiki.debian.org/Firmware#Firmware_during_the_installation)
|
|
||||||
* `--no-force-efi-extra-removable` [See](https://wiki.debian.org/UEFI#Force_grub-efi_installation_to_the_removable_media_path)
|
|
||||||
* `--grub-timeout 5` How many seconds the GRUB menu shows before entering the installer
|
|
||||||
* `--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
|
|
||||||
|
|
||||||
### Presets
|
|
||||||
|
|
||||||
### `--cdn`
|
|
||||||
|
|
||||||
* `--mirror-protocol https`
|
|
||||||
* `--mirror-host deb.debian.org`
|
|
||||||
* `--security-repository mirror`
|
|
||||||
|
|
||||||
### `--aws`
|
|
||||||
|
|
||||||
* `--mirror-protocol https`
|
|
||||||
* `--mirror-host cdn-aws.deb.debian.org`
|
|
||||||
* `--security-repository mirror`
|
|
||||||
|
|
||||||
### `--china`
|
|
||||||
|
|
||||||
* `--dns '223.5.5.5 223.6.6.6'`
|
|
||||||
* `--mirror-protocol https`
|
|
||||||
* `--mirror-host mirrors.aliyun.com`
|
|
||||||
* `--security-repository mirror`
|
|
||||||
* `--ntp ntp.aliyun.com`
|
|
||||||
|
|||||||
+357
@@ -0,0 +1,357 @@
|
|||||||
|
<div lang="zh-CN">
|
||||||
|
|
||||||
|
# Debian 网络重装脚本
|
||||||
|
|
||||||
|
## 这是什么?
|
||||||
|
|
||||||
|
一个通过网络启动(network boot)方式,将任何 VPS 或物理机重装为最小化 Debian 系统的脚本。其工作原理是将 Debian 安装程序注入到 GRUB 中,并自动完成安装过程的配置。
|
||||||
|
|
||||||
|
**非常适合以下场景:**
|
||||||
|
|
||||||
|
- 将 Oracle Cloud 的 Ubuntu 镜像更换为 Debian
|
||||||
|
- 移除云服务商内置的监控代理
|
||||||
|
- 创建最小、纯净的 Debian 环境
|
||||||
|
- 使用 preseed 或 cloud-init 实现自动化安装
|
||||||
|
- 拯救或恢复损坏的系统
|
||||||
|
|
||||||
|
## 快速上手
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 下载脚本
|
||||||
|
curl -fLO https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh
|
||||||
|
chmod +x debi.sh
|
||||||
|
|
||||||
|
# 基础安装 (会创建一个拥有 sudo 权限的 'debian' 用户)
|
||||||
|
sudo ./debi.sh
|
||||||
|
|
||||||
|
# 或者,直接以 root 用户安装
|
||||||
|
sudo ./debi.sh --user root
|
||||||
|
|
||||||
|
# 准备就绪后重启
|
||||||
|
sudo reboot
|
||||||
|
```
|
||||||
|
|
||||||
|
**默认设置:** Debian 13 (trixie),DHCP 网络,创建一个名为 `debian` 并拥有 sudo 权限的用户,脚本会提示你为该用户设置密码。
|
||||||
|
|
||||||
|
## 平台支持
|
||||||
|
|
||||||
|
| 平台 | 状态 | 备注 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| ✅ **KVM/物理机** | 完全支持 | 所有功能均可正常工作 |
|
||||||
|
| ✅ **大多数 VPS** | 完全支持 | DigitalOcean, Vultr, Linode 等 |
|
||||||
|
| ⚠️ **Google Cloud** | 需要手动配置网络 | 必须使用 `--ip` 和 `--gateway` (DHCP 工作不正常) |
|
||||||
|
| ⚠️ **AWS EC2** | 仅支持 BIOS | 尚不支持 UEFI 启动模式 |
|
||||||
|
| ❌ **容器** | 不支持 | 需要 GRUB 引导加载程序 |
|
||||||
|
|
||||||
|
**环境要求:**
|
||||||
|
|
||||||
|
- KVM 虚拟化或物理机 (不支持容器)
|
||||||
|
- GRUB 2 引导加载程序
|
||||||
|
- Root 权限
|
||||||
|
|
||||||
|
## 区域预设
|
||||||
|
|
||||||
|
| 预设 | 镜像源 | DNS | NTP | 适用场景 |
|
||||||
|
| :--- | :--- | :--- | :--- | :--- |
|
||||||
|
| *默认* | deb.debian.org | Google DNS | time.google.com | 全球通用 |
|
||||||
|
| `--cloudflare` | deb.debian.org | Cloudflare | time.cloudflare.com | 全球通用 (注重隐私) |
|
||||||
|
| `--aws` | cdn-aws.deb.debian.org | Google DNS | time.aws.com | AWS 实例 |
|
||||||
|
| `--aliyun` | mirrors.aliyun.com | AliDNS | time.amazonaws.cn | 中国大陆 |
|
||||||
|
| `--ustc` | mirrors.ustc.edu.cn | DNSPod | time.amazonaws.cn | 中国大陆 |
|
||||||
|
| `--tuna` | mirrors.tuna.tsinghua.edu.cn | DNSPod | time.amazonaws.cn | 中国大陆 |
|
||||||
|
|
||||||
|
## 完整选项参考
|
||||||
|
|
||||||
|
### 系统和用户配置
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--version 13` | `13` | Debian 版本:`10`, `11`, `12`, `13`, `14` |
|
||||||
|
| `--suite trixie` | `trixie` | Debian 发行代号:`stable`, `testing`, `sid` 等 |
|
||||||
|
| `--user debian` | `debian` | 用户名 (使用 `root` 则只创建 root 用户) |
|
||||||
|
| `--password PASSWORD` | *交互式提示* | 用户密码 (如果未指定,则会提示输入) |
|
||||||
|
| `--authorized-keys-url URL` | *密码认证* | 从 URL 加载 SSH 公钥 (例如 `https://github.com/user.keys`) |
|
||||||
|
| `--no-account-setup` | *创建用户* | 跳过用户创建步骤 (需要通过控制台手动设置) |
|
||||||
|
| `--sudo-with-password` | *无需密码* | 执行 sudo 命令时需要输入密码 |
|
||||||
|
| `--timezone UTC` | `UTC` | 系统时区 (例如 `Asia/Shanghai`) |
|
||||||
|
| `--hostname NAME` | *当前主机名* | 系统主机名 |
|
||||||
|
|
||||||
|
### 网络配置
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--interface auto` | `auto` | 网络接口 (例如 `eth0`, `eth1`) |
|
||||||
|
| `--ip ADDRESS` | *DHCP* | 静态 IP:`10.0.0.100`, `1.2.3.4/24`, `2001:db8::1/64` |
|
||||||
|
| `--static-ipv4` | *DHCP* | 自动使用当前系统的 IPv4 设置 |
|
||||||
|
| `--netmask MASK` | *自动* | 子网掩码:`255.255.255.0`, `ffff:ffff:ffff:ffff::` |
|
||||||
|
| `--gateway ADDRESS` | *自动* | 网关 IP (使用 `none` 表示无网关) |
|
||||||
|
| `--dns '8.8.8.8 8.8.4.4'` | `1.1.1.1 1.0.0.1` | IPv4 的 DNS 服务器 |
|
||||||
|
| `--dns6 '2001:4860:4860::8888'` | `2606:4700:4700::1111` | IPv6 的 DNS 服务器 |
|
||||||
|
| `--ethx` | *一致性命名* | 使用 `eth0`/`eth1` 风格的网卡名,而不是 `enp0s3` |
|
||||||
|
| `--ntp time.google.com` | `time.google.com` | NTP 时间服务器 |
|
||||||
|
|
||||||
|
### 网络控制台 (远程安装)
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--network-console` | *禁用* | 在安装过程中启用 SSH 访问 |
|
||||||
|
|
||||||
|
**网络控制台用法:**
|
||||||
|
|
||||||
|
1. 使用 `--network-console` 参数并重启
|
||||||
|
2. 等待 2-3 分钟,让 Debian 安装程序加载组件
|
||||||
|
3. 通过 SSH 连接到你的服务器:`ssh installer@YOUR_IP`
|
||||||
|
4. 使用多个终端窗口进行操作:
|
||||||
|
- **Alt+F1**: 主安装界面
|
||||||
|
- **Alt+F2**: Shell 终端
|
||||||
|
- **Alt+F3**: 另一个 Shell 终端
|
||||||
|
- **Alt+F4**: 系统日志 (可监控自动化安装进度)
|
||||||
|
- 使用 Alt+Left/Alt+Right 切换
|
||||||
|
|
||||||
|
|
||||||
|
**⚠️ 注意事项**
|
||||||
|
|
||||||
|
如果使用了 `--authorized-keys-url`,SSH 的密码认证将被禁用 (必须使用 SSH 密钥登录),**但你仍然需要设置一个用户密码**,用于 VNC 控制台登录和执行 sudo 命令。
|
||||||
|
|
||||||
|
### 存储和分区
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--disk /dev/sda` | *自动检测* | 目标磁盘 (**如果有多块磁盘,此项为必填**) |
|
||||||
|
| `--no-disk-partitioning` | *自动分区* | 通过控制台手动分区 |
|
||||||
|
| `--filesystem ext4` | `ext4` | 根文件系统类型 |
|
||||||
|
| `--force-gpt` | *启用* | 创建 GPT 分区表 |
|
||||||
|
| `--no-force-gpt` | *使用 GPT* | 使用 MBR 分区表代替 GPT |
|
||||||
|
| `--bios` | *自动检测* | 强制使用 BIOS 启动 (会创建 BIOS boot 分区) |
|
||||||
|
| `--efi` | *自动检测* | 强制使用 EFI 启动 (会创建 EFI 系统分区) |
|
||||||
|
| `--esp 106` | `106` | EFI 系统分区 (ESP) 大小 (106=100MB, 538=512MB, 1075=1GB) |
|
||||||
|
|
||||||
|
### 镜像源和仓库配置
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--mirror-protocol https` | `https` | 镜像源协议:`http`, `https`, `ftp` |
|
||||||
|
| `--https` | *启用* | `--mirror-protocol https` 的别名 |
|
||||||
|
| `--mirror-host deb.debian.org` | `deb.debian.org` | 镜像源主机名 |
|
||||||
|
| `--mirror-directory /debian` | `/debian` | 镜像源目录路径 |
|
||||||
|
| `--mirror-proxy URL` | *无* | 用于下载和 APT 的 HTTP 代理 |
|
||||||
|
| `--reuse-proxy` | *无* | 使用当前环境中的 `http_proxy` 变量 |
|
||||||
|
| `--security-repository URL` | *自动* | 安全更新仓库地址 (使用 `mirror` 表示与主镜像源一致) |
|
||||||
|
|
||||||
|
### APT 仓库组件
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--apt-non-free-firmware` | *启用* | 包含 non-free-firmware (Debian 12+) |
|
||||||
|
| `--apt-non-free` | *禁用* | 启用 non-free 仓库 |
|
||||||
|
| `--apt-contrib` | *禁用* | 启用 contrib 仓库 |
|
||||||
|
| `--apt-src` | *启用* | 启用源码仓库 |
|
||||||
|
| `--apt-backports` | *启用* | 启用 backports 仓库 |
|
||||||
|
| `--no-apt-non-free-firmware` | *使用默认值* | 禁用 non-free-firmware |
|
||||||
|
| `--no-apt-non-free` | *使用默认值* | 禁用 non-free |
|
||||||
|
| `--no-apt-contrib` | *使用默认值* | 禁用 contrib |
|
||||||
|
| `--no-apt-src` | *使用默认值* | 禁用源码仓库 |
|
||||||
|
| `--no-apt-backports` | *使用默认值* | 禁用 backports |
|
||||||
|
|
||||||
|
### 软件包安装
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--install 'pkg1 pkg2'` | *最小化* | 额外安装的软件包 (用空格分隔,并用引号括起来) |
|
||||||
|
| `--install-recommends` | *启用* | 安装推荐的软件包 |
|
||||||
|
| `--no-install-recommends` | *安装推荐包* | 跳过推荐的软件包 |
|
||||||
|
| `--upgrade safe-upgrade` | `safe-upgrade` | 软件包升级模式 |
|
||||||
|
| `--safe-upgrade` | *默认* | 在安装过程中执行安全的软件包升级 |
|
||||||
|
| `--full-upgrade` | *安全升级* | 执行完整的系统升级 (`dist-upgrade`) |
|
||||||
|
| `--no-upgrade` | *安全升级* | 完全跳过软件包升级 |
|
||||||
|
|
||||||
|
### 内核选项
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--kernel PACKAGE` | `linux-image-ARCH` | 内核软件包名称 |
|
||||||
|
| `--cloud-kernel` | *标准内核* | 使用为云环境优化的内核 |
|
||||||
|
| `--bpo-kernel` | *稳定版内核* | 使用来自 backports 的较新内核 |
|
||||||
|
| `--firmware` | *自动检测* | 为硬件安装 non-free 固件 |
|
||||||
|
|
||||||
|
### 高级选项
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--ssh-port 2222` | `22` | 自定义 SSH 端口 |
|
||||||
|
| `--bbr` | *禁用* | 启用 TCP BBR 拥塞控制算法 |
|
||||||
|
| `--architecture amd64` | *自动检测* | 目标系统架构:`amd64`, `arm64`, `i386` 等 |
|
||||||
|
| `--force-lowmem 1` | *自动* | 强制开启低内存模式:`0`, `1`, `2` (适用于内存 \<512MB 的机器) |
|
||||||
|
| `--no-force-efi-extra-removable` | *启用* | 禁用 EFI 的 extra removable media 路径 |
|
||||||
|
| `--grub-timeout 5` | `5` | GRUB 菜单等待超时时间 (秒) |
|
||||||
|
|
||||||
|
### Debian 安装程序选项
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--release-d-i` | *自动* | 使用发布版的 debian-installer |
|
||||||
|
| `--daily-d-i` | *自动* | 使用每日构建版的 debian-installer |
|
||||||
|
|
||||||
|
### Cloud-Init 集成
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--cidata /path/to/dir` | *无* | 自定义 cloud-init 数据目录 |
|
||||||
|
|
||||||
|
**Cloud-Init 用法:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 创建 cloud-init 配置文件
|
||||||
|
mkdir my-cloud-config
|
||||||
|
echo "instance-id: my-server" > my-cloud-config/meta-data
|
||||||
|
cat > my-cloud-config/user-data << 'EOF'
|
||||||
|
#cloud-config
|
||||||
|
hostname: my-server
|
||||||
|
packages:
|
||||||
|
- htop
|
||||||
|
- git
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 在安装时使用
|
||||||
|
sudo ./debi.sh --cidata my-cloud-config
|
||||||
|
```
|
||||||
|
|
||||||
|
### 开发与测试
|
||||||
|
|
||||||
|
| 选项 | 默认值 | 描述 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `--dry-run` | *执行* | 只生成配置文件,不执行安装 |
|
||||||
|
| `--hold` | *重启* | 安装后不重启 |
|
||||||
|
| `--power-off` | *重启* | 安装后关机而不是重启 |
|
||||||
|
|
||||||
|
## 使用示例
|
||||||
|
|
||||||
|
### Oracle Cloud (Ubuntu → Debian)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --cloudflare --user debian
|
||||||
|
```
|
||||||
|
|
||||||
|
### Google Cloud Platform
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# GCP 需要手动配置网络 (请替换为你的 VPC 设置)
|
||||||
|
sudo ./debi.sh --ip 10.128.0.100/24 --gateway 10.128.0.1
|
||||||
|
```
|
||||||
|
|
||||||
|
### 最小化安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --no-install-recommends --install 'curl git vim' --no-upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
### 中国大陆部署
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --ustc --timezone Asia/Shanghai --dns '119.29.29.29'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 使用网络控制台安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 在安装过程中启用远程访问 (SSH 密钥用于网络登录,密码仍需用于 VNC/sudo)
|
||||||
|
sudo ./debi.sh --network-console --authorized-keys-url https://github.com/yourusername.keys
|
||||||
|
# 重启后,通过 SSH 连接: ssh installer@YOUR_IP
|
||||||
|
```
|
||||||
|
|
||||||
|
### 静态网络与 Cloud-Init
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --ip 192.168.1.100/24 --gateway 192.168.1.1 --cidata ./cloud-config/
|
||||||
|
```
|
||||||
|
|
||||||
|
### 高级自定义配置
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh \
|
||||||
|
--version 13 \
|
||||||
|
--user admin \
|
||||||
|
--timezone Europe/London \
|
||||||
|
--disk /dev/nvme0n1 \
|
||||||
|
--filesystem btrfs \
|
||||||
|
--cloud-kernel \
|
||||||
|
--bbr \
|
||||||
|
--ssh-port 2222 \
|
||||||
|
--install 'htop iotop ncdu'
|
||||||
|
```
|
||||||
|
|
||||||
|
## 故障排查
|
||||||
|
|
||||||
|
### 撤销所有更改
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 移除所有修改并恢复原始的 GRUB 配置
|
||||||
|
sudo rm -rf /etc/default/grub.d/zz-debi.cfg /boot/debian-*
|
||||||
|
sudo update-grub || sudo grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||||
|
```
|
||||||
|
|
||||||
|
### 常见问题
|
||||||
|
|
||||||
|
**检测到多块磁盘:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 列出可用磁盘
|
||||||
|
lsblk
|
||||||
|
# 指定目标磁盘
|
||||||
|
sudo ./debi.sh --disk /dev/sda
|
||||||
|
```
|
||||||
|
|
||||||
|
**低内存 VPS (\<512MB):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --force-lowmem 1
|
||||||
|
```
|
||||||
|
|
||||||
|
**网络配置失败:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 使用当前系统的网络设置
|
||||||
|
sudo ./debi.sh --static-ipv4
|
||||||
|
|
||||||
|
# 或者手动配置
|
||||||
|
sudo ./debi.sh --ip YOUR_IP/CIDR --gateway YOUR_GATEWAY
|
||||||
|
```
|
||||||
|
|
||||||
|
**网卡需要固件 (firmware):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./debi.sh --firmware
|
||||||
|
```
|
||||||
|
|
||||||
|
**安装过程调试:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 只生成 preseed 文件
|
||||||
|
sudo ./debi.sh --dry-run
|
||||||
|
|
||||||
|
# 启用网络控制台进行远程访问 (SSH 密钥用于远程登录,密码用于 VNC/sudo)
|
||||||
|
sudo ./debi.sh --network-console --authorized-keys-url YOUR_KEYS_URL
|
||||||
|
```
|
||||||
|
|
||||||
|
## 工作原理
|
||||||
|
|
||||||
|
1. **下载 Debian 安装程序** 到 `/boot/debian-$VERSION/` 目录
|
||||||
|
2. 根据你的配置**生成 preseed 应答文件**
|
||||||
|
3. **修改 GRUB 配置** (添加一个新的安装程序菜单项)
|
||||||
|
4. 将配置文件**注入到安装程序的 initramfs** 中
|
||||||
|
5. **更新 GRUB** 以加载新的启动选项
|
||||||
|
|
||||||
|
**对你系统所做的更改:**
|
||||||
|
|
||||||
|
- 在 `/boot/debian-*/` 目录中添加文件
|
||||||
|
- 在 `/etc/default/grub.d/zz-debi.cfg` 创建 GRUB 配置文件
|
||||||
|
- 更新 GRUB 菜单
|
||||||
|
|
||||||
|
**在重启之前,所有这些更改都是安全且可逆的**,可以使用上面的撤销命令来恢复。
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
|
*作者 [@bohanyang](https://github.com/bohanyang) • [问题反馈](https://github.com/bohanyang/debi/issues) • [GitHub 仓库](https://github.com/bohanyang/debi)*
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
instance-id: 4c75121c-44fb-4166-8717-800b73cab4e4
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#cloud-config
|
||||||
|
hostname: ci01
|
||||||
|
user: debian
|
||||||
|
disable_root: false
|
||||||
|
ssh_pwauth: true
|
||||||
|
password: 'kuras001'
|
||||||
|
ssh_authorized_keys:
|
||||||
|
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCgBp08hAwwPk2w2T+yvlqil7jqXlzM7ulIA9lrgJB9NJLZV3wyYEmcxP/frTSUanjWtiYlrmn5d6EJFwR01Ga+aD6hwQoSZtKyVGY7zKfM6NWKF/lcpFT6HxPg33C4tpueqSqupSlx2yoPqRZhVoCeERrN9k/7fN8Bv8Xvfa/LN8sAI4v8CEJ7BpRXplRwnxceECBdJm0d3ebzMTnj1sfWBTgu/5iwpDh8DRR6LEab7famSTTB8jo6gz3gcwZC+Q3L/UTxS4kcjiQTuX7G74ae9+oSOpuPfP7N0Yo7lJDr8LCZHqkAZC47mQ2baatmD4hc3ZdVD64k6V1b/ms+37/7 youth@DESKTOP-AV4DNMN
|
||||||
|
chpasswd: { expire: false }
|
||||||
|
|
||||||
|
write_files:
|
||||||
|
- content: |
|
||||||
|
[Swap]
|
||||||
|
What=/swapfile
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=swap.target
|
||||||
|
path: /etc/systemd/system/swapfile.swap
|
||||||
|
|
||||||
|
runcmd:
|
||||||
|
- [ sh, -c, "[ ! -e /swapfile ] && { fallocate -l 100M /swapfile && chmod 0600 /swapfile && mkswap /swapfile; }; systemctl daemon-reload && systemctl enable --now swapfile.swap" ]
|
||||||
@@ -18,7 +18,7 @@ command_exists() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Sets variable:
|
# Sets variable:
|
||||||
late_command=
|
in_target_script=
|
||||||
in_target() {
|
in_target() {
|
||||||
local command=
|
local command=
|
||||||
|
|
||||||
@@ -27,8 +27,8 @@ in_target() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "$command" ]; then
|
if [ -n "$command" ]; then
|
||||||
[ -z "$late_command" ] && late_command='true'
|
[ -z "$in_target_script" ] && in_target_script='true'
|
||||||
late_command="$late_command;$command"
|
in_target_script="$in_target_script;$command"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,12 +109,16 @@ set_mirror_proxy() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Determines the security repository path format based on Debian suite
|
||||||
|
# - Buster (Debian 10): Uses old format "buster/updates"
|
||||||
|
# - Bullseye onwards and testing: Uses new format "suite-security"
|
||||||
|
# - Sid/unstable: No security repository (fixes go directly to unstable)
|
||||||
set_security_archive() {
|
set_security_archive() {
|
||||||
case $suite in
|
case $suite in
|
||||||
buster|oldoldstable|bullseye|oldstable)
|
buster)
|
||||||
security_archive="$suite/updates"
|
security_archive="$suite/updates"
|
||||||
;;
|
;;
|
||||||
bookworm|stable|trixie|testing)
|
bullseye|oldoldstable|bookworm|oldstable|trixie|stable|forky|testing)
|
||||||
security_archive="$suite-security"
|
security_archive="$suite-security"
|
||||||
;;
|
;;
|
||||||
sid|unstable)
|
sid|unstable)
|
||||||
@@ -125,12 +129,16 @@ set_security_archive() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Determines whether to use daily or stable installer builds
|
||||||
|
# - Stable/oldstable releases: Use stable installer builds (thoroughly tested)
|
||||||
|
# - Testing/unstable: Use daily installer builds (latest changes, may be less stable)
|
||||||
|
# Daily builds are necessary for testing/unstable as they need the latest kernel and packages
|
||||||
set_daily_d_i() {
|
set_daily_d_i() {
|
||||||
case $suite in
|
case $suite in
|
||||||
buster|oldoldstable|bullseye|oldstable|bookworm|stable)
|
buster|bullseye|oldoldstable|bookworm|oldstable|trixie|stable)
|
||||||
daily_d_i=false
|
daily_d_i=false
|
||||||
;;
|
;;
|
||||||
trixie|testing|sid|unstable)
|
forky|testing|sid|unstable)
|
||||||
daily_d_i=true
|
daily_d_i=true
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@@ -144,19 +152,31 @@ set_suite() {
|
|||||||
set_security_archive
|
set_security_archive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Maps version numbers and release aliases to actual suite names
|
||||||
|
# Accepts: version number (10-14), suite name (buster, bullseye, etc.), or alias (stable, testing, etc.)
|
||||||
|
# Current mapping:
|
||||||
|
# - 10/buster: No longer supported as oldoldstable (archived)
|
||||||
|
# - 11/bullseye/oldoldstable: LTS support
|
||||||
|
# - 12/bookworm/oldstable: Previous stable
|
||||||
|
# - 13/trixie/stable: Current stable release
|
||||||
|
# - 14/forky/testing: Next release in development
|
||||||
|
# - sid/unstable: Rolling development branch
|
||||||
set_debian_version() {
|
set_debian_version() {
|
||||||
case $1 in
|
case $1 in
|
||||||
10|buster|oldoldstable)
|
10|buster)
|
||||||
set_suite buster
|
set_suite buster
|
||||||
;;
|
;;
|
||||||
11|bullseye|oldstable)
|
11|bullseye|oldoldstable)
|
||||||
set_suite bullseye
|
set_suite bullseye
|
||||||
;;
|
;;
|
||||||
12|bookworm|stable)
|
12|bookworm|oldstable)
|
||||||
set_suite bookworm
|
set_suite bookworm
|
||||||
;;
|
;;
|
||||||
13|trixie|testing)
|
13|trixie|stable)
|
||||||
set_suite bookworm
|
set_suite trixie
|
||||||
|
;;
|
||||||
|
14|forky|testing)
|
||||||
|
set_suite forky
|
||||||
;;
|
;;
|
||||||
sid|unstable)
|
sid|unstable)
|
||||||
set_suite sid
|
set_suite sid
|
||||||
@@ -166,13 +186,19 @@ set_debian_version() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Checks if cloud-optimized kernels are available for the current architecture and suite
|
||||||
|
# Cloud kernels are minimal kernels optimized for cloud/virtual environments
|
||||||
|
# - Buster: Only amd64 has cloud kernel, arm64 requires backports
|
||||||
|
# - Bullseye onwards: Both amd64 and arm64 have cloud kernels
|
||||||
|
# - Other architectures (i386, etc.): No cloud kernels available
|
||||||
|
# Returns 0 if available, 1 if not
|
||||||
has_cloud_kernel() {
|
has_cloud_kernel() {
|
||||||
case $suite in
|
case $suite in
|
||||||
buster|oldoldstable)
|
buster)
|
||||||
[ "$architecture" = amd64 ] && return
|
[ "$architecture" = amd64 ] && return
|
||||||
[ "$architecture" = arm64 ] && [ "$bpo_kernel" = true ] && return
|
[ "$architecture" = arm64 ] && [ "$bpo_kernel" = true ] && return
|
||||||
;;
|
;;
|
||||||
bullseye|oldstable|bookworm|stable|trixie|testing|sid|unstable)
|
bullseye|oldoldstable|bookworm|oldstable|trixie|stable|forky|testing|sid|unstable)
|
||||||
[ "$architecture" = amd64 ] || [ "$architecture" = arm64 ] && return
|
[ "$architecture" = amd64 ] || [ "$architecture" = arm64 ] && return
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@@ -182,11 +208,19 @@ has_cloud_kernel() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Checks if backports repository is available for the current suite
|
||||||
|
# Backports provide newer versions of packages from testing/unstable rebuilt for stable releases
|
||||||
|
# - All stable releases and testing: Have backports available
|
||||||
|
# - Sid/unstable: No backports (already has the latest packages)
|
||||||
|
# Returns 0 if available, 1 if not
|
||||||
has_backports() {
|
has_backports() {
|
||||||
case $suite in
|
case $suite in
|
||||||
buster|oldoldstable|bullseye|oldstable|bookworm|stable|trixie|testing) return
|
bookworm|oldstable|trixie|stable|forky|testing) return
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# buster|bullseye|oldoldstable DO have backports, but it's in archive.debian.org now
|
||||||
|
# considering mirrors support varies and the code complexity we must accommodate, we just treat them as no backports available
|
||||||
|
|
||||||
warn "No backports kernel is available for $suite"
|
warn "No backports kernel is available for $suite"
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
@@ -196,24 +230,26 @@ 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='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 13
|
||||||
mirror_protocol=http
|
mirror_protocol=https
|
||||||
mirror_host=deb.debian.org
|
mirror_host=deb.debian.org
|
||||||
mirror_directory=/debian
|
mirror_directory=/debian
|
||||||
mirror_proxy=
|
mirror_proxy=
|
||||||
security_repository=http://security.debian.org/debian-security
|
security_repository=mirror
|
||||||
account_setup=true
|
account_setup=true
|
||||||
username=debian
|
username=debian
|
||||||
password=
|
password=
|
||||||
authorized_keys_url=
|
authorized_keys_url=
|
||||||
sudo_with_password=false
|
sudo_with_password=false
|
||||||
timezone=UTC
|
timezone=UTC
|
||||||
ntp=0.debian.pool.ntp.org
|
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
|
||||||
@@ -222,7 +258,7 @@ kernel=
|
|||||||
cloud_kernel=false
|
cloud_kernel=false
|
||||||
bpo_kernel=false
|
bpo_kernel=false
|
||||||
install_recommends=true
|
install_recommends=true
|
||||||
install='ca-certificates libpam-systemd'
|
install=
|
||||||
upgrade=
|
upgrade=
|
||||||
kernel_params=
|
kernel_params=
|
||||||
force_lowmem=
|
force_lowmem=
|
||||||
@@ -240,20 +276,46 @@ apt_non_free=false
|
|||||||
apt_contrib=false
|
apt_contrib=false
|
||||||
apt_src=true
|
apt_src=true
|
||||||
apt_backports=true
|
apt_backports=true
|
||||||
|
cidata=
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--cdn|--aws)
|
--cdn)
|
||||||
mirror_protocol=https
|
|
||||||
[ "$1" = '--aws' ] && mirror_host=cdn-aws.deb.debian.org
|
|
||||||
security_repository=mirror
|
|
||||||
;;
|
;;
|
||||||
--china)
|
--aws)
|
||||||
|
mirror_host=cdn-aws.deb.debian.org
|
||||||
|
ntp=time.aws.com
|
||||||
|
;;
|
||||||
|
--cloudflare)
|
||||||
|
dns='1.1.1.1 1.0.0.1'
|
||||||
|
dns6='2606:4700:4700::1111 2606:4700:4700::1001'
|
||||||
|
ntp=time.cloudflare.com
|
||||||
|
;;
|
||||||
|
--aliyun)
|
||||||
dns='223.5.5.5 223.6.6.6'
|
dns='223.5.5.5 223.6.6.6'
|
||||||
mirror_protocol=https
|
dns6='2400:3200::1 2400:3200:baba::1'
|
||||||
mirror_host=mirrors.aliyun.com
|
mirror_host=mirrors.aliyun.com
|
||||||
ntp=ntp.aliyun.com
|
ntp=time.amazonaws.cn
|
||||||
security_repository=mirror
|
;;
|
||||||
|
--ustc|--china)
|
||||||
|
dns='119.29.29.29'
|
||||||
|
dns6='2402:4e00::'
|
||||||
|
mirror_host=mirrors.ustc.edu.cn
|
||||||
|
ntp=time.amazonaws.cn
|
||||||
|
;;
|
||||||
|
--tuna)
|
||||||
|
dns='119.29.29.29'
|
||||||
|
dns6='2402:4e00::'
|
||||||
|
mirror_host=mirrors.tuna.tsinghua.edu.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
|
||||||
@@ -275,6 +337,10 @@ while [ $# -gt 0 ]; do
|
|||||||
dns=$2
|
dns=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--dns6)
|
||||||
|
dns6=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--hostname)
|
--hostname)
|
||||||
hostname=$2
|
hostname=$2
|
||||||
shift
|
shift
|
||||||
@@ -468,6 +534,12 @@ while [ $# -gt 0 ]; do
|
|||||||
--dry-run)
|
--dry-run)
|
||||||
dry_run=true
|
dry_run=true
|
||||||
;;
|
;;
|
||||||
|
--cidata)
|
||||||
|
cidata=$(realpath "$2")
|
||||||
|
[ ! -f "$cidata/meta-data" ] && err 'No "meta-data" file found in the cloud-init directory'
|
||||||
|
[ ! -f "$cidata/user-data" ] && err 'No "user-data" file found in the cloud-init directory'
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
err "Unknown option: \"$1\""
|
err "Unknown option: \"$1\""
|
||||||
esac
|
esac
|
||||||
@@ -502,9 +574,14 @@ done
|
|||||||
[ -n "$authorized_keys_url" ] && ! download "$authorized_keys_url" /dev/null &&
|
[ -n "$authorized_keys_url" ] && ! download "$authorized_keys_url" /dev/null &&
|
||||||
err "Failed to download SSH authorized public keys from \"$authorized_keys_url\""
|
err "Failed to download SSH authorized public keys from \"$authorized_keys_url\""
|
||||||
|
|
||||||
|
# Determines if the non-free-firmware repository component is available
|
||||||
|
# Starting from Debian 12 (Bookworm), firmware was split into a separate component
|
||||||
|
# to make it easier to include necessary firmware while keeping main free
|
||||||
|
# - Bookworm onwards: non-free-firmware component available
|
||||||
|
# - Bullseye and earlier: Firmware is in non-free component
|
||||||
non_free_firmware_available=false
|
non_free_firmware_available=false
|
||||||
case $suite in
|
case $suite in
|
||||||
bookworm|stable|trixie|testing|sid|unstable)
|
bookworm|oldstable|trixie|stable|forky|testing|sid|unstable)
|
||||||
non_free_firmware_available=true
|
non_free_firmware_available=true
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@@ -517,7 +594,7 @@ apt_components=main
|
|||||||
[ "$apt_non_free_firmware" = true ] && apt_components="$apt_components non-free-firmware"
|
[ "$apt_non_free_firmware" = true ] && apt_components="$apt_components non-free-firmware"
|
||||||
|
|
||||||
apt_services=updates
|
apt_services=updates
|
||||||
[ "$apt_backports" = true ] && apt_services="$apt_services, backports"
|
[ "$apt_backports" = true ] && has_backports && apt_services="$apt_services, backports"
|
||||||
|
|
||||||
installer_directory="/boot/debian-$suite"
|
installer_directory="/boot/debian-$suite"
|
||||||
|
|
||||||
@@ -554,11 +631,15 @@ EOF
|
|||||||
echo "d-i netcfg/get_ipaddress string $ip" | $save_preseed
|
echo "d-i netcfg/get_ipaddress string $ip" | $save_preseed
|
||||||
[ -n "$netmask" ] && echo "d-i netcfg/get_netmask string $netmask" | $save_preseed
|
[ -n "$netmask" ] && echo "d-i netcfg/get_netmask string $netmask" | $save_preseed
|
||||||
[ -n "$gateway" ] && echo "d-i netcfg/get_gateway string $gateway" | $save_preseed
|
[ -n "$gateway" ] && echo "d-i netcfg/get_gateway string $gateway" | $save_preseed
|
||||||
[ -z "${ip%%*:*}" ] && [ -n "${dns%%*:*}" ] && dns='2001:4860:4860::8888 2001:4860:4860::8844'
|
[ -z "${ip%%*:*}" ] && [ -n "${dns%%*:*}" ] && dns="$dns6"
|
||||||
[ -n "$dns" ] && echo "d-i netcfg/get_nameservers string $dns" | $save_preseed
|
[ -n "$dns" ] && echo "d-i netcfg/get_nameservers string $dns" | $save_preseed
|
||||||
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
|
||||||
@@ -762,6 +843,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -803,6 +885,9 @@ $save_preseed << 'EOF'
|
|||||||
tasksel tasksel/first multiselect ssh-server
|
tasksel tasksel/first multiselect ssh-server
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
install="$install ca-certificates libpam-systemd"
|
||||||
|
[ -n "$cidata" ] && install="$install cloud-init"
|
||||||
|
|
||||||
[ -n "$install" ] && echo "d-i pkgsel/include string $install" | $save_preseed
|
[ -n "$install" ] && echo "d-i pkgsel/include string $install" | $save_preseed
|
||||||
[ -n "$upgrade" ] && echo "d-i pkgsel/upgrade select $upgrade" | $save_preseed
|
[ -n "$upgrade" ] && echo "d-i pkgsel/upgrade select $upgrade" | $save_preseed
|
||||||
|
|
||||||
@@ -832,7 +917,22 @@ 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 "$late_command" ] && echo "d-i preseed/late_command string in-target sh -c '$late_command'" | $save_preseed
|
[ -n "$cidata" ] && {
|
||||||
|
in_target 'echo "datasource_list: [ NoCloud ]" > /etc/cloud/cloud.cfg.d/91_set_datasource.cfg'
|
||||||
|
in_target 'echo "" >> /etc/cloud/cloud.cfg.d/91_set_datasource.cfg'
|
||||||
|
in_target 'echo "datasource:" >> /etc/cloud/cloud.cfg.d/91_set_datasource.cfg'
|
||||||
|
in_target 'echo " ConfigDrive:" >> /etc/cloud/cloud.cfg.d/91_set_datasource.cfg'
|
||||||
|
in_target 'echo " dsmode: disabled" >> /etc/cloud/cloud.cfg.d/91_set_datasource.cfg'
|
||||||
|
in_target 'echo " NoCloud:" >> /etc/cloud/cloud.cfg.d/91_set_datasource.cfg'
|
||||||
|
in_target 'echo " fs_label: ~" >> /etc/cloud/cloud.cfg.d/91_set_datasource.cfg'
|
||||||
|
in_target 'echo " dsmode: local" >> /etc/cloud/cloud.cfg.d/91_set_datasource.cfg'
|
||||||
|
}
|
||||||
|
|
||||||
|
late_command='true'
|
||||||
|
[ -n "$in_target_script" ] && late_command="$late_command; in-target sh -c '$in_target_script'"
|
||||||
|
[ -n "$cidata" ] && late_command="$late_command; mkdir -p /target/var/lib/cloud/seed/nocloud; cp -r /cidata/. /target/var/lib/cloud/seed/nocloud/"
|
||||||
|
|
||||||
|
echo "d-i preseed/late_command string $late_command" | $save_preseed
|
||||||
|
|
||||||
[ "$power_off" = true ] && echo 'd-i debian-installer/exit/poweroff boolean true' | $save_preseed
|
[ "$power_off" = true ] && echo 'd-i debian-installer/exit/poweroff boolean true' | $save_preseed
|
||||||
|
|
||||||
@@ -850,6 +950,12 @@ save_grub_cfg='cat'
|
|||||||
gzip -d initrd.gz
|
gzip -d initrd.gz
|
||||||
# cpio reads a list of file names from the standard input
|
# cpio reads a list of file names from the standard input
|
||||||
echo preseed.cfg | cpio -o -H newc -A -F initrd
|
echo preseed.cfg | cpio -o -H newc -A -F initrd
|
||||||
|
|
||||||
|
if [ -n "$cidata" ]; then
|
||||||
|
cp -r "$cidata" cidata
|
||||||
|
find cidata | cpio -o -H newc -A -F initrd
|
||||||
|
fi
|
||||||
|
|
||||||
gzip -1 initrd
|
gzip -1 initrd
|
||||||
|
|
||||||
mkdir -p /etc/default/grub.d
|
mkdir -p /etc/default/grub.d
|
||||||
@@ -870,9 +976,19 @@ 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
|
||||||
|
tmp=$(mktemp)
|
||||||
|
grep -vF zz_debi /etc/default/grub > "$tmp"
|
||||||
|
cat "$tmp" > /etc/default/grub
|
||||||
|
rm "$tmp"
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
echo 'zz_debi=/etc/default/grub.d/zz-debi.cfg; if [ -f "$zz_debi" ]; then . "$zz_debi"; fi' >> /etc/default/grub
|
||||||
|
grub_cfg=/boot/grub/grub.cfg
|
||||||
|
grub-mkconfig -o "$grub_cfg"
|
||||||
else
|
else
|
||||||
err 'Could not find "update-grub" or "grub2-mkconfig" command'
|
err 'Could not find "update-grub" or "grub2-mkconfig" or "grub-mkconfig" command'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
save_grub_cfg="tee -a $grub_cfg"
|
save_grub_cfg="tee -a $grub_cfg"
|
||||||
|
|||||||
Reference in New Issue
Block a user