# installimage e ZFS - Proxmox Hetzner

Detalhes de instalacao via installimage e configuracao ZFS.

---

## Template installimage

Template base para 2x NVMe 1TB + HDD 16TB:

```bash
DRIVE1 /dev/nvme0n1
DRIVE2 /dev/nvme1n1
SWRAID 0
SWRAIDLEVEL 0
BOOTLOADER grub
HOSTNAME HOSTNAME_PLACEHOLDER
PART /boot ext3 1024M
PART lvm vg0 all

LV vg0 root / ext4 50G
LV vg0 swap swap swap 16G
LV vg0 tmp /tmp ext4 10G
LV vg0 home /home ext4 20G

IMAGE /root/images/Debian-bookworm-latest-amd64-base.tar.gz
```

## Executar installimage

```bash
# No Rescue Mode
installimage

# Seleccionar Debian 12 (Bookworm)
# Copiar template acima
# Salvar e confirmar
# Reboot automatico
```

## Conversao para ZFS (Pos-Install)

**IMPORTANTE:** installimage nao suporta ZFS directamente. Workflow:
1. Instalar Debian 12 com LVM (installimage)
2. Boot em Debian
3. Instalar ZFS + Proxmox
4. Migrar para ZFS pool (ou aceitar LVM para root, ZFS para VMs)

### Opcao A: ZFS para VMs apenas (RECOMENDADO para Hetzner)

```bash
# Criar ZFS pool em NVMe para VMs
zpool create -f \
  -o ashift=12 \
  -o compression=lz4 \
  -o atime=off \
  rpool mirror /dev/nvme0n1p3 /dev/nvme1n1p3

# Criar datasets
zfs create rpool/vm-disks
zfs create rpool/ct-volumes
```

### Opcao B: ZFS root (AVANCADO - requer reinstall manual)

- Nao suportado por installimage
- Requer particionamento manual + debootstrap
- Consultar: https://pve.proxmox.com/wiki/ZFS_on_Linux

**Recomendacao para Cluster Descomplicar:** Opcao A (LVM root, ZFS para VMs)

---

## ZFS Tuning (128GB RAM)

### Configurar ARC Limits

```bash
# ARC max 16GB (deixa 110GB para VMs)
# ARC min 4GB
echo "options zfs zfs_arc_max=17179869184" >> /etc/modprobe.d/zfs.conf
echo "options zfs zfs_arc_min=4294967296" >> /etc/modprobe.d/zfs.conf

# Aplicar
update-initramfs -u -k all
```

### Optimizar ZFS para NVMe

```bash
# Verificar ashift (deve ser 12 para NVMe 4K sectors)
zdb -C rpool | grep ashift

# Activar compression LZ4 (se ainda nao)
zfs set compression=lz4 rpool

# Disable atime (performance)
zfs set atime=off rpool

# Snapshot visibility
zfs set snapdir=hidden rpool
```

### Criar ZFS Datasets para PBS (se HDD 16TB)

```bash
# Dataset para PBS datastore
zfs create rpool/pbs-datastore
zfs set mountpoint=/mnt/pbs-datastore rpool/pbs-datastore
zfs set compression=lz4 rpool/pbs-datastore
zfs set dedup=off rpool/pbs-datastore
```
