Serveur PXE virtuel et client PXE virtuels

 

Dans le but de mettre en place un labo de test avec un serveur et des clients diskless, j'avais besoins de tester mon installation simplement sans installer plusieurs machines (au moins deux, une pour le serveur et une pour le client diskless). J'ai donc essayé de voir si je pouvais créer un serveur PXE virtuel et un client diskless virtuel qui booterait sur ce serveur.

Tout ceci se fait sur un serveur Debian Lenny 64bits, avec un hyperviseur Xen 3.2. J'ai aussi une carte PCI multiport réseau, mais cela peut très bien se faire aussi avec des interfaces réseau virtuelles (dummy0). Cette méthode marche très bien aussi avec des machines virtualbox avec le serveur PXE diffusant sur un réseau interne.

Serveur PXE virtuel

Le serveur aura deux interfaces, une première connectée vers le net, une seconde pour le réseau des postes diskless. Voici le fichier de configuration de mon serveur virtuel :

kernel      = '/boot/vmlinuz-2.6.26-1-xen-686'
ramdisk     = '/boot/initrd.img-2.6.26-1-xen-686'
memory      = '1024'
root        = '/dev/xvda2 ro'
disk        = [ 'phy:/dev/xen_disk/srvpxe-disk,xvda2,w',
                   'phy:/dev/xen_disk/srvpxe-swap,xvda1,w', ]
name        = 'srvpxe'
vif         = [ 'mac=00:16:3E:6C:14:B7,bridge=eth2',
                  'mac=00:16:3E:6C:14:B8,bridge=eth5' ]
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

Serveur dhcp

# apt-get install dhcp3-server

On va faire diffuser le serveur dhcp sur l'interface eth1 :

# vi /etc/default/dhcp3-server
INTERFACES="eth1"

Et on configure notre serveur dhcp :

 authoritative;
 ddns-update-style interim;
 ignore client-updates;

 subnet 192.168.5.0 netmask 255.255.255.0 {
   range 192.168.5.100 192.168.5.200;
   option domain-name-servers 192.168.5.1;
   option domain-name "reseau.local";
   option routers 192.168.5.1;
   option subnet-mask 255.255.255.0;
   option broadcast-address 192.168.5.255;
   default-lease-time 43200;
   max-lease-time 86400;

   server-name "server-pxe";
   next-server 192.168.5.1;
   filename "/tftpboot/pxe/pxelinux.0";
 }

Et on le re-démarre :

# /etc/init.d/dhcp3-server restart

Serveur TFTP

Voir cet article Wikipedia pour des explications sur le TFTP : http://fr.wikipedia.org/wiki/Trivial_File_Transfer_Protocol

On va utiliser atftp :

# apt-get install atftpd

On veut que notre serveur tftp démarre en tant que demon et non pas avec inetd (configuration par défaut). Il faut que le fichier /etc/default/atftp ressemble à ceci :

USE_INETD=false
OPTIONS="--daemon --tftpd-timeout 300 --retry-timeout 5 --mcast-port 1758 
--mcast-addr 239.239.239.0-255 --mcast-ttl 1 --maxthread 100 --verbose=5 /tftpboot"

Et commenter la ligne tftp dans le fichier /etc/inetd.conf. On peut redémarrer le serveur tftp :

# /etc/init.d/atftpd restart

Serveur PXE

# apt-get install pxe syslinux

Si besoins modifier le fichier /etc/pxe.conf mais personnellement j'ai pas eu besoins d'y toucher.

Netboot Debian

Dans un premier temps notre serveur PXE va servir de netboot pour les postes qui n'auraient pas de lecteur CD ou pour les machines virtuelles sans utiliser de fichiers iso. On va donc télécharger les netboot Debian Lenny i386 et amd64.

# cd /tmp
# wget http://ftp.fr.debian.org/debian/dists/lenny/main/installer-i386/current
/images/netboot/netboot.tar.gz -O /tmp/netboot-debian-lenny-i386.tar.gz
# wget http://ftp.fr.debian.org/debian/dists/lenny/main/installer-amd64/current
/images/netboot/netboot.tar.gz -O /tmp/netboot-debian-lenny-amd64.tar.gz

On décompresse tout cela :

# tar zxvf /tmp/netboot-debian-lenny-i386.tar.gz
# tar zxvf /tmp/netboot-debian-lenny-amd64.tar.gz

On crée l'arborescence de notre serveur tftp :

# mkdir -p /tftpboot/pxe/{boot-screens,pxelinux.cfg,debian-lenny/{i386,amd64}}

Copie des fichiers :

# cp /tmp/pxelinux.0 /tftpboot/pxe/
# cp /tmp/debian-installer/i386/boot-screens/splash.png /tftpboot/pxe
/boot-screens/
# cp /tmp/debian-installer/i386/boot-screens/vesamenu.c32 /tftpboot/pxe
/boot-screens/
# cp /tmp/debian-installer/i386/initrd.gz /tftpboot/pxe/debian-lenny/i386/
# cp /tmp/debian-installer/i386/linux /tftpboot/pxe/debian-lenny/i386/
# cp /tmp/debian-installer/amd64/initrd.gz /tftpboot/pxe/debian-lenny/amd64/
# cp /tmp/debian-installer/amd64/linux /tftpboot/pxe/debian-lenny/amd64/

Création du fichier /tftpboot/pxe/pxelinux.cfg/default

include /boot-screens/menu.cfg
default /boot-screens/vesamenu.c32
prompt 0
timeout 0

Création du fichier /tftpboot/pxe/boot-screens/menu.cfg

menu hshift 13
menu width 49
menu title Guidtz Installer boot menu
menu background boot-screens/splash.png
menu color title        * #FFFFFFFF *
menu color border       * #00000000 #00000000 none
menu color sel          * #ffffffff #76a1d0ff *
menu color hotsel       1;7;37;40 #ffffffff #76a1d0ff *
menu color tabmsg       * #ffffffff #00000000 *
menu vshift 12
menu rows 10
menu tabmsgrow 16
menu timeoutrow 17
menu tabmsg Press ENTER to boot or TAB to edit a menu entry
menu autoboot Starting Local System in # seconds
prompt 0
label bootlocal
 menu label ^Boot from local disk
 menu default
 localboot 0
timeout 200
 totaltimeout 1200
menu begin debian
 menu title Debian
 label mainmenu
 menu label ^Back..
 menu exit
 menu begin debian-lenny
 menu title Debian Lenny
 label mainmenu
 menu label ^Back..
 menu exit
 menu begin debian-lenny-i386
 menu title Debian Lenny i386
 label mainmenu
 menu label ^Back..
 menu exit
 default install
 label install
 menu label ^Install
kernel debian-lenny/i386/linux append vga=normal initrd=debian-lenny/i386
/initrd.gz -- quiet
 label expert
 menu label ^Expert install
 kernel debian-lenny/i386/linux
 append priority=low vga=normal initrd=debian-lenny/i386/initrd.gz --
 label rescue
 menu label ^Rescue mode
 kernel debian-lenny/i386/linux
 append vga=normal initrd=debian-lenny/i386/initrd.gz rescue/enable=true -- quiet
 label auto
 menu label ^Automated install
 kernel debian-lenny/i386/linux
 append auto=true priority=critical vga=normal initrd=debian-lenny/i386
/initrd.gz -- quiet
 menu end
 menu begin debian-lenny-amd64
 menu title Debian Lenny amd64
 label mainmenu
 menu label ^Back..
menu exit
 label install
 menu label ^Install
 kernel debian-lenny/amd64/linux
 append vga=normal initrd=debian-lenny/amd64/initrd.gz -- quiet
 label expert
 menu label ^Expert install
 kernel debian-lenny/amd64/linux
 append priority=low vga=normal initrd=debian-lenny/amd64/initrd.gz --
 label rescue
 menu label ^Rescue mode
 kernel debian-lenny/amd64/linux
 append vga=normal initrd=debian-lenny/amd64/initrd.gz rescue/enable=true -- quiet
 label auto
 menu label ^Automated install
 kernel debian-lenny/amd64/linux
 append auto=true priority=critical vga=normal initrd=debian-lenny/amd64
/initrd.gz -- quiet
 menu end
 menu end
menu end

Pour compléter je vous conseille la lecteure de cet article qui est plus complet que le mien :

http://www.queret.net/blog/post/2008/10/08/132-linux-installation-d-un-serveur-pxe

Shorewall et dns

Ne pas oublier pour la configuration de notre machine pour un bon accès au réseau, d'installer un firewall avec du masquerading et un dns local. J'utilise shorewall et bind9.

Client PXE HVM

Nous allons créer une machine virtuelle hvm qui viendra booter sur le serveur PXE. Le fichier de configuration de cette machine virtuelle est le suivant :

import os, re
arch = os.uname()[4]
if re.search('64', arch):
 arch_libdir = 'lib64'
else:
 arch_libdir = 'lib'
kernel = '/usr/lib/xen-3.2-1/boot/hvmloader'
builder='hvm'
memory='1024'
name='client-pxe'
device_model = '/usr/' + arch_libdir + '/xen-3.2-1/bin/qemu-dm'
boot='n'
vnc=1
vif=['type=ioemu,bridge=eth5,mac=00:00:aa:bb:44:ae']
usbdevice='tablet'

On démarre notre machine virtuelle et on se connecte dessus via VNC.

pypxeboot

Il existe une possibilité pour booter une machine paravirtualisé avec PXE, cependant elle impose d'installer le serveur PXE directement sur le domaine 0, c'est pypxeboot. Je n'ai pas testé cela ne correspondait pas à ce que je cherchais.