Installer Windows depuis un serveur PXE Linux

Voyons comment installer Windows depuis un démarrage PXE. Ceci revient en fait à lancer l'installation de Windows (7 par exemple) depuis un environnement WinPE personnalisé de la manière suivante :
- intégration du pilote Realtek Gigabit PCIe, de plus en plus répandu et indispensable pour lancer l'installation par le réseau ;
- une fois WinPE chargé, montage du media en CIFS contenant le répertoire "source" du média d'installation et lancement de l'assistant.

Cette méthode et ce billet sont très largement inspirée de ce très bon billet : Installing Windows 7 with a PXE boot server. Il consiste essentiellement en quelques modifications du script.

  • Télécharger et installer le Windows Automated Installation Kit (WAIK) ;
  • Télécharger le pilote Realtek et le décompresser.
  • Dans un nouveau fichier (par exemple build.cmd), coller le code suivant après avoir adapté les variables :
@echo off
cls

REM Variables
echo Setting variables ...
REM the path to your WAIK installation
set WAIKPath=%ProgramFiles%\Windows AIK
echo Set WAIK directory to %WAIKPath%.
REM possible values are: x86, amd64 and ia64
set ARCH=amd64
echo Set architecture to %ARCH%.
set PEPath=C:\winpe_%ARCH%
echo Set temporary working directory for Windows PE to %PEPath%.
set TFTPPath=C:\tftp\Boot
echo Set TFTP boot directory to %TFTPPath%.
set CIFSShare=\\boot\seven_x64
echo Set CIFS share containing the media to %CIFSShare%
set AdditionalDriver=C:\GBE\64\rt64win7.inf
echo Set driver to be added to %AdditionalDriver%
set BCDStore=%TFTPPath%\BCD
echo Set BCDStore to %BCDStore%.
echo All variables set!
echo.

REM Environment check
echo Checking for clean environment...
if not exist "%WAIKPATH%" set NoWAIK=1 && goto :end
if not exist "%WAIKPath%\Tools\PETools\%ARCH%" set NoARCH=1 && goto :end
if exist %PEPath% echo Temporary working directory not empty! Need to remove && rd %PEPath% /S
if exist %PEPath% echo Temporary working directory still not empty! Trying again ... && cd "%WAIKPath%\Tools\%ARCH%" && imagex /unmount %PEPath%\mount && rd %PEPath% /S /Q
if exist %PEPath% set NotClean=1 && goto :end
if exist %TFTPPath% echo TFTP boot directory not empty! Need to remove && rd %TFTPPath% /S
if exist %TFTPPath% set NotClean=1 && goto :end
echo.

echo Starting real work now ...
cd "%WAIKPath%\Tools\PETools"
echo Copying PE-Files ...
call copype %ARCH% %PEPath%

imagex /mountrw %PEPath%\winpe.wim 1 %PEPath%\mount
echo Personnalisation de l'environnement WinPE
echo net use y: %CIFSShare% >> "%PEPath%\mount\Windows\System32\startnet.cmd"
echo y:\setup.exe >> "%PEPath%\mount\Windows\System32\startnet.cmd"
dism /image:%PEPath%\mount /add-driver /driver:%AdditionalDriver%
md %TFTPPath% > NUL
copy %PEPath%\mount\Windows\Boot\PXE\*.* %TFTPPath% > NUL
copy "%WAIKPath%\Tools\PETools\%ARCH%\boot\boot.sdi" %TFTPPath% > NUL

echo Creation du BCD...
cd %PEPath%\mount\Windows\System32
bcdedit -createstore %BCDStore%
bcdedit -store %BCDStore% -create {ramdiskoptions} /d "Ramdisk options"
bcdedit -store %BCDStore% -set {ramdiskoptions} ramdisksdidevice Boot
bcdedit -store %BCDStore% -set {ramdiskoptions} ramdisksdipath \Boot\boot.sdi
REM Tokens=3 sur un WAIK en anglais
for /f "Tokens=2" %%i in ('bcdedit /store %BCDStore% /create /d "Windows 7 Install Image" /application osloader') do set GUID=%%i
bcdedit -store %BCDStore% -set %GUID% systemroot \Windows
bcdedit -store %BCDStore% -set %GUID% detecthal yes
bcdedit -store %BCDStore% -set %GUID% winpe yes
bcdedit -store %BCDStore% -set %GUID% osdevice ramdisk=[boot]\Boot\winpe.wim,{ramdiskoptions}
bcdedit -store %BCDStore% -set %GUID% device ramdisk=[boot]\Boot\winpe.wim,{ramdiskoptions}
bcdedit -store %BCDStore% -create {bootmgr} /d "Windows 7 Boot Manager"
bcdedit -store %BCDStore% -set {bootmgr} timeout 30
bcdedit -store %BCDStore% -set {bootmgr} displayorder %GUID%

cd "%WAIKPath%\Tools\PETools"
imagex /unmount /commit %PEPath%\mount
copy %PEPath%\winpe.wim %TFTPPath%

goto :exit

:end
if %NoWAIK%=1 echo "Your WAIK directory was not found. Execution aborted." && pause && goto :exit
if %NoARCH%=1 echo "Your Architecture doesn't seem to be right. Or at least it is not known by your WAIK installation. Execution aborted." && pause && goto :exit
if %NotClean%=1 echo "Your environment was not clean. Execution aborted." && pause && goto :exit

:exit


  • Démarrer la console ("Deployment Tools Command Prompt") en administrateur et lancer le script build.cmd. Cela génère dans %TFTPPath% plusieurs fichiers à copier dans un répertoire "Boot", lui-même à la racine du serveur TFTP.


  • Ajouter le remapping suivant grâce à l'option -m de tftpd-hpa :
rg \\ /


  • Il faut créer le lien symbolique suivant dans <racine TFTP>/Boot :
ln -s pxeboot.n12 startrom.0


  • Ajouter une entrée dans le fichier <racine TFTP>/pxelinux.cfg/default :
LABEL winpe
     MENU LABEL Installation de Windows 7 64 bits
     KERNEL Boot/startrom.0



EDIT 24/02/2014 : correction de quelques erreurs dans le script.

La discussion continue ailleurs

URL de rétrolien : http://www.leslamas.net/index.php?trackback/53

Fil des commentaires de ce billet