Blog de ILINFO

Trucs et astuces

Blog ILINFO Active DIrectory MIIS LDAP ADAM PCA PRA BCP DRP

Log in

Création d'un DVD de secours WINPE pour automatiser la réinstallation d'un poste Windows 7

by Emmanuel Dreux septembre 04, 2010 00:59

Voici un nouvel article autour de WINPE.

Ce billet explique comment créer un DVD bootable WINPE qui installe automatiquement votre image personnalisée Windows 7 stockée sur ce même DVD.

Il faut tout d'abord créer une image personnalisée de WINPE, puis y copier votre image WIM de Windows 7(préalablement capturée).

Ensuite créer un fichier de configuration qui permettra de formatter automatiquement vos disques puis d'appliquer l'image WIM.

A l'issue de cette manipulation, vous disposez d'un DVD de secours qui vous permettra d'installer ou réinstaller automatiquement votre poste.

 

Pour réaliser ce DVD, je vous propose tout d'abord de partir du script existant winpe.cmd disponible dans le WAIK.

Nous allons le customiser pour automatiser la création du WINPE qui contiendra tous les éléments nécessaires.

Faites une copie de winpe.cmd dans le même répertoire (exemple mywinpe.cmd) puis customisez le:

----------------------------   mywinpe.cmd -------------------------------------------------

@echo off
setlocal

set _P=%~dp0%
set TEMPL=ISO

if /i "%1"=="" goto usage
if /i "%2"=="" goto usage
if /i not "%3"=="" goto usage
set SOURCE=%_P%%1
set DEST=%2

if not exist "%SOURCE%\winpe.wim" (
  echo File does not exist: "%SOURCE%\winpe.wim"
  exit /b 1
)

if exist "%DEST%" (
  echo Destination directory exists: %2
  exit /b 1
)

mkdir "%DEST%"
if errorlevel 1 (
  echo Unable to create destination: %2
  exit /b 1
)

echo.
echo ===================================================
echo Creating Windows PE customization working directory
echo.
echo     %DEST%
echo ===================================================
echo.

mkdir "%DEST%\%TEMPL%"
if errorlevel 1 goto :FAIL
mkdir "%DEST%\mount"
if errorlevel 1 goto :FAIL

if exist "%SOURCE%\bootmgr" copy "%SOURCE%\bootmgr" "%DEST%\%TEMPL%"
if errorlevel 1 goto :FAIL
if exist "%SOURCE%\bootmgr.efi" copy "%SOURCE%\bootmgr.efi" "%DEST%\%TEMPL%"
if errorlevel 1 goto :FAIL
if exist "%SOURCE%\boot\etfsboot.com" copy "%SOURCE%\boot\etfsboot.com" "%DEST%"
if errorlevel 1 goto :FAIL
if exist "%SOURCE%\boot\efisys.bin" copy "%SOURCE%\boot\efisys.bin" "%DEST%"
if errorlevel 1 goto :FAIL
if exist "%SOURCE%\boot\efisys_noprompt.bin" copy "%SOURCE%\boot\efisys_noprompt.bin" "%DEST%"
if errorlevel 1 goto :FAIL
if exist "%SOURCE%\boot" xcopy /cherky "%SOURCE%\boot" "%DEST%\%TEMPL%\boot\"
if errorlevel 1 goto :FAIL
if exist "%SOURCE%\EFI" xcopy /cherky "%SOURCE%\EFI" "%DEST%\%TEMPL%\EFI\"
if errorlevel 1 goto :FAIL
mkdir "%DEST%\%TEMPL%\sources"
if errorlevel 1 goto :FAIL
copy "%SOURCE%\winpe.wim" "%DEST%\winpe.wim"
if errorlevel 1 goto :FAIL

endlocal
echo.
echo Success
echo.
echo Updating path to include peimg, cdimage, imagex
echo.
echo    %~dp0
echo    %~dp0..\%PROCESSOR_ARCHITECTURE%
echo.

set PATH=%PATH%;%~dp0;%~dp0..\%PROCESSOR_ARCHITECTURE%
cd /d "%2"

rem: les commandes suviantes personnalisent l'image winpe et y copient les fichiers nécessaires

Dism /Mount-Wim /WimFile:C:\winpe_x86\winpe.wim /index:1 /MountDir:C:\winpe_x86\mount
dism /image:C:\winpe_x86\mount /Set-InputLocale:fr-FR
dism /image:C:\winpe_x86\mount /Set-UserLocale:fr-FR
copy "C:\Program Files\Windows AIK\Tools\x86\imagex.exe" C:\winpe_x86\mount\Windows\System32\
rem: copie l'utilitaire de reboot
copy "C:\windows\system32\shutdown.exe" C:\winpe_x86\mount\Windows\System32\
mkdir c:\winpe_x86\mount\tools
rem: Fichier qui précise les commandes à exécuter automatiquement
copy c:\temp\winpeshl.ini C:\winpe_x86\mount\Windows\System32
rem: Fichier qui automatise le partitionnement
copy c:\temp\diskpart.txt c:\winpe_x86\mount\tools
rem: Batch lancé au démarrage
copy c:\temp\install.cmd c:\winpe_x86\mount\tools
dism /Unmount-Wim /MountDir:C:\winpe_x86\mount /Commit
copy c:\winpe_x86\winpe.wim c:\winpe_x86\ISO\sources\boot.wim
rem:Inséréz ici votre propre image windows7.wim
copy c:\temp\install7.wim c:\winpe_x86\ISO
oscdimg -m -n -bC:\winpe_x86\etfsboot.com C:\winpe_x86\ISO C:\winpe_x86\winpe_x86.iso

goto :EOF

:usage
echo Usage: copype [x86 ^| amd64 ^| ia64] destination
echo.
echo Example: copype x86 c:\windowspe-x86
goto :EOF

:FAIL
echo Failed to create working directory
 

-----------------------------------------------------------------------------------------------------

winpeshl.ini est le fichier qui contient les commandes à exécuter au démarrage de winpe.

Ici, on se contentera de démarrer un batch qui contient toutes les commandes.

----------------------------------   winpeshl.ini              ----------------------------------------

 [LaunchApp]
AppPath = x:\tools\install.cmd

-----------------------------------------------------------------------------------------------------

Install.cmd partitionne le disque automatiquement.

Ensuite, en fonction des lecteurs CD et DVD installés, il detecte automatiquement sur quelle lettre est disponible l'image d'installation et l'applique.

A la fin, il réalise un shutdown de la station.

 ------------------------------------- Install.cmd              ---------------------------------------

 diskpart /s x:\tools\diskpart.txt

if exist d:\install7.wim goto lectd
if exist e:\install7.wim goto lecte
if exist f:\install7.wim goto lectf
if exist g:\install7.wim goto lectg

:lectd
imagex /apply d:\install7.wim 1 c:
c:\windows\system32\bcdboot c:\windows
shutdown -s -t 00

:lecte
imagex /apply e:\install7.wim 1 c:
c:\windows\system32\bcdboot c:\windows
shutdown -s -t 00

:lectf
imagex /apply f:\install7.wim 1 c:
c:\windows\system32\bcdboot c:\windows
shutdown -s -t 00

:lectg
imagex /apply g:\install7.wim 1 c:
c:\windows\system32\bcdboot c:\windows
shutdown -s -t 00

 -----------------------------------------------------------------------------------------------

Pour terminer, le fichier diskpart.txt contiendra les commandes à lancer dans l'utilitaire diskpart pour automatiser la création des partitions et leur formattage.

 ---------------------------------------  dispkpart.txt           ------------------------------

select disk 0
clean
create partition primary
select partition 1
format fs=ntfs quick label="Windows"
active
assign letter=c
exit
 

Soyez le premier à noter ce billet

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

déploiement Windows 7 | winpe

Partenaires
Assurez votre plan de continuit� d'activit� avec BCPAnywhere
Votre poste de travail partout dans le monde.

Mig6 votre solution de migration de vos postes de travail vers Windows 7
Migrez de XP vers Windows 7 avec Mig6.

Auteur

Freelance, Indépendant, expert Active Directory, Domaine et Sécurité.

Expert MIIS, ILM, FIM 2010,Kerberos, NTLM, SSL, PKI et chiffrement.