Creating EBS Volume from Snapshot to Bake AMI

31 views
Skip to first unread message

nnat...@ucsd.edu

unread,
Dec 5, 2018, 2:17:18 PM12/5/18
to Packer
I have a source AMI and I want to bake a new AMI with some additional packages. I have a snapshot with scripts to install these packages. I was wondering what combination of builders/provisioners/etc I would use to create a volume from this snapshot and then install packages to a different volume (root volume). I would then need to unmount the additional volume created from the snapshot so it is not baked into the AMI as well. 

My guess was to use an ' amazon-ebsvolume ' builder to create a volume from the snapshot, then use ' amazon-ebs ' builder to actually create the AMI. I am slightly confused, however, on how I would order the events so the AMI created would only have the root volume baked in. I was looking at using ' launch_block_device_mappings '.  

Is this easily done in packer? In terraform, I can see how to create a volume from a snapshot easily and with packer I see how to create an AMI given a source AMI. Is there a way to do both cleanly in packer? 

Alvaro Miranda Aguilera

unread,
Dec 5, 2018, 3:47:49 PM12/5/18
to packe...@googlegroups.com
Hello

How are you creating these snapshots?

Maybe you can add an extra step and create an AMI with the snapshots, and keep packer template more clean, and just use amazon-ebs



Alvaro

--
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/76673db5-2111-4159-b948-f78aa7d06bce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Alvaro

Rickard von Essen

unread,
Dec 5, 2018, 4:09:07 PM12/5/18
to packe...@googlegroups.com
You should use Packer for this. amazon-ebs should be enough for this. If you are new to packer I suggest you start with that and ignore your extra volume first until you get a hang of it. Then it's just adding it to the launch_block_device_mappings and drop it in the ami_block_device_mappings so it isn't added to the AMI.

--

Neil Natarajan

unread,
Dec 5, 2018, 4:21:39 PM12/5/18
to packe...@googlegroups.com
Alvaro - It is just one snapshot that has some scripts. It was manually created once. I need to use these scripts to install packages so I bake a new EBS backed AMI.

Rickard - Could you explain the usage of launch_block_device_mappings and ami_block_device_mappings? I am confused as to how I would be using both in order to avoid the snapshot containing the Scripts getting added to the AMI. 

Rickard von Essen

unread,
Dec 7, 2018, 2:04:39 AM12/7/18
to packe...@googlegroups.com
Example:
  "launch_block_device_mappings": [
    {
      "device_name": "/dev/sdb",
      "volume_type": "gp2",
      "snapshot_id": "snap-XXXX",
      "delete_on_termination": true
    }
  ],
  "ami_block_device_mappings": [
    {
      "device_name": "/dev/sdb",
      "no_device": true
    }
  ]

The launch bdm will create a volume from you snapshot that will be available on your instance (you might have to mount it).

The AMI bdm takes the same device and sets no_device which excludes it from the AMI. 

Reply all
Reply to author
Forward
0 new messages