- Add apps: create (scaffold host from template), deploy (multi-host deployment with -n filter), install (NixOS installation from live ISO) - Register all apps in flake.nix (create, deploy, install, rebuild) - Add deploy.json config (cryodev-main, SSH port 2299) - Fix generic-server template: was using Pi hardware/boot config, now correct x86_64 with systemd-boot, UEFI, ROOT/BOOT/SWAP labels - Fix template networking.nix: use HOSTNAME placeholder instead of hardcoded cryodev-pi (both templates) - Fix headplane upstream pnpm-deps hash mismatch via overlay - Fix all docs: replace root@ with user@, --ssh-option with NIX_SSHOPTS, add deploy app references, update first-install guide to use create app and document service deactivation steps
184 lines
4.3 KiB
Markdown
184 lines
4.3 KiB
Markdown
# Neuinstallation (Reinstall)
|
|
|
|
Diese Anleitung beschreibt die **Neuinstallation** eines bestehenden Hosts, z.B. nach Hardwarewechsel oder bei Problemen.
|
|
|
|
## Unterschied zur Erstinstallation
|
|
|
|
| Aspekt | Erstinstallation | Neuinstallation |
|
|
|--------|------------------|-----------------|
|
|
| SOPS-Secrets | Noch nicht vorhanden | Bereits konfiguriert |
|
|
| SSH-Host-Key | Neu generiert | **Muss wiederhergestellt werden!** |
|
|
| Disk-IDs | Neu ermitteln | Oft geändert (neue Hardware) |
|
|
| secrets.yaml | Wird erstellt | Bereits vorhanden |
|
|
|
|
## Wichtig: SSH-Host-Key Problem
|
|
|
|
Bei einer Neuinstallation wird ein **neuer SSH-Host-Key** generiert. Dieser stimmt nicht mehr mit dem Age-Key in `.sops.yaml` überein!
|
|
|
|
### Lösungsmöglichkeiten
|
|
|
|
**Option A: Alten Host-Key sichern und wiederherstellen** (empfohlen)
|
|
|
|
**Option B: Neuen Key generieren und SOPS aktualisieren**
|
|
|
|
## Voraussetzungen
|
|
|
|
- Backup des alten SSH-Host-Keys (falls Option A)
|
|
- Zugriff auf `.sops.yaml` und die Admin-Age-Keys
|
|
- Bootbares NixOS ISO
|
|
|
|
## Schritt 1: Vorbereitung (vor der Installation)
|
|
|
|
### 1.1 Alten SSH-Host-Key sichern (Option A)
|
|
|
|
Falls der alte Host noch läuft:
|
|
|
|
```bash
|
|
# Auf dem alten Host
|
|
sudo cat /etc/ssh/ssh_host_ed25519_key > ~/ssh_host_ed25519_key.backup
|
|
sudo cat /etc/ssh/ssh_host_ed25519_key.pub > ~/ssh_host_ed25519_key.pub.backup
|
|
```
|
|
|
|
Dateien sicher auf den Entwicklungsrechner kopieren.
|
|
|
|
### 1.2 Disk-IDs ermitteln
|
|
|
|
**Bei neuer Hardware** ändern sich die Disk-IDs!
|
|
|
|
```bash
|
|
# Im NixOS Live-System
|
|
lsblk -o NAME,SIZE,MODEL,SERIAL
|
|
ls -la /dev/disk/by-id/
|
|
```
|
|
|
|
Die neue Disk-ID in `hosts/<hostname>/disks.sh` oder `disks.nix` eintragen:
|
|
|
|
```bash
|
|
# Beispiel disks.sh
|
|
DISK="/dev/disk/by-id/nvme-Samsung_SSD_970_EVO_Plus_XXXXX"
|
|
```
|
|
|
|
## Schritt 2: Installation durchführen
|
|
|
|
### 2.1 NixOS ISO booten
|
|
|
|
Von USB/CD booten, Root-Passwort setzen, per SSH verbinden.
|
|
|
|
### 2.2 Repository klonen
|
|
|
|
```bash
|
|
sudo -i
|
|
nix-shell -p git
|
|
git clone <GIT_REPO_URL> /tmp/nixos
|
|
cd /tmp/nixos
|
|
```
|
|
|
|
### 2.3 Disk-Konfiguration prüfen
|
|
|
|
```bash
|
|
# Aktuelle Disk-IDs anzeigen
|
|
ls -la /dev/disk/by-id/
|
|
|
|
# Mit Konfiguration vergleichen
|
|
cat hosts/<hostname>/disks.sh | grep DISK
|
|
```
|
|
|
|
**Falls nötig:** Disk-ID in der Konfiguration anpassen.
|
|
|
|
### 2.4 Install-Script ausführen
|
|
|
|
```bash
|
|
bash scripts/install.sh -n <hostname>
|
|
```
|
|
|
|
### 2.5 SSH-Host-Key wiederherstellen (Option A)
|
|
|
|
**Vor dem Reboot!**
|
|
|
|
```bash
|
|
# Host-Key vom Backup wiederherstellen
|
|
cp /path/to/ssh_host_ed25519_key.backup /mnt/etc/ssh/ssh_host_ed25519_key
|
|
cp /path/to/ssh_host_ed25519_key.pub.backup /mnt/etc/ssh/ssh_host_ed25519_key.pub
|
|
chmod 600 /mnt/etc/ssh/ssh_host_ed25519_key
|
|
chmod 644 /mnt/etc/ssh/ssh_host_ed25519_key.pub
|
|
```
|
|
|
|
### 2.6 Reboot
|
|
|
|
```bash
|
|
umount -Rl /mnt
|
|
reboot
|
|
```
|
|
|
|
## Schritt 3: Nach dem Reboot
|
|
|
|
### Bei Option A (Key wiederhergestellt)
|
|
|
|
SOPS-Secrets sollten automatisch funktionieren. Testen:
|
|
|
|
```bash
|
|
sudo cat /run/secrets/tailscale/auth-key
|
|
```
|
|
|
|
### Bei Option B (Neuer Key)
|
|
|
|
Der Host kann die Secrets nicht entschlüsseln. Neuen Key konfigurieren:
|
|
|
|
```bash
|
|
# Neuen Age-Key ermitteln
|
|
nix-shell -p ssh-to-age --run 'cat /etc/ssh/ssh_host_ed25519_key.pub | ssh-to-age'
|
|
```
|
|
|
|
Auf dem Entwicklungsrechner:
|
|
|
|
```bash
|
|
# .sops.yaml aktualisieren mit neuem Key
|
|
vim .sops.yaml
|
|
|
|
# Secrets mit neuem Key neu verschlüsseln
|
|
sops updatekeys hosts/<hostname>/secrets.yaml
|
|
```
|
|
|
|
Dann Konfiguration neu deployen:
|
|
|
|
```bash
|
|
NIX_SSHOPTS="-p 2299" nixos-rebuild switch --flake .#<hostname> \
|
|
--target-host <user>@<IP> --use-remote-sudo
|
|
```
|
|
|
|
## Häufige Probleme
|
|
|
|
### "No secret key available"
|
|
|
|
SOPS kann die Secrets nicht entschlüsseln. Ursache:
|
|
- SSH-Host-Key stimmt nicht mit Age-Key in `.sops.yaml` überein
|
|
|
|
Lösung: Option B durchführen (neuen Key konfigurieren).
|
|
|
|
### "Device not found" beim Partitionieren
|
|
|
|
Disk-ID in `disks.sh`/`disks.nix` ist falsch.
|
|
|
|
```bash
|
|
# Richtige ID finden
|
|
ls -la /dev/disk/by-id/
|
|
```
|
|
|
|
### Hardware-Config veraltet
|
|
|
|
Bei neuer Hardware muss `hardware.nix` neu generiert werden:
|
|
|
|
```bash
|
|
# Install-Script generiert automatisch neu, falls Datei fehlt
|
|
rm hosts/<hostname>/hardware.nix
|
|
bash scripts/install.sh -n <hostname>
|
|
```
|
|
|
|
## Checkliste
|
|
|
|
- [ ] Alten SSH-Host-Key gesichert (falls möglich)
|
|
- [ ] Disk-IDs in Konfiguration geprüft/aktualisiert
|
|
- [ ] Installation durchgeführt
|
|
- [ ] SSH-Host-Key wiederhergestellt ODER neuen Key in SOPS konfiguriert
|
|
- [ ] Secrets funktionieren (`sudo cat /run/secrets/...`)
|
|
- [ ] Tailscale verbunden (`tailscale status`)
|