github.com/kimor79/packer@v0.8.7-0.20151221212622-d507b18eb4cf/website/source/docs/builders/amazon-chroot.html.markdown (about) 1 --- 2 description: | 3 The `amazon-chroot` Packer builder is able to create Amazon AMIs backed by an 4 EBS volume as the root device. For more information on the difference between 5 instance storage and EBS-backed instances, storage for the root device section 6 in the EC2 documentation. 7 layout: docs 8 page_title: 'Amazon AMI Builder (chroot)' 9 ... 10 11 # AMI Builder (chroot) 12 13 Type: `amazon-chroot` 14 15 The `amazon-chroot` Packer builder is able to create Amazon AMIs backed by an 16 EBS volume as the root device. For more information on the difference between 17 instance storage and EBS-backed instances, see the ["storage for the root 18 device" section in the EC2 19 documentation](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ComponentsAMIs.html#storage-for-the-root-device). 20 21 The difference between this builder and the `amazon-ebs` builder is that this 22 builder is able to build an EBS-backed AMI without launching a new EC2 instance. 23 This can dramatically speed up AMI builds for organizations who need the extra 24 fast build. 25 26 \~> **This is an advanced builder** If you're just getting started with 27 Packer, we recommend starting with the [amazon-ebs 28 builder](/docs/builders/amazon-ebs.html), which is much easier to use. 29 30 The builder does *not* manage AMIs. Once it creates an AMI and stores it in your 31 account, it is up to you to use, delete, etc. the AMI. 32 33 ## How Does it Work? 34 35 This builder works by creating a new EBS volume from an existing source AMI and 36 attaching it into an already-running EC2 instance. Once attached, a 37 [chroot](http://en.wikipedia.org/wiki/Chroot) is used to provision the system 38 within that volume. After provisioning, the volume is detached, snapshotted, and 39 an AMI is made. 40 41 Using this process, minutes can be shaved off the AMI creation process because a 42 new EC2 instance doesn't need to be launched. 43 44 There are some restrictions, however. The host EC2 instance where the volume is 45 attached to must be a similar system (generally the same OS version, kernel 46 versions, etc.) as the AMI being built. Additionally, this process is much more 47 expensive because the EC2 instance must be kept running persistently in order to 48 build AMIs, whereas the other AMI builders start instances on-demand to build 49 AMIs as needed. 50 51 ## Configuration Reference 52 53 There are many configuration options available for the builder. They are 54 segmented below into two categories: required and optional parameters. Within 55 each category, the available configuration keys are alphabetized. 56 57 In addition to the options listed here, a 58 [communicator](/docs/templates/communicator.html) can be configured for this 59 builder. 60 61 ### Required: 62 63 - `access_key` (string) - The access key used to communicate with AWS. [Learn 64 how to set this.](/docs/builders/amazon.html#specifying-amazon-credentials) 65 66 - `ami_name` (string) - The name of the resulting AMI that will appear when 67 managing AMIs in the AWS console or via APIs. This must be unique. To help 68 make this unique, use a function like `timestamp` (see [configuration 69 templates](/docs/templates/configuration-templates.html) for more info) 70 71 - `secret_key` (string) - The secret key used to communicate with AWS. [Learn 72 how to set this.](/docs/builders/amazon.html#specifying-amazon-credentials) 73 74 - `source_ami` (string) - The source AMI whose root volume will be copied and 75 provisioned on the currently running instance. This must be an EBS-backed 76 AMI with a root volume snapshot that you have access to. 77 78 ### Optional: 79 80 - `ami_description` (string) - The description to set for the 81 resulting AMI(s). By default this description is empty. 82 83 - `ami_groups` (array of strings) - A list of groups that have access to 84 launch the resulting AMI(s). By default no groups have permission to launch 85 the AMI. `all` will make the AMI publicly accessible. 86 87 - `ami_product_codes` (array of strings) - A list of product codes to 88 associate with the AMI. By default no product codes are associated with 89 the AMI. 90 91 - `ami_regions` (array of strings) - A list of regions to copy the AMI to. 92 Tags and attributes are copied along with the AMI. AMI copying takes time 93 depending on the size of the AMI, but will generally take many minutes. 94 95 - `ami_users` (array of strings) - A list of account IDs that have access to 96 launch the resulting AMI(s). By default no additional users other than the 97 user creating the AMI has permissions to launch it. 98 99 - `ami_virtualization_type` (string) - The type of virtualization for the AMI 100 you are building. This option is required to register HVM images. Can be 101 "paravirtual" (default) or "hvm". 102 103 - `chroot_mounts` (array of array of strings) - This is a list of additional 104 devices to mount into the chroot environment. This configuration parameter 105 requires some additional documentation which is in the "Chroot Mounts" 106 section below. Please read that section for more information on how to 107 use this. 108 109 - `command_wrapper` (string) - How to run shell commands. This defaults 110 to "{{.Command}}". This may be useful to set if you want to set 111 environmental variables or perhaps run it with `sudo` or so on. This is a 112 configuration template where the `.Command` variable is replaced with the 113 command to be run. 114 115 - `copy_files` (array of strings) - Paths to files on the running EC2 instance 116 that will be copied into the chroot environment prior to provisioning. This 117 is useful, for example, to copy `/etc/resolv.conf` so that DNS lookups work. 118 119 - `device_path` (string) - The path to the device where the root volume of the 120 source AMI will be attached. This defaults to "" (empty string), which 121 forces Packer to find an open device automatically. 122 123 - `enhanced_networking` (boolean) - Enable enhanced 124 networking (SriovNetSupport) on HVM-compatible AMIs. If true, add 125 `ec2:ModifyInstanceAttribute` to your AWS IAM policy. 126 127 - `force_deregister` (boolean) - Force Packer to first deregister an existing 128 AMI if one with the same name already exists. Default `false`. 129 130 - `mount_path` (string) - The path where the volume will be mounted. This is 131 where the chroot environment will be. This defaults to 132 `packer-amazon-chroot-volumes/{{.Device}}`. This is a configuration template 133 where the `.Device` variable is replaced with the name of the device where 134 the volume is attached. 135 136 - `mount_options` (array of strings) - Options to supply the `mount` command 137 when mounting devices. Each option will be prefixed with `-o` and supplied 138 to the `mount` command ran by Packer. Because this command is ran in a 139 shell, user discrestion is advised. See [this manual page for the mount 140 command](http://linuxcommand.org/man_pages/mount8.html) for valid file 141 system specific options 142 143 - `root_volume_size` (integer) - The size of the root volume for the chroot 144 environment, and the resulting AMI 145 146 - `tags` (object of key/value strings) - Tags applied to the AMI. 147 148 ## Basic Example 149 150 Here is a basic example. It is completely valid except for the access keys: 151 152 ``` {.javascript} 153 { 154 "type": "amazon-chroot", 155 "access_key": "YOUR KEY HERE", 156 "secret_key": "YOUR SECRET KEY HERE", 157 "source_ami": "ami-e81d5881", 158 "ami_name": "packer-amazon-chroot {{timestamp}}" 159 } 160 ``` 161 162 ## Chroot Mounts 163 164 The `chroot_mounts` configuration can be used to mount additional devices within 165 the chroot. By default, the following additional mounts are added into the 166 chroot by Packer: 167 168 - `/proc` (proc) 169 - `/sys` (sysfs) 170 - `/dev` (bind to real `/dev`) 171 - `/dev/pts` (devpts) 172 - `/proc/sys/fs/binfmt_misc` (binfmt\_misc) 173 174 These default mounts are usually good enough for anyone and are sane defaults. 175 However, if you want to change or add the mount points, you may using the 176 `chroot_mounts` configuration. Here is an example configuration: 177 178 ``` {.javascript} 179 { 180 "chroot_mounts": [ 181 ["proc", "proc", "/proc"], 182 ["bind", "/dev", "/dev"] 183 ] 184 } 185 ``` 186 187 `chroot_mounts` is a list of a 3-tuples of strings. The three components of the 188 3-tuple, in order, are: 189 190 - The filesystem type. If this is "bind", then Packer will properly bind the 191 filesystem to another mount point. 192 193 - The source device. 194 195 - The mount directory. 196 197 ## Parallelism 198 199 A quick note on parallelism: it is perfectly safe to run multiple *separate* 200 Packer processes with the `amazon-chroot` builder on the same EC2 instance. In 201 fact, this is recommended as a way to push the most performance out of your AMI 202 builds. 203 204 Packer properly obtains a process lock for the parallelism-sensitive parts of 205 its internals such as finding an available device. 206 207 ## Gotchas 208 209 One of the difficulties with using the chroot builder is that your provisioning 210 scripts must not leave any processes running or packer will be unable to unmount 211 the filesystem. 212 213 For debian based distributions you can setup a 214 [policy-rc.d](http://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt) 215 file which will prevent packages installed by your provisioners from starting 216 services: 217 218 ``` {.javascript} 219 { 220 "type": "shell", 221 "inline": [ 222 "echo '#!/bin/sh' > /usr/sbin/policy-rc.d", 223 "echo 'exit 101' >> /usr/sbin/policy-rc.d", 224 "chmod a+x /usr/sbin/policy-rc.d" 225 ] 226 }, 227 228 // ... 229 230 { 231 "type": "shell", 232 "inline": [ 233 "rm -f /usr/sbin/policy-rc.d" 234 ] 235 } 236 ```