Tuesday, February 07, 2012

SysPrep /generalize + BCD store + STOP: c000021a

Today I tried to do a sysprep of a Windows Server 2008 R2 x64 computer before capturing an image of it via imagex.

sysprep.exe /generalize /oobe /shutdown /unattend:unattend.xml

Everything went fine and the computer shutdown.

Then I rebooted the server and had a blue screen (BSOD) :

STOP: c000021a {Fatal System Error}
The session manager initialization system process terminated unexpectedly with a status of 0xc000003a (0x00000000 0x00000000).
The system has been shut down.

I found out that SYSPREP had made some changes to my Boot Configuration Data (BCD). Here’s an extract of my setupact.log file :

LaunchDll:Found 'C:\Windows\System32\spbcd.dll,Sysprep_Generalize_Bcd'; executing it
Sysprep_Generalize_Bcd: Located BCD store on system drive. Generalizing it...
GeneralizeBcdStore: Found the memory tester object.
GeneralizeBcdStore: Found the Windows OS Loader object {bb3f7e5d-3afe-11e1-908d-0010184c4562} for the currently running OS.
GeneralizeBcdStore: Found the resume object {bb3f7e5c-3afe-11e1-908d-0010184c4562} for the OS loader.
GeneralizeBcdStore: System drive backed by VHD = 0
GeneralizeBcdStore: Generalizing object {9dea862c-5cdd-4e70-acc1-f32b344d4795}
GeneralizeBcdStore: Successfully generalized application device. Status = [0x0]
GeneralizeBcdStore: Generalizing object {b2721d73-1db4-4c62-bf78-c548a880142d}
GeneralizeBcdStore: Successfully generalized application device. Status = [0x0]
GeneralizeBcdStore: Generalizing object {bb3f7e5d-3afe-11e1-908d-0010184c4562}
GeneralizeBcdStore: Successfully generalized application device. Status = [0x0]
GeneralizeBcdStore: Successfully generalized OS device. Status = [0x0]
GeneralizeBcdStore: Generalizing object {bb3f7e5c-3afe-11e1-908d-0010184c4562}
GeneralizeBcdStore: Successfully generalized application device. Status = [0x0]
GeneralizeBcdStore: Successfully generalized hiberfile device. Status = [0x0]
Sysprep_Generalize_Bcd: Successfully generalized the bcd store. Status=[0x0]
LaunchDll:Successfully executed 'C:\Windows\System32\spbcd.dll,Sysprep_Generalize_Bcd' without error

So, after running sysprep /generalize my BCD looked like this :

Windows Boot Loader
-------------------
identifier              {default}
device                  locate=\windows\system32\winload.efi
path                    \windows\system32\winload.efi
description             Windows Server 2008 R2
locale                  en-us
inherit                 {bootloadersettings}
osdevice                locate=\windows
systemroot              \windows
resumeobject            {bb3f7e5c-3afe-11e1-908d-0010184c4562}
nx                      OptOut
detecthal               Yes

Did you noticed the locate=… value for the device and osdevice entries ? Well it seems that those new values were causing my blue screen.

I restored the previous values (before Sysprep) with the following commands :

bcdedit /set {default} device partition=C:
bcdedit /set [default} osdevice partition=C:

After that, my computer was able to boot again.

I’m not sure, but i suspect that this little mixed up with the BCD Store maybe related to how I partitioned my disk :

WinPE
Size 900Mb, boot WinPE to capture or apply an image from imagex
ESP
Size 100Mb, EFI System Partition, Active Partition
Microsoft Reserved
Size 128Mb
Windows
Size 120Gb, C: drive
Data
Size 400Gb, E: drive

My disk is initialize as a GPT disk and this is an EFI Computer.

My recommendation

Always make a backup of the BCD store before running SYSPREP :

bcdedit /export backupbcd.bcd