Introduction
PXE (prononcer "pixie") permet :
- Boot de machines via le reseau (NIC supporte PXE)
- Installation automatisee d'OS (Debian, Ubuntu, ESXi, etc.)
- Deploiement de masse sans intervention manuelle
- Re-install rapide en cas de panne
- Bootage en mode rescue / live system
Cas d'usage : datacenter VeryCloud avec 50 serveurs identiques a deployer, baies de provisioning, lab Proxmox.
Comment ca marche
Client PXE Switch PXE Server
| 1. DHCP DISCOVER (broadcast) | |
|------------------------------->| |
| | 2. DHCPOFFER + filename + |
| | next-server |
|<-------------------------------|----------------------------|
| 3. TFTP GET pxelinux.0 | |
|---------------------------------|--------------------------->|
| 4. Bootloader (pxelinux/grub) | |
| charge kernel + initrd | |
| 5. Kernel boote, monte NFS | |
| ou HTTP pour preseed | |
Prerequis
- VPS Linux Debian 12 / Ubuntu 24.04 (le PXE server)
- 2 IPs sur le meme LAN que les clients (ou meme reseau)
- Acces root
- Pas de DHCP server existant sur le LAN, OU possibilite de configurer le DHCP existant
Etape 1 : Installer dnsmasq + tftpd
sudo apt update
sudo apt install -y dnsmasq tftpd-hpa pxelinux syslinux-common nginx
Etape 2 : Configurer dnsmasq (DHCP + DNS + TFTP)
/etc/dnsmasq.d/pxe.conf :
interface=eth0
bind-interfaces
# DHCP
dhcp-range=192.168.1.100,192.168.1.200,12h
dhcp-option=3,192.168.1.1 # gateway
dhcp-option=6,1.1.1.1,8.8.8.8 # DNS
# PXE
enable-tftp
tftp-root=/srv/tftp
dhcp-boot=pxelinux.0
# pour UEFI clients
dhcp-match=set:bios,option:client-arch,0
dhcp-match=set:efi64,option:client-arch,7
dhcp-boot=tag:bios,pxelinux.0
dhcp-boot=tag:efi64,grubx64.efi
log-dhcp
⚠️ Adaptez interface=eth0, plage IP et gateway a votre LAN.
sudo systemctl restart dnsmasq
sudo systemctl status dnsmasq
Etape 3 : Telecharger pxelinux et bootloaders
sudo mkdir -p /srv/tftp/pxelinux.cfg
sudo cp /usr/lib/PXELINUX/pxelinux.0 /srv/tftp/
sudo cp /usr/lib/syslinux/modules/bios/ldlinux.c32 /srv/tftp/
sudo cp /usr/lib/syslinux/modules/bios/menu.c32 /srv/tftp/
sudo cp /usr/lib/syslinux/modules/bios/libutil.c32 /srv/tftp/
sudo cp /usr/lib/syslinux/modules/bios/vesamenu.c32 /srv/tftp/
sudo cp /usr/lib/syslinux/modules/bios/libcom32.c32 /srv/tftp/
Pour UEFI :
sudo apt install -y grub-efi-amd64-signed shim-signed
sudo cp /usr/lib/grub/x86_64-efi-signed/grubx64.efi /srv/tftp/
Etape 4 : Menu PXE
/srv/tftp/pxelinux.cfg/default :
DEFAULT vesamenu.c32
PROMPT 0
MENU TITLE VeryCloud PXE Boot Menu
TIMEOUT 100
LABEL local
MENU LABEL Boot from local disk
LOCALBOOT 0
LABEL debian12
MENU LABEL Install Debian 12 (auto)
KERNEL debian-installer/amd64/linux
APPEND vga=788 initrd=debian-installer/amd64/initrd.gz auto=true priority=critical preseed/url=http://192.168.1.5/preseed.cfg ---
LABEL ubuntu24
MENU LABEL Install Ubuntu 24.04 (auto)
KERNEL ubuntu/casper/vmlinuz
APPEND initrd=ubuntu/casper/initrd autoinstall ds=nocloud-net\;s=http://192.168.1.5/autoinstall/ ---
LABEL rescue
MENU LABEL Rescue / live system
KERNEL debian-installer/amd64/linux
APPEND initrd=debian-installer/amd64/initrd.gz rescue/enable=true
Etape 5 : Telecharger les netboot images
Debian 12
sudo mkdir -p /srv/tftp/debian-installer/amd64
cd /srv/tftp/debian-installer/amd64
sudo wget http://ftp.debian.org/debian/dists/bookworm/main/installer-amd64/current/images/netboot/debian-installer/amd64/linux
sudo wget http://ftp.debian.org/debian/dists/bookworm/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz
Ubuntu 24.04
sudo mkdir -p /srv/tftp/ubuntu/casper
cd /tmp
sudo wget https://releases.ubuntu.com/24.04/ubuntu-24.04-live-server-amd64.iso
sudo mount -o loop ubuntu-24.04-live-server-amd64.iso /mnt
sudo cp /mnt/casper/vmlinuz /srv/tftp/ubuntu/casper/
sudo cp /mnt/casper/initrd /srv/tftp/ubuntu/casper/
sudo umount /mnt
Etape 6 : Serveur HTTP pour preseed
Nginx pour servir les fichiers preseed et autoinstall :
/etc/nginx/sites-available/pxe :
server {
listen 80;
server_name 192.168.1.5;
root /srv/www;
location / {
autoindex on;
}
}
sudo mkdir -p /srv/www
sudo ln -s /etc/nginx/sites-available/pxe /etc/nginx/sites-enabled/
sudo systemctl restart nginx
Etape 7 : Preseed Debian
/srv/www/preseed.cfg :
# Locale
d-i debian-installer/locale string fr_FR.UTF-8
d-i keyboard-configuration/xkb-keymap select fr
# Network
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string serveur
# Mirror
d-i mirror/country string France
d-i mirror/http/hostname string ftp.fr.debian.org
d-i mirror/http/directory string /debian
# User
d-i passwd/root-login boolean true
d-i passwd/root-password-crypted password $6$rounds=4096$xxxx...
d-i passwd/user-fullname string Admin
d-i passwd/username string admin
d-i passwd/user-password-crypted password $6$rounds=4096$yyyy...
# Clock
d-i clock-setup/utc boolean true
d-i time/zone string Europe/Paris
d-i clock-setup/ntp boolean true
# Partitioning
d-i partman-auto/method string regular
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
# Base
tasksel tasksel/first multiselect ssh-server
d-i pkgsel/include string openssh-server sudo curl
# Grub
d-i grub-installer/bootdev string default
d-i grub-installer/only_debian boolean true
# Reboot
d-i finish-install/reboot_in_progress note
# Custom post-install
d-i preseed/late_command string \
in-target wget -O /root/post.sh http://192.168.1.5/post.sh; \
in-target chmod +x /root/post.sh; \
in-target /root/post.sh
Generez les hashs de mdp :
mkpasswd -m sha-512
Etape 8 : Post-install script
/srv/www/post.sh :
#!/bin/bash
# Add SSH key
mkdir -p /root/.ssh
echo "ssh-ed25519 AAAA... admin@verycloud" > /root/.ssh/authorized_keys
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
# Update + install
apt-get update
apt-get install -y htop curl vim git fail2ban
# Disable password auth
sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart ssh
# Hostname
echo "$(cat /etc/hostname)" > /etc/hostname
Etape 9 : Ubuntu autoinstall (cloud-init)
Pour Ubuntu 24.04 :
sudo mkdir -p /srv/www/autoinstall
sudo touch /srv/www/autoinstall/meta-data
/srv/www/autoinstall/user-data :
#cloud-config
autoinstall:
version: 1
locale: fr_FR.UTF-8
keyboard:
layout: fr
identity:
hostname: serveur
username: admin
password: "$6$rounds=4096$xxxx..."
ssh:
install-server: true
authorized-keys:
- "ssh-ed25519 AAAA... admin@verycloud"
storage:
layout:
name: lvm
packages:
- htop
- curl
- vim
- git
late-commands:
- curtin in-target -- systemctl enable ssh
Etape 10 : Booter une machine en PXE
Sur le client :
- Entrez dans le BIOS / UEFI
- Activez "Network Boot" / "PXE Boot"
- Mettez le LAN en premier dans l'ordre de boot
- Sauvegardez et redemarrez
La machine doit :
- Faire un DHCP DISCOVER
- Recevoir DHCPOFFER avec next-server (votre PXE)
- Telecharger pxelinux.0 via TFTP
- Afficher le menu PXE
- Lancer l'install auto
Etape 11 : Logs et debug
sudo tail -f /var/log/syslog | grep dnsmasq
sudo journalctl -u dnsmasq -f
sudo journalctl -u tftpd-hpa -f
Si TFTP echoue, testez :
tftp 192.168.1.5
> get pxelinux.0
> quit
Etape 12 : Foreman / Cobbler (allerent plus loin)
Pour des deploiements complexes, utilisez un outil orchestre :
- Cobbler : tuto separe, voir le tuto Cobbler
- Foreman : full stack provisioning + reporting
- MAAS (Canonical) : "Metal as a Service", pour deployer du bare metal
Depannage
Client ne recoit pas de DHCP
Verifiez :
dnsmasqecoute sur la bonne interface- Pas de firewall (port 67/UDP, 69/UDP)
- Le client est sur le bon VLAN
- Pas de DHCP server concurrent
sudo tcpdump -i eth0 -n port 67 or port 68
TFTP "File not found"
Verifiez que le fichier existe vraiment :
sudo ls -la /srv/tftp/
Permissions :
sudo chmod -R 755 /srv/tftp/
sudo chown -R tftp:tftp /srv/tftp/
Boot tres lent
TFTP est tres lent (UDP + petits paquets). Pour acceler, utilisez iPXE qui charge ensuite via HTTP :
/srv/tftp/ipxe.efi est plus moderne que pxelinux. Voir https://ipxe.org
Preseed echoue silencieusement
Sur le client, pressez Esc puis e au boot du menu pour editer la ligne kernel. Ajoutez debconf/priority=low pour voir les erreurs.
Commandes utiles
# Services
sudo systemctl status dnsmasq
sudo systemctl status tftpd-hpa
sudo systemctl status nginx
# Logs DHCP
sudo journalctl -u dnsmasq -f
# Tester TFTP
tftp 192.168.1.5 -c get pxelinux.0
# Verifier le menu
ls -la /srv/tftp/
cat /srv/tftp/pxelinux.cfg/default
# Boot UEFI iPXE (plus moderne)
sudo apt install -y ipxe
Conclusion
PXE Boot permet le deploiement rapide et automatise :
- Pas de support physique necessaire
- Reproductible (preseed / autoinstall)
- Indispensable en datacenter
Limites :
- Necessite controle du LAN (DHCP)
- TFTP est lent (utilisez iPXE + HTTP)
- Configuration initiale technique
Pour aller plus loin :
- iPXE pour booter via HTTP (10x plus rapide)
- Cobbler pour orchestrer multiple distros
- Foreman / MAAS pour le full provisioning
Ressources
- Documentation PXELINUX : https://wiki.syslinux.org/wiki/index.php?title=PXELINUX
- Debian preseed : https://www.debian.org/releases/stable/amd64/apb.fr.html
- Ubuntu autoinstall : https://ubuntu.com/server/docs/install/autoinstall
- iPXE : https://ipxe.org


















