Saturday 1 September 2018


What is the best way to create a reusable Azure Virtual Machine Image?

https://serverfault.com/questions/726921/what-is-the-best-way-to-create-a-reusable-azure-virtual-machine-image


The best way to create an image is to use Powershell, the command is easy and straight forward:
Save-AzureVMImage -ServiceName "service-name" -Name "VM-name" -ImageName "image-name" -Osstate "Generalized/Specialized" -Verbose
Be careful about the Osstate option, if you want to create a template, you can choose Generalized, it will delete the existing vm and create a template image. If you want to create a snapshot image, you can choose Specialized, it will keep the existing vm and create an image -- it's just like the checkpoint in Hyper-V.

Azure link -- https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-capture-image-windows-server/



As someone who had never used SysPrep before, I found that many things I came across regarding SysPrep were not very useful to me, so I wanted to share two resources that I think are awesome for learning how to SysPrep a machine.

How to Use Sysprep to Customize Windows 7 and Windows 8
https://www.sevenforums.com/tutorials/286053-system-preparation-tool-use-customize-windows.html

Components - tells you about the different components available to customize an answer file

My situation: bought some Dell OptiPlex 380s from my community college for $25 each, refurbished them, and flipped for a profit. I wanted to get a perfect installation with all the settings and software I wanted and then create an image of it and place it on the other systems to save a ton of time.

Simply making a backup image with a program like Acronis isn't good enough as Microsoft says that you need to SysPrep the system to make it useable on another computer. SysPrep creates a new Security ID, resets Windows Activation, and more. It makes it so that the install is unique for each computer.

I created an answer file with only one thing - CopyProfile (mentioned in resource above). After using SysPrep you have to create a new user account. With CopyProfile enabled the new account is setup almost identical to the base one (the original one used in the install), so I barely have to do anything to the new account.

After making the answer file, I placed it in C:\Windows\System32\sysprep so that it's in the same location as the SysPrep program. There's no sensitive info in the answer file like domain/user passwords so this is secure.

Once ready to SysPrep, I simply opened a command prompt, used CD C:\Windows\System32\sysprep to get to the SysPrep.exe program, and then ran the following command:

sysprep.exe /generalize /shutdown /oobe /unattend:C:\Windows\System32\sysprep\MyAnswerFile.xml.

(Resource above explains how it works).

After SysPrep runs the system shuts down and then you make a clone of the drive. Reboot and the system sets itself up again - you can add a new user, activate Windows, and more.

It makes the system just like an OEM system you'd buy from HP or Dell. Especially if you do this using the built-in admin account.

Note:

Avast! Free Antivirus broke SysPrep. It caused an infinite loop error. I had to reimage the machine, remove Avast!, run the Avast Clean Uninstall program, and run SysPrep again.

When SysPrep failed, I used the article How to Fix Reboot Loop SysPrep Error to read the SysPrep log and find the culprit.




How To Fix Reboot Loop Sysprep Error







Error:  "Windows could not finish configuring the system.  To attempt to resume configuration, restart the computer."
When sysprepping a new image there is a chance that a corrupt or invalid registry key can cause the system to become stuck in an endless loop of of system configuration.  Many users will get stuck in a situation in which they have spent many hours perfecting an image only to have gathered an image that does not come out of Sysprep configuration.  If you find yourself stuck in this situation, there is a way to figure out exactly what registry key is causing your sysprep to fail, so then you don't have to slowly install every program until you find which software is causing the problem.
This issue is caused by a registry key or registry keys that are:
  • Set with invalid permissions
  • Bigger than 8kb
  • Corrupt
Sysprep has a log that you can use that will tell you exactly what registry key is erroring out, but it is not straightforward to extract this log from a machine that is stuck in a neverending sysprep reboot loop.
 Here are the steps for getting the log you need to see:
When you see the "Windows could not finish configuring the system. To attempt to resume configuration, restart the computer." error message, do the following:
  1. Push Shift+F10 to get to a command prompt
  2. Navigate to C:\windows\Panther
  3. Find the Setup.etl file and find a way to copy this file off of the system using network drivers or removable media
  4. Copy the setup.etl file from the sysprep looping system to another computer that has Windows 7. 
  5. Open a Command Prompt on the Windows 7 computer.
  6. Navigate to the root of C:\ (or wherever you saved the file)
  7. Type "tracerpt setup.etl -o logfile.csv"
  8. Close the command prompt and open up logfile.csv in your text editor of choice. 
  9. Look through the log file (towards the end probably) for messages that say "Failed to process reg key or one of it's decendants"
  10. Remove this software from your image or simply remove the offending registry key if possible
These steps will allow you to identify any problem keys and remove/workaround them on your image.

No comments:

Post a Comment