github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/website/source/docs/builders/amazon-chroot.html.md (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](https://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](https://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_partition` (integer) - The partition number containing the /
   137      partition. By default this is the first partition of the volume.
   138  
   139  -   `mount_options` (array of strings) - Options to supply the `mount` command
   140      when mounting devices. Each option will be prefixed with `-o` and supplied
   141      to the `mount` command ran by Packer. Because this command is ran in a
   142      shell, user discrestion is advised. See [this manual page for the mount
   143      command](http://linuxcommand.org/man_pages/mount8.html) for valid file
   144      system specific options
   145  
   146  -   `root_volume_size` (integer) - The size of the root volume for the chroot
   147      environment, and the resulting AMI
   148  
   149  -   `tags` (object of key/value strings) - Tags applied to the AMI.
   150  
   151  ## Basic Example
   152  
   153  Here is a basic example. It is completely valid except for the access keys:
   154  
   155  ``` {.javascript}
   156  {
   157    "type": "amazon-chroot",
   158    "access_key": "YOUR KEY HERE",
   159    "secret_key": "YOUR SECRET KEY HERE",
   160    "source_ami": "ami-e81d5881",
   161    "ami_name": "packer-amazon-chroot {{timestamp}}"
   162  }
   163  ```
   164  
   165  ## Chroot Mounts
   166  
   167  The `chroot_mounts` configuration can be used to mount additional devices within
   168  the chroot. By default, the following additional mounts are added into the
   169  chroot by Packer:
   170  
   171  -   `/proc` (proc)
   172  -   `/sys` (sysfs)
   173  -   `/dev` (bind to real `/dev`)
   174  -   `/dev/pts` (devpts)
   175  -   `/proc/sys/fs/binfmt_misc` (binfmt\_misc)
   176  
   177  These default mounts are usually good enough for anyone and are sane defaults.
   178  However, if you want to change or add the mount points, you may using the
   179  `chroot_mounts` configuration. Here is an example configuration:
   180  
   181  ``` {.javascript}
   182  {
   183    "chroot_mounts": [
   184      ["proc", "proc", "/proc"],
   185      ["bind", "/dev", "/dev"]
   186    ]
   187  }
   188  ```
   189  
   190  `chroot_mounts` is a list of a 3-tuples of strings. The three components of the
   191  3-tuple, in order, are:
   192  
   193  -   The filesystem type. If this is "bind", then Packer will properly bind the
   194      filesystem to another mount point.
   195  
   196  -   The source device.
   197  
   198  -   The mount directory.
   199  
   200  ## Parallelism
   201  
   202  A quick note on parallelism: it is perfectly safe to run multiple *separate*
   203  Packer processes with the `amazon-chroot` builder on the same EC2 instance. In
   204  fact, this is recommended as a way to push the most performance out of your AMI
   205  builds.
   206  
   207  Packer properly obtains a process lock for the parallelism-sensitive parts of
   208  its internals such as finding an available device.
   209  
   210  ## Gotchas
   211  
   212  One of the difficulties with using the chroot builder is that your provisioning
   213  scripts must not leave any processes running or packer will be unable to unmount
   214  the filesystem.
   215  
   216  For debian based distributions you can setup a
   217  [policy-rc.d](http://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt)
   218  file which will prevent packages installed by your provisioners from starting
   219  services:
   220  
   221  ``` {.javascript}
   222  {
   223    "type": "shell",
   224    "inline": [
   225      "echo '#!/bin/sh' > /usr/sbin/policy-rc.d",
   226      "echo 'exit 101' >> /usr/sbin/policy-rc.d",
   227      "chmod a+x /usr/sbin/policy-rc.d"
   228    ]
   229  },
   230  
   231  // ...
   232  
   233  {
   234    "type": "shell",
   235    "inline": [
   236      "rm -f /usr/sbin/policy-rc.d"
   237    ]
   238  }
   239  ```