proc:bare_metal_server_provisioning
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| proc:bare_metal_server_provisioning [2026/05/16 20:40] – [17. First boot and unlock] phil | proc:bare_metal_server_provisioning [2026/07/23 15:10] (current) – [18. (EXTRA) hugepage & swap configuration] phil | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| * RAID1 on two NVMe disks | * RAID1 on two NVMe disks | ||
| * LVM on LUKS | * LVM on LUKS | ||
| - | * Boot UEFI with ESP on both disks | + | * Boot UEFI **or** legacy/BIOS (auto-detected) |
| * Remote cryptroot unlock with '' | * Remote cryptroot unlock with '' | ||
| Line 17: | Line 17: | ||
| < | < | ||
| nvme0n1 (419 Go) nvme1n1 (419 Go) | nvme0n1 (419 Go) nvme1n1 (419 Go) | ||
| - | ├── p1 : 512 Mo ESP ├── p1 : 512 Mo ESP (copy) | + | ├── p1 : see note below ├── p1 : see note below |
| ├── p2 : 512 Mo ────┐ | ├── p2 : 512 Mo ────┐ | ||
| │ | │ | ||
| Line 24: | Line 24: | ||
| | | ||
| | | ||
| + | |||
| + | p1 depends on boot mode: | ||
| + | * UEFI : 512 Mo ESP (ef00, vfat, mounted /boot/efi), one per disk | ||
| + | * legacy : 1 Mo BIOS boot partition (ef02, raw), one per disk | ||
| </ | </ | ||
| Line 31: | Line 35: | ||
| ==== 1. Boot in rescue mode ==== | ==== 1. Boot in rescue mode ==== | ||
| + | |||
| + | Detect the rescue boot mode once, everything downstream branches on $MODE. | ||
| + | The mode is imposed by the rescue boot (Hetzner PXE), not locally adjustable. | ||
| + | |||
| + | <code bash> | ||
| + | $ if [ -d / | ||
| + | $ echo "Boot mode: $MODE" | ||
| + | </ | ||
| ==== 2. Disk setup ==== | ==== 2. Disk setup ==== | ||
| Line 49: | Line 61: | ||
| # GPT partitioning on both disks | # GPT partitioning on both disks | ||
| + | # p1 differs by mode: | ||
| + | # | ||
| + | # | ||
| $ for D in / | $ for D in / | ||
| - | sgdisk -n 1:0:+512M -t 1:ef00 -c 1:" | + | |
| + | | ||
| + | else | ||
| + | sgdisk -n 1: | ||
| + | fi | ||
| sgdisk -n 2:0:+512M -t 2:fd00 -c 2:" | sgdisk -n 2:0:+512M -t 2:fd00 -c 2:" | ||
| sgdisk -n 3:0:0 -t 3:fd00 -c 3:" | sgdisk -n 3:0:0 -t 3:fd00 -c 3:" | ||
| Line 98: | Line 117: | ||
| <code bash> | <code bash> | ||
| - | $ mkfs.vfat -F32 -n EFI0 / | + | # ESP only in UEFI mode; in legacy p1 is a raw BIOS boot partition (no fs) |
| - | $ mkfs.vfat -F32 -n EFI1 / | + | $ if [ " |
| + | | ||
| + | mkfs.vfat -F32 -n EFI1 / | ||
| + | fi | ||
| $ mkfs.ext4 -L boot /dev/md0 | $ mkfs.ext4 -L boot /dev/md0 | ||
| $ mkfs.ext4 -L root / | $ mkfs.ext4 -L root / | ||
| Line 106: | Line 128: | ||
| $ mkdir -p /mnt/boot | $ mkdir -p /mnt/boot | ||
| $ mount /dev/md0 /mnt/boot | $ mount /dev/md0 /mnt/boot | ||
| - | $ mkdir -p / | + | $ if [ " |
| - | $ mount / | + | |
| + | mount / | ||
| + | fi | ||
| </ | </ | ||
| Line 124: | Line 148: | ||
| mount --bind /$d /mnt/$d | mount --bind /$d /mnt/$d | ||
| done | done | ||
| - | $ mount --bind / | + | # efivars only exists (and is only needed) in UEFI mode |
| + | $ if [ "$MODE" = uefi ]; then | ||
| + | | ||
| + | fi | ||
| $ cp / | $ cp / | ||
| Line 131: | Line 158: | ||
| $ blkid -s UUID -o value / | $ blkid -s UUID -o value / | ||
| $ blkid -s UUID -o value / | $ blkid -s UUID -o value / | ||
| - | $ blkid -s UUID -o value / | + | # EFI UUIDs only relevant in UEFI mode: |
| - | $ blkid -s UUID -o value / | + | $ if [ " |
| + | | ||
| + | blkid -s UUID -o value / | ||
| + | fi | ||
| $ chroot /mnt /bin/bash | $ chroot /mnt /bin/bash | ||
| Line 139: | Line 169: | ||
| ==== 9. Base configuration (in chroot) ==== | ==== 9. Base configuration (in chroot) ==== | ||
| + | |||
| + | Re-evaluate the mode inside the chroot (the rescue variable is not inherited). | ||
| + | / | ||
| + | rescue, so the detection stays consistent with section 1. | ||
| + | |||
| + | <code bash> | ||
| + | $ if [ -d / | ||
| + | </ | ||
| <code bash> | <code bash> | ||
| # Hostname | # Hostname | ||
| $ echo " | $ echo " | ||
| - | $ cat > /etc/hosts << | + | $ sed -i " |
| - | 127.0.0.1 localhost | + | |
| - | 127.0.1.1 | + | |
| - | ::1 | + | |
| - | ff02:: | + | |
| - | ff02:: | + | |
| - | EOF | + | |
| - | |||
| # Locales / timezone | # Locales / timezone | ||
| $ apt update && apt install -y locales | $ apt update && apt install -y locales | ||
| Line 199: | Line 230: | ||
| UUID=$ROOT_UUID | UUID=$ROOT_UUID | ||
| UUID=$BOOT_UUID | UUID=$BOOT_UUID | ||
| - | UUID=$EFI0_UUID | ||
| EOF | EOF | ||
| + | # ESP entry only in UEFI mode | ||
| + | $ if [ " | ||
| + | echo " | ||
| + | fi | ||
| # mdadm.conf | # mdadm.conf | ||
| Line 226: | Line 260: | ||
| </ | </ | ||
| - | ==== 13. GRUB UEFI ==== | + | ==== 13. GRUB (UEFI or legacy) |
| <code bash> | <code bash> | ||
| - | $ apt install -y grub-efi-amd64 efibootmgr | ||
| - | |||
| $ echo ' | $ echo ' | ||
| - | $ grub-install --target=x86_64-efi \ | + | $ if [ " |
| - | | + | ## --- UEFI --- |
| - | | + | apt install -y grub-efi-amd64 efibootmgr |
| - | | + | |
| - | + | | |
| - | $ update-grub | + | |
| - | + | | |
| - | # Sync ESP2 | + | |
| - | $ mkdir -p /tmp/efi2 | + | update-grub |
| - | $ mount / | + | |
| - | $ cp -av /boot/efi/* / | + | # Sync ESP2 |
| - | $ umount /tmp/efi2 | + | mkdir -p /tmp/efi2 |
| - | + | mount / | |
| - | # UEFI fallback for ESP2 | + | cp -av /boot/efi/* / |
| - | $ efibootmgr --create \ | + | umount /tmp/efi2 |
| - | --disk / | + | |
| - | --label " | + | # UEFI fallback for ESP2 |
| - | --loader ' | + | efibootmgr --create \ |
| - | + | --disk / | |
| - | # Reorder to make debian (ESP1) as priority | + | --label " |
| - | $ efibootmgr -o 000A,000B,0003, | + | --loader ' |
| - | # (adapt IDs from `efibootmgr`) | + | |
| + | # Reorder to make debian (ESP1) as priority | ||
| + | # | ||
| + | |||
| + | else | ||
| + | ## --- legacy/BIOS --- | ||
| + | apt install -y grub-pc | ||
| + | |||
| + | # Install GRUB core into the BIOS boot partition (ef02) of BOTH disks | ||
| + | # for redundancy: if nvme0 fails, the machine still boots on nvme1. | ||
| + | grub-install --target=i386-pc --recheck / | ||
| + | grub-install --target=i386-pc --recheck / | ||
| + | update-grub | ||
| + | fi | ||
| </ | </ | ||
| Line 293: | Line 338: | ||
| $ apt install -y dropbear-initramfs busybox | $ apt install -y dropbear-initramfs busybox | ||
| - | # Config dropbear : port 2222 and force cryptroot-unlock command | + | # Config dropbear : port 4222 and force cryptroot-unlock command |
| $ cat > / | $ cat > / | ||
| - | DROPBEAR_OPTIONS=" | + | DROPBEAR_OPTIONS=" |
| EOF | EOF | ||
| Line 318: | Line 363: | ||
| $ exit # exit chroot | $ exit # exit chroot | ||
| - | $ umount / | + | # $MODE from section 1 is still set in the rescue shell here |
| - | $ umount / | + | $ if [ " |
| + | | ||
| + | umount / | ||
| + | fi | ||
| $ umount /mnt/boot | $ umount /mnt/boot | ||
| $ umount /mnt/run | $ umount /mnt/run | ||
| Line 340: | Line 388: | ||
| <code bash> | <code bash> | ||
| # Wait dropbear to be up | # Wait dropbear to be up | ||
| - | nc -zv xx.xx.xx.xx | + | nc -zv xx.xx.xx.xx |
| # remote unlocking oneliner: | # remote unlocking oneliner: | ||
| - | pass show luks/ | + | pass show luks/ |
| </ | </ | ||
| After few seconds, normal SSD become available. | After few seconds, normal SSD become available. | ||
| + | |||
| + | ==== 18. (EXTRA) hugepage & swap & LVM thin configuration ==== | ||
| + | |||
| + | <code bash> | ||
| + | sudo lvcreate -L 4G -n swap vg0 | ||
| + | sudo mkswap / | ||
| + | sudo swapon / | ||
| + | echo "/ | ||
| + | </ | ||
| + | |||
| + | If you want to configure hugepage for a qemu hypervisor: | ||
| + | |||
| + | <code bash> | ||
| + | sudo tee / | ||
| + | vm.nr_hugepages = 13312 # EXAMPLE FOR 26GB/32GB | ||
| + | EOF | ||
| + | </ | ||
| + | |||
| + | LVM Thin initialization to store VM storage | ||
| + | |||
| + | <code bash> | ||
| + | sudo lvcreate --type thin-pool -L 250G -n thin vg0 | ||
| + | </ | ||
proc/bare_metal_server_provisioning.1778964048.txt.gz · Last modified: by phil
