Debian Network Reinstall Script (debi)

repository·master·Indexed 23 days ago

https://github.com/bohanwood/debi

A tool to reinstall VPS or physical machines to a minimal Debian environment via network boot by injecting the installer into GRUB. It supports custom Debian versions, regional mirror presets, static network configuration, cloud-init integration, and remote installation via a network console. Compatible with KVM and physical hardware using GRUB 2, with specific configurations available for AWS and Google Cloud.

Tokens
3.7K
Snippets
3
Records
18
Agent score
81%

What's inside debi

  1. Platform Support and Requirements

    master

    The script works by injecting the Debian installer into GRUB.

    Supported Platforms:

    • KVM/Physical Machines: Fully supported.
    • Most VPS: Fully supported (e.g., DigitalOcean, Vultr, Linode).
    • Google Cloud: Requires manual network configuration using --ip and --gateway (DHCP is unreliable).
    • AWS EC2: Only supports BIOS mode; UEFI boot is not yet supported.

    Unsupported:

    • Containers: Not supported (requires GRUB bootloader).

    Environment Requirements:

    • KVM virtualization or physical hardware.
    • GRUB 2 bootloader.
    • Root privileges.
  2. How the Debian Network Reinstall Script works

    master

    The script automates the preparation of a Debian installation environment by performing the following steps:

    1. Downloads the Debian installer to the /boot/debian-$VERSION/ directory.
    2. Generates a preseed answer file based on your provided configuration.
    3. Modifies GRUB configuration by adding a new installer menu entry.
    4. Injects configuration files into the installer's initramfs.
    5. Updates GRUB to enable the new boot option.

    System Changes

    The script makes the following changes to your system:

    • Adds files to the /boot/debian-*/ directory.
    • Creates a GRUB configuration file at /etc/default/grub.d/zz-debi.cfg.
    • Updates the GRUB menu.

    Note: All changes are safe and reversible before you reboot. You can use the provided undo command to revert the system to its original state.

  3. Use Regional Presets for Mirrors and DNS

    master

    Instead of configuring mirrors and DNS manually, you can use regional presets to optimize download speeds and connectivity based on your location.

    PresetMirrorDNSNTPBest for
    Defaultdeb.debian.orgGoogle DNStime.google.comGlobal
    --cloudflaredeb.debian.orgCloudflaretime.cloudflare.comGlobal (privacy)
    --awscdn-aws.deb.debian.orgGoogle DNStime.aws.comAWS instances
    --aliyunmirrors.aliyun.comAliDNStime.amazonaws.cnChina
    --ustcmirrors.ustc.edu.cnDNSPodtime.amazonaws.cnChina
    --tunamirrors.tuna.tsinghua.edu.cnDNSPodtime.amazonaws.cnChina
  4. How debi.sh works

    master

    The script automates the Debian reinstallation process through the following lifecycle:

    1. Downloads Debian installer: Places it in /boot/debian-$VERSION/.
    2. Generates preseed file: Creates a configuration file based on your provided arguments.
    3. Modifies GRUB: Adds a new installer menu entry to the GRUB bootloader.
    4. Injects configuration: Injects settings into the installer's initramfs.
    5. Updates GRUB: Finalizes the boot options to reflect the new installer entry.

    System changes made by the script:

    • Files added to /boot/debian-*/.
    • A GRUB configuration file is added at /etc/default/grub.d/zz-debi.cfg.
    • The GRUB menu is updated.

    Note: These changes are reversible before rebooting using the provided revert commands.

  5. Use Network Console for Remote Installation

    master

    The --network-console option enables SSH access during the installation process. This is useful for remote servers where you cannot access a physical console.

    Usage Steps:

    1. Run the script with the --network-console flag and provide an SSH key URL via --authorized-keys-url.
    2. Reboot and wait 2-3 minutes for the Debian installer to load components.
    3. Connect via SSH: ssh installer@YOUR_IP.

    Console Navigation (Alt keys):

    • Alt+F1: Main installation interface
    • Alt+F2: Shell terminal
    • Alt+F3: Another shell terminal
    • Alt+F4: System logs (to monitor automation progress)
    • Use Alt+Left/Alt+Right to switch between views.

    Note: If using --authorized-keys-url, SSH password authentication is disabled. You must still set a user password for VNC console access and sudo commands.

  6. Quick Start: Install Debian via Network Reinstall

    master

    To reinstall your current system as a minimal Debian environment, download the script, make it executable, and run it with sudo.

    Default Behavior:

    • Installs Debian 13 (trixie).
    • Configures network via DHCP.
    • Creates a user named debian with sudo privileges (you will be prompted for a password).

    Steps:

    1. Download and prepare the script.
    2. Run the installation (choose between creating a debian user or using root).
    3. Reboot the system to trigger the network boot process.
  7. Quick Start: Install Debian via Network Boot

    master

    To reinstall your system as a minimal Debian environment using the network boot method, follow these steps:

    1. Download and prepare the script:

      curl -fLO https://raw.githubusercontent.com/bohanyang/debi/master/debi.sh
      chmod +x debi.sh
    2. Run the installation:

      • Basic installation: Creates a user named debian with sudo privileges. The script will prompt you for a password.
        sudo ./debi.sh
      • Install as root: If you prefer to use the root user instead of creating a new user.
        sudo ./debi.sh --user root
    3. Reboot:

      sudo reboot

    Default Settings: Debian 13 (trixie), DHCP networking, and a debian user with sudo access.

  8. Troubleshoot Installation Issues

    master

    Revert Changes

    If the script modifies your GRUB configuration and you need to restore the original state:

    sudo rm -rf /etc/default/grub.d/zz-debi.cfg /boot/debian-*
    sudo update-grub || sudo grub2-mkconfig -o /boot/grub2/grub.cfg

    Common Scenarios

    • Multiple Disks Detected: Use lsblk to find the disk name, then specify it with --disk. sudo ./debi.sh --disk /dev/sda
    • Low Memory VPS (<512MB): Force low memory mode. sudo ./debi.sh --force-lowmem 1
    • Network Configuration Failure: Use current system settings or manual config. sudo ./debi.sh --static-ipv4 or sudo ./debi.sh --ip YOUR_IP/CIDR --gateway YOUR_GATEWAY
    • Missing Hardware Firmware: Use the --firmware flag to install non-free firmware. sudo ./debi.sh --firmware
    • Debugging: Use --dry-run to generate configuration files without executing the installation.
  9. Troubleshoot debi.sh installation issues

    master

    If the installation fails or requires adjustment, use the following troubleshooting steps:

    Reverting changes

    If you haven't rebooted yet, you can undo all changes by deleting the generated GRUB config and boot files, then updating GRUB.

    Multiple disks detected

    If the script cannot identify the target disk, list disks with lsblk and specify the correct one using --disk.

    Low memory VPS

    For VPS instances with less than 512MB of RAM, use the --force-lowmem 1 flag.

    Network configuration failures

    If networking fails, you can attempt to use --static-ipv4 or manually define the IP and gateway.

    Missing firmware

    If your network card requires specific firmware, use the --firmware flag.

    Debugging

    To see what the script would do without making changes, use --dry-run to generate only the preseed file.

  10. Common usage examples for debi.sh

    master

    The debi.sh script can be configured for various cloud providers, regions, and installation requirements using CLI flags.

    Oracle Cloud (Ubuntu to Debian transition)

    Use --cloudflare and specify a user.

    Google Cloud Platform (GCP)

    GCP requires manual network configuration. Replace the IP and gateway with your VPC settings.

    Minimal Installation

    Use --no-install-recommends to keep the system lean, specify packages with --install, and skip upgrades with --no-upgrade.

    Deployment for China

    Use --ustc for mirrors, set the appropriate timezone, and configure local DNS.

    Installation via Network Console

    Enable remote access during installation by providing an authorized keys URL. After rebooting, connect via ssh installer@YOUR_IP.

    Static IP and Cloud-Init

    Configure static networking and provide a path to cloud-init data using --cidata.

  11. Integrate with Cloud-Init

    master

    You can pass custom cloud-init data to the installer using the --cidata option. This allows for automated configuration of hostnames, packages, and other metadata.

    Example Workflow:

    1. Create a directory containing meta-data and user-data files.
    2. Run the script pointing to that directory.
    # 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
    
    # Run installation with cloud-init data
    sudo ./debi.sh --cidata my-cloud-config
    # 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
  12. Advanced custom configuration with debi.sh

    master

    For full control over the installation, you can specify the Debian version, user, timezone, target disk, filesystem, kernel type, and additional packages.

    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'