Posted by December 24, 2013
Creating AMI from Windows instance in AWS is simple and easy. The whole process is well-documented, yet here are several notes that I made while experimenting.
Running Sysprep Tool
In the VMware world, you can convert a VM to a template at any moment. Deployment of multiple clones is made possible via Customization Specifications mechanism, where you define how to customize the new VM after cloning. As part of the customization process, vCenter will run Sysprep tool – after the instance was already cloned. In contrary, AWS wants you to run sysprep before the cloning, as preparation to AMI creation. You can do that via EC2ConfigService settings (see below) or manually, but former seems to be the preferred and recommended way.
The unwanted side effect of running sysprep on the original instance is that many of the original instance settings (instance name, Administrator account etc.) are actually reset during the cloning process. There are workarounds that can help you to deal with some consequences, but not all of them.
The EC2ConfigService is Windows service provided and installed by AWS, which takes care about a lot of useful customizations behind the scenes. Examples are generation of Administrator password (one that you retrieve via “Connect” button in EC2 Management Console), setting of computer name, display of system information on the desktop wallpaper and a lot more. But the most important task is to deal with instance cloning – that is, make sure that stuff that is supposed to be unique is really unique and make this cloning process simple and easy.
Note that you cannot install this service on a Windows instance imported from other systems (for example, VMware vCenter). You’ll have to start your original instance from AWS AMI if you want to use EC2ConfigService there.
The name of the original Windows instance will be reset during sysprep process to the default semi-random name provided by AWS (in the form of “WIN-<something>”). The only workaround for that is to use “Set Computer Name” from EC2ConfigService settings. This flag instructs EC2ConfigService to (re)set system name according to the internal IP adrress – which remains constant during the instance lifecycle. The resulting name will not become much more readable, but at least it will not change during the AMI creation process. You’ll have to remove this flag manually on the cloned instances to set more meaningful names there.
The Administrator account from the original instance will not make his way to the cloned instances, so any customizations made there will be lost. The workaround is to create an additional account with administrative permissions and perform the desired customizations there. There are many settings that will go this way too (for example, regional settings or pinned taskbar items), but some will survive – desktop shortcuts, windows explorer options and more.
Another tip is to choose “Keep Existing” in the “Administrator Password” section of EC2ConfigService configuration. While it won’t help you to retain current password in the new instances (because Sysprep tool on Windows 2008 resets it anyway), at least the Administrator password of your original instance will not be changed.
AMI Creation Steps
This is not an ultimate guide on how to create AMI, but rather a note/reminder to myself…
- Create a new EC2 instance from AWS AMI
- Create new administrative account and start using it instead of the build-in one
- (optional) Use “Set Computer Name” option from EC2ConfigService settings
- Customize your instance – install software, add desktop shortcuts etc.
- Start EC2ConfigService settings utility, go to the “Image” tab and perform the following:
- (optional) Under “Administrator Password” section, select “Keep Existing” option
- Click “Shutdown with Sysprep” button and confirm the prompt
- Wait while the Sysprep process completed and the instance shuts down
- Right-click the instance in the EC2 Management Console, choose “Create Image” and follow the instructions
Tip: Disk Size
When you launch an EC2 instance that you plan to convert to AMI later, pay attention to the disk size. Remember that the disk of the AMI must be at least that big, and the same applies to any instance that will be launched from the new AMI. Provisioning 10GB of spare storage in your AMI will cost you $1 per instance per month, which may be kinda painful in the yearly bill (do the math yourself).
Posted in HOWTO, Workarounds | Tagged: AMI, AWS, EC2, VMware, Windows, Windows 2008 | 2 Comments »
Posted by October 28, 2013
Using Thin Provisioning for virtual disks of your VM can save you a lot of useful space on your datastore and significantly speed up maintenance tasks that involve copying or moving of the VMDK files. Apparently, switching from one provisioning format to another can be done easily via Clone Virtual Machine wizard, where Storage tab allows you to specify the virtual disk format for the cloned VM. There you can select either to keep the same disk format as source VM had or choose another one, including Thin Provision. However, the choice of Thin Provision disk format will be silently ignored when the source format is Thick Provisioned and both source and target are located in the same datastore. This behavior is somehow understandable when you think about the underlying implementation, but not user friendly.
So, how can you change the provisioning type of your VM from Thick to Thin anyway? Here is your algorithm.
- Do you have more than one datastore available? You can migrate your VM to another datastore, modifying the virtual disk provisioning mode on the way, and then migrate it back if needed. This way is covered in details in the second part of KB2014832 article on VMware Knowledge Base.
- Do you have only one datastore or all your datastores are under the same Storage DRS? You can create a clone of your VM with the help of vCenter Converter Standalone. This tool runs on your desktop and allows you to convert one VM format into another, changing most of the VM setting on the way. This includes change of disk provisioning type from Thick to Thin even when both source and destination are located on the same datastore.
- Do you prefer the hard and risky ways? If so, dealing with vmkfstools if for you 🙂
Posted in HOWTO, Workarounds | Tagged: VMware, vSphere | Leave a Comment »
Posted by January 16, 2012
Some time ago I managed to isolate an ugly vSphere 5 bug that caused me some unpleasant moments. Today I finally reproduced this behavior in a clean lab environment, so I feel confident enough to describe it in public. Don’t worry, the way to recover is described also!
Take a vSphere 5 environment with a template (say, “MyTemplate”) that you want to deploy a virtual machine from. Step through a regular deployment wizard and select “Edit Virtual Hardware” on the last page. In the VM properties, choose the hard disk and change its size. The new VM (say, “MyVM”) will be created successfully, but the next time you’ll go through the deployment process it will fail with a strange message: “Unable to access file ‘MyTemplate/MyTemplate.vmdk’ since it is locked”…
A quick search in VMware KB (or just in Google) will tell you that the vmdk (the virtual disk of the VM) is usually locked when some other VM uses the same disk. Hey, this is a template! No other VMs are supposed to use the template disk, right? Well, the truth is that this disk is now attached to MyVM – yes, that one with different disk size… But let the lock alone. Your lovely template is now gone, since the disk that belonged to the template is now owned by the running virtual machine – with new name, settings and maybe even software!
Well, how do you recover from this situation? The good news are that the original disk from MyTemplate is not gone. In fact, vSphere really cloned a new vmdk file for MyVM and placed it where it should usually reside – in ‘MyVM/MyVM.vmdk’ – but for some reason set the MyVM to use a template file instead. At this moment you can take a deep breath, shut down MyVM, point it to the right virtual disk and physically swap the files in the datastore… Read the rest of this entry »
Posted in Troubleshooting, Workarounds | Tagged: VMware, vSphere | 32 Comments »
Posted by December 14, 2011
The internet is full of complains that Admin Pack for Windows 2003 cannot be installed due to protected Windows files. I guess that this can happen for various reasons, but I have found a solution for at least one of the cases – when the server where the installation of Windows 2003 Admin Pack fails is virtualized.
So, we have two servers – Windows 2003 Server with Active Directory installed as Domain Controller (server #1) and VM with Windows 2003 Server that is a member of this domain (server #2). The need – administer DNS and DHCP settings of AD remotely, but corresponding MMC snap-ins are not available by default on non-DC machines. The correct way is to install ADMINPACK.MSI, available from Windows 2003 installation CD-ROM or from Microsoft Download Center. (Of course, you can always open an RDP session to a DC – but this does not address the real need.)
However, the installation suddenly shows a message “The Windows Installer service cannot update one or more protected windows files” and rolls back everything that was already installed. The Event Viewer reveals error numbers (“Error 1933. … SPF Error: 1223.”) and the list of protected files – but this does not really help. So, what can we do about that?
In fact, the solution is really simple. Running the same installation via the console RDP session (or in the vSphere console) reveals the real cause for the failure – the Admin Pack install needs Windows 2003 installation CD-ROM, but for some reason does not tell that on non-console sessions. After the requested CD is provided (for VMs, this can be done by mounting the CD image in vSphere or via DaemonTools), the installation was able to complete successfully. Read the rest of this entry »
Posted in HOWTO, Troubleshooting | Tagged: Microsoft, RDP, VMware, Windows 2003 | Leave a Comment »
Posted by September 8, 2011
Did it ever happen to you that you want to revert some VM to another snapshot and get “The object has already been deleted or has not been completely created” error message? It is really painful, especially if you lab heavily relies on excellent snapshot functionality provided by vSphere… It appears that sometimes it can be fixed by deleting the VM from the inventory and adding it back. The process is really simple, but requires administrative credentials.
So, here it goes:
- Go to the Summary tab for your VM, find the relevant datastore and choose “Browse Datastore…” option.
- Find the folder that belongs to your VM and make sure you see the “.vmx” file (you’ll need it in step 5).
- Go back to your VM in the vSphere tree and choose “Remove from Inventory” in the context menu. Be careful – “Delete from Disk” is the next option, and it is not reversible!
- Wait while vSphere performs your request.
- Go to datastore window, open context menu of the “.vmx” file and choose “Add to Inventory”
- Go through the wizard, selecting relevant options for VM import.
That’s all – wait until the VM will be fully imported and try to revert to your favorite snapshot now.
Posted in Troubleshooting, Workarounds | Tagged: VMware, vSphere | Leave a Comment »