Romain Tiennot

Technicien Superieur en Informatique

Aller au contenu | Aller au menu | Aller à la recherche

Keyword - PXE

Fil des billets

Installation de CentOS via PXE et automatiser grace à KickStart

Linux Vous pouvez retrouver mon article pour la création d'un serveur DHCP et TFTP pour démarrer sous PXE afin d'installer différente distribution. L'avantage de ceci est que nous n'avons plus besoin de media. Cette article permet d'automatiser cette installation grâce à KickStart. Il suffit de créer un fichier avec différente information. C'est information peuvent être retrouvé sur le site de Fedora ou encore CentOS.

Pour commencer, il faut installer un serveur apache :

apt-get install apache2

Ensuite créer un fichier de réponse à la racine (par exemple) du répertoire "/var/www" :

wget http://romain.tiennot.fr/public/pxelinux/centos5.ks && mv centos5.ks /var/www/

Voici mon exemple :

# Kickstart file for CentOS 5
# TP CESI
 
# General option
 
install
url --url http://mirror.centos.org/centos-5/5.7/os/x86_64/
lang fr_FR.UTF-8
keyboard fr-latin1
skipx
# Use text for normal install, cmdline for debug
cmdline
firstboot --disable
network --device=eth0 --bootproto=dhcp
firewall --disabled
selinux --enforcing
timezone Europe/Paris
 
authconfig --enableshadow --enablemd5
rootpw --iscrypted $1$Cr6bSPjq$0PDcH3i5r0AOHDt.oDHRt1
 
# Reboot after install
reboot
 
# Disable unnecessary services
services --disabled=avahi-daemon,bluetooth,isdn,cups,mdmonitor,NetworkManager,pcscd,smartd,ip6tables,yum-updatesd,portmap,rpcidmapd,netfs,rpcgssd,gpm,nfslock,firstboot,iscsid,iscsi
 
# Partition 
bootloader --location=mbr --append="console=xvc0"
 
clearpart --all --initlabel
part /boot --fstype ext3 --size=150 --ondisk=sda
part pv.01 --size=1 --grow  --asprimary --ondisk=sda
volgroup rootvg --pesize=32768 pv.01
logvol swap --fstype swap --name=LV_swap --vgname=rootvg --size=1024
logvol / --fstype ext4 --name=LV_Racine --vgname=rootvg --size=4092 
logvol /var --fstype ext4 --name=LV_var --vgname=rootvg --size=4048
 
 
# Select package to install
%packages
@editors
@core
@base
@french-support
rsyslog
postfix
nfs-utils
 
# Remove unnecessary package
-sendmail-cf
-sendmail
-exim
-smartmontools
-autofs
-bluez-utils
-acpid
-mdmonitor
-microcode_ctl
-xinetd
-pcsc-lite
-sysklogd
 
# Postinstall script
%post --log=/root/kickstart_post_install.log
 
cat <<EOF >>/etc/motd
Installed `date` 
EOF

Par la suite, s'assurer que le serveur à un accès internet afin de télécharger les sources d'installation indiqué un peu plus haut dans le fichier de réponse "url --url http://mirror.centos.org/centos-5/5.7/os/x86_64/". Il est possible d'indiquer l'emplacement du CDROM ou encore d'un emplacement sur le disque dur.

Il faut indiquer dans le fichier "default" que l'installation du CentOS utilisera le fichier "centos5.ks" présent sur notre serveur Apache :

LABEL CentOS 5.7 KS eth0
        KERNEL image/centos/5.7/vmlinuz
        APPEND ks=http://172.16.0.152/centos5.ks initrd=image/centos/5.7/initrd.img

Il ne vous reste plus qu'à démarrer en PXE et lancer l'installation. Si une erreur est rencontré à cause du fichier de réponse, celui si vous demandera de modifier les informations (Par exemple, le chemin du fichier KS ou encore les sources d'installation).

A bientôt,
Romain

Créer un menu PXE pour l'installation Debian, Centos, Ubuntu et Memtest

Linux Je vais vous expliquer comment créer un serveur DHCP et PXE afin d'installer à partir du réseau différente distribution comme dans mon exemple Debian, Centos et Ubuntu. Il est possible d'intégrer des outils de diagnostic comme Memtest ou encore SystemRescueCd.

Pour mettre en place le serveur PXE, nous avons besoins :

  • un DHCP
  • un serveur TFTP

Pour ce faire, nous avons besoin d'installer les paquets suivant :

apt-get update
apt-get upgrade
apt-get install dhcp3-server tftpd-hpa

Il est préférable de mettre une IP statique à la carte réseau du serveur :

vi /etc/network/interfaces
auto eth0
iface eth0 inet static
        address 172.16.0.152
        netmask 255.255.0.0
        network 172.16.0.1
        broadcast 172.16.255.255
        gateway 172.16.0.254
        dns-nameservers 172.16.0.254

Et de redémarrer le service réseau :

invoke-rc.d networking restart

Ensuite, il faut configurer le serveur DHCP pour qu'il puisse distribuer une configuration réseau notamment des informations pour le PXE :

vi /etc/dhcp/dhcpd.conf
ddns-update-style none;
option domain-name "local.info";
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
 
 
subnet 172.16.0.0 netmask 255.255.255.0 {
        option broadcast-address 172.16.255.255;
        option routers 172.16.0.1;
        range 172.16.0.20 172.16.0.30;
        filename "pxelinux.0";
        next-server 172.16.0.152;

Il faut ensuite créer l'arborescence :

mkdir -pv /srv/tftpboot/pxelinux.cfg /srv/tftpboot/image/debian/squeeze/i386 /srv/tftpboot/image/centos/5.7/ /srv/tftpboot/image/memtest/4.2/ /srv/tftpboot/image/ubuntu/11.10/
wget http://ftp.fr.debian.org/debian/dists/squeeze/main/installer-i386/current/images/netboot/debian-installer/i386/boot-screens/vesamenu.c32 && mv vesamenu.c32 /srv/tftpboot/
wget http://ftp.fr.debian.org/debian/dists/squeeze/main/installer-i386/current/images/netboot/debian-installer/i386/pxelinux.0 && mv pxelinux.0 /srv/tftpboot/

Puis télécharger les images des distributions qui serviront à l'installation :

DEBIAN
 
wget http://ftp.fr.debian.org/debian/dists/squeeze/main/installer-i386/current/images/netboot/debian-installer/i386/linux && mv linux /srv/tftpboot/image/debian/squeeze/i386/
wget http://ftp.fr.debian.org/debian/dists/squeeze/main/installer-i386/current/images/netboot/debian-installer/i386/initrd.gz && mv initrd.gz /srv/tftpboot/image/debian/squeeze/i386/
UBUNTU
 
wget http://fr.archive.ubuntu.com/ubuntu/dists/oneiric/main/installer-i386/current/images/netboot/ubuntu-installer/i386/linux && mv linux /srv/tftpboot/image/ubuntu/11.10/
wget http://fr.archive.ubuntu.com/ubuntu/dists/oneiric/main/installer-i386/current/images/netboot/ubuntu-installer/i386/initrd.gz && mv initrd.gz /srv/tftpboot/image/ubuntu/11.10/
CENTOS
 
wget http://mirror.centos.org/centos-5/5.7/os/x86_64/images/pxeboot/vmlinuz && mv vmlinuz /srv/tftpboot/image/centos/5.7/
wget http://mirror.centos.org/centos-5/5.7/os/x86_64/images/pxeboot/initrd.img && mv initrd.img /srv/tftpboot/image/centos/5.7/
MEMTEST
 
wget http://www.memtest.org/download/4.20/memtest86+-4.20.bin && mv memtest86+-4.20.bin /srv/tftpboot/image/memtest/4.2/memtest86+

Ensuite, nous allons créer le fichier "default" qui va nous permettre à créer le menu PXE :

vi /srv/tftpboot/pxelinux.cfg/default
DEFAULT vesamenu.c32
menu background pxelinux.cfg/fond.png
menu title Menu d'installation PXE
 
prompt 0
timeout 100
 
noescape 1
allowoptions 0
 
LABEL Demarrage Disque Dur
        localboot 0
 
MENU BEGIN Debian
MENU TITLE Debian
LABEL Debian Squeeze 6.03 Installation
       kernel image/debian/squeeze/i386/linux
       append vga=normal initrd=image/debian/squeeze/i386/initrd.gz  --
 
LABEL Debian Rescue
       kernel image/debian/squeeze/i386/linux
       append vga=normal initrd=image/debian/squeeze/i386/initrd.gz  rescue/enable=true --
MENU END
 
MENU BEGIN CentOS
MENU TITLE CentOS
LABEL CentOS 5.7 KS eth0
        KERNEL image/centos/5.7/vmlinuz
        APPEND ks=http://172.16.0.152/centos5.ks initrd=image/centos/5.7/initrd.img
MENU END
 
MENU BEGIN Ubuntu
MENU TITLE Ubuntu
LABEL Ubuntu 11.10
        KERNEL image/ubuntu/11.10/linux
        append vga=normal initrd=image/ubuntu/11.10/initrd.gz --
MENU END
 
LABEL Diagnostique Memoire (Memtest)
        kernel image/memtest/4.2/memtest86+

Il est possible de mettre une image en fond d'écran :

wget http://romain.tiennot.fr/public/pxelinux/fond.png && mv fond.png /srv/tftpboot/pxelinux.cfg/

Après avoir relancé les services, Il vous reste à démarrer via le réseau et voir le résultat.

invoke-rc.d isc-dhcp-server start
invoke-rc.d tftpd-hpa start

A bientôt,
Romain