Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Does anyone know how to create smaller disk size Windows instances on Amazon EC2? Their default is 30 GB, and I have to pay $0.10/GB/month for EBS storage, which means that for each Windows instance I have to pay additional $3 a month. If I have 100 instances, that's $300 wasted. I'd be pretty happy with 5GB or even smaller Windows instances. Thanks!

share|improve this question
    
What version of Windows? If you want small you probably need to look elsewhere. You are going to need 30gb if you are running Windows 2008. –  dunxd Nov 14 '10 at 13:12

2 Answers 2

It seems like this has been done on Win2008-R2, according to http://support.rightscale.com/09-Clouds/AWS/FAQs/How_do_I_shrink_an_EBS-backed_HVM_Windows_AMI%3F :

  1. Launch an instance directly from the image you want to resize, not using a Server Template. Be sure to associate an SSH key for which you have the private key material handy so you can log in.
  2. Once the instance is running, retrieve the administrator password from the AWS Console. Additionally, identify the snapshot ID of the volume used as the root device by clicking the device name (typically /dev/sda1) in the description of the instance in the AWS Console.
  3. Create a volume from the image you wish to resize using the snapshot ID obtained in the previous step, and attach this to the instance.
  4. Create and attach a blank EBS volume using the desired size of the shrunk image.
  5. Open an RDP session to the instance.
  6. Open the Server Manager, and under the Server Summary section, scroll to Security Information. Click the Configure IE ESC setting; disable for admin. Now, go to Storage, enable the attached disk containing the image (right-click and set to online), then format and mark as active the empty disk(this should be e:).
  7. To proceed, you'll need to install imagex. You can get the full WAIK suite from Microsoft, or selectively download the required tools using this application: http://theoven.org/index.php?topic=287
  8. Open the command prompt and cd to waik_3, as installed in the previous step.
  9. Invoke imagex as follows, where C: is the root device, D: is the volume containing the image to be shrunk, and E: is the empty volume.

    imagex.exe /capture d:\ c:\server-image.wim "Windows Server Image" imagex.exe /apply c:\server-image.wim 1 e:

  10. Close your RDP session, and stop the instance from the AWS Console.

  11. Detach all volumes; reattach the smaller volume as /dev/sda1; the other two volumes (the original root device and the volume containing the source of the image) should be destroyed.
  12. Start the instance to confirm the new image is operational; use the EC2 tools to run sysprep and stop the instance. Otherwise, skip to the next step.

Your new instance might not boot after this, so you need to fix that, using http://www.smattie.com/2011/12/21/windows-72008r2-does-not-load-after-adding-the-drive-to-another-machine-that-also-uses-new-bcd-store/ and https://technet.microsoft.com/en-us/library/cc731245(WS.10).aspx:

bootsect /nt60 D: /mgr
C:\windows\system32\bcdboot.exe E:\Windows /s D:
bcdedit /store D:\Boot\BCD /set {default} device partition=E:
bcdedit /store D:\Boot\BCD /set {default} osdevice partition=E:
bcdedit /store D:\Boot\BCD /set {bootmgr} device partition=E:

The disk signature needs to be fixed as well using regedit and DISKPART as described here http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-passwords.html#ResettingAdminPassword - Step 8:

If your temporary instance is based on the same AMI that the original instance is based on, and the operating system is later than Windows Server 2003, you must complete the following steps or you won't be able to boot the original instance after you restore its root volume because of a disk signature collision.

  1. In the Registry Editor, load the following registry hive into a folder named BCD: d:\boot\bcd.
  2. Search for the following data value in BCD: "Windows Boot Manager". You'll find a match under a key named 12000004.
  3. Select the key named 11000001 that is sibling to the key you found in the previous step. View the data for the Element value.
  4. Locate the four-byte disk signature at offset 0x38 in the data. Reverse the bytes to create the disk signature, and write it down. For example, the disk signature represented by the following data is E9EB3AA5:

    ...

    0030 00 00 00 00 01 00 00 00

    0038 A5 3A EB E9 00 00 00 00

    0040 00 00 00 00 00 00 00 00

    ...

  5. In a Command Prompt window, run the following command to start Microsoft DiskPart.

    C:> diskpart

  6. Run the following DiskPart command to select the volume. (You can verify that the disk number is 1 using the Disk Management utility.)

    DISKPART> select disk 1

  7. Disk 1 is now the selected disk. Run the following DiskPart command to get the disk signature.

    DISKPART> uniqueid disk Disk ID: 0C764FA8

  8. If the disk signature shown in the previous step doesn't match the disk signature from BCD that you wrote down earlier, use the following DiskPart command to change the disk signature so that it matches:

    DISKPART> uniqueid disk id=E9EB3AA5

To finish up:

  1. Detach the secondary volume from the temporary instance as follows:

    a. Using the Disk Management utility, bring the volume offline.

    Note The drive is automatically offline if the temporary instance is running the same operating system as the affected
    instance, so you won't need to bring it offline manually. From the Amazon EC2 console, in the navigation pane, click Volumes.

    b. In the list of volumes, right-click the volume, and then click Detach Volume. After the volume's status changes to available, proceed with the next step.

  2. Reattach the volume to the original instance as its root volume as follows:

    a. Right-click the volume and then click Attach Volume.

    b. In the Attach Volume dialog box, start typing the name or ID of the original instance in the Instances list, and then select the instance.

    c. In the Device box, enter /dev/sda1.

    d. Click Yes, Attach.

  3. Restart the original instance as follows:

    a. In the navigation pane, click Instances.

    b. Right-click the original instance and then click Start.

    c. In the Start Instances dialog box, click Yes, Start.

At this point you can create a new image with a the smaller boot volume

share|improve this answer
1  
Welcome to Server Fault! Your answer suggests a workable solution to the question is available via another website. The Stack Exchange family of Q&A websites generally frowns on this type of answer because other websites may move, get deleted, or changed. Please read How do I write a good answer? and consider revising your answer to include the steps required to resolve the issue. And don't forget to take the site tour. –  Paul Apr 23 at 0:34
up vote 0 down vote accepted

It seems that it's no possible at this time:

https://forums.aws.amazon.com/message.jspa?messageID=177749

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.