amazon-ebs ami shrink to fit

37 views
Skip to first unread message

sfoster

unread,
Sep 3, 2018, 11:48:17 AM9/3/18
to Packer
Hello,

I'm working on a windows vm build and want to move to the amazon-ebs builder (currently I use a different builder with the amazon-import post-processor). I'm having trouble achieving a reasonable ami size. The provisioning is quite heavy, and leaves many gigs of cached files, installers and logs. I use launch_device_block_mappings to give myself enough disk overhead to carry out the provisioning but I can't figure out how to shrink the size of the volume to fit once I've cleaned up all of the clutter. From what I can tell, there is a manual way of doing this but it's a bit involved.

Does the amazon-ebs builder have a way to shrink the volume at the end of the build?

Rickard von Essen

unread,
Sep 3, 2018, 2:26:54 PM9/3/18
to packe...@googlegroups.com
Hi,

I don't know much about Windows but the way I would do it with a unix system is:

1) Use launch_device_mappings to attach an additional device
2) Mount it temporarly at say /mnt/tmp
3) Ensure that all clutter ends up on it
4) Unmount it
5) Use ami_device_mappings with no_device: true to not include the additional device in the final AMI

I haven't tried this, but I'm pretty confident that it should work. I guess the same procedure should be possible for Windows. 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/dd269a9f-b5c5-45e3-9974-34955035b2c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JP Toto

unread,
Sep 4, 2018, 8:58:57 AM9/4/18
to packe...@googlegroups.com
Matt Wrock has done a lot of work on this for Windows. https://github.com/mwrock/packer-templates He's got some great Powershell scripts he runs to help reduce the size of his Windows images. I haven't tried these specifically using the amazon-ebs builder but the idea is the same. Specifically he's got a provisioner script he runs that removes a bunch of features, cleans out logs and caches, and zeroes out the rest of the empty disk https://github.com/mwrock/packer-templates/blob/master/scripts/provision.ps1 


For more options, visit https://groups.google.com/d/optout.


--
JP Toto   |   james....@gmail.com   |   http://jptoto.jp   |   @jptoto

Rickard von Essen

unread,
Sep 4, 2018, 2:08:06 PM9/4/18
to packe...@googlegroups.com
Matt's work is splendid, but be sure to understand which things applies to AWS. For example zeroing the disk doesn't do anything on an EBS volume, that is only useful when you want to shrink the size of the file you distribute for a thin provisioning disk.

JP Toto

unread,
Sep 4, 2018, 2:23:41 PM9/4/18
to packe...@googlegroups.com
Ahh right on. Was getting my disk mechanics confused between hypervisors :)


For more options, visit https://groups.google.com/d/optout.

sfoster

unread,
Sep 5, 2018, 5:58:27 AM9/5/18
to Packer

On Tuesday, September 4, 2018 at 1:58:57 PM UTC+1, Jp Toto wrote:
Matt Wrock has done a lot of work on this for Windows. https://github.com/mwrock/packer-templates He's got some great Powershell scripts he runs to help reduce the size of his Windows images. I haven't tried these specifically using the amazon-ebs builder but the idea is the same. Specifically he's got a provisioner script he runs that removes a bunch of features, cleans out logs and caches, and zeroes out the rest of the empty disk https://github.com/mwrock/packer-templates/blob/master/scripts/provision.ps1 

--
JP Toto   |   james....@gmail.com   |   http://jptoto.jp   |   @jptoto


Thanks for the link, some nice techniques in there.



On Tuesday, September 4, 2018 at 7:08:06 PM UTC+1, Rickard von Essen wrote:
Matt's work is splendid, but be sure to understand which things applies to AWS. For example zeroing the disk doesn't do anything on an EBS volume, that is only useful when you want to shrink the size of the file you distribute for a thin provisioning disk.

I guess the real objective I have is to minimize startup time of VMs by reducing the amount of data that needs to be transferred. If the storage of the EBS volumes is related to their contents rather than their capacity, then cleaning them might be worthwhile.
I see a quote in the AWS docs that hints at this being the case, but I don't know for sure. Reducing the actual size would have the bonus of being a bit cheaper.
Reduce start time by deleting temporary files, defragmenting your hard drive, and zeroing out free space
 
 
Reply all
Reply to author
Forward
0 new messages