So I did some further research and what I found is:

1) You need to recreate the official AMI by launching an instance and 
create an AMI from that since the official AMI dosen't seem to have public 
access to the associated snapshot.
2) CoreOS have a very different and complex partitioning. This requires 
"mount_partition": 9, to be set to mount the correct root partition. The 
following template works:

{
  "builders": [{
    "type": "amazon-chroot",
    "region": "eu-central-1",
    "ami_virtualization_type": "hvm",
    "source_ami": "ami-eab64b85",
    "ami_name": "packer-example {{timestamp}} coreos",
    "root_volume_size": 8,
    "mount_partition": 9,
    "chroot_mounts": [
         [ "proc", "proc", "/proc" ],
         [ "sysfs", "sysfs", "/sys" ],
         [ "bind", "/dev", "/dev" ],
         [ "devpts", "devpts", "/dev/pts" ]
    ]
  }]
}

But adding any provisioner crashes since there is no /bin or /usr/bin in 
the root partition. There are TWO partitions containing /usr (which /bin 
links to) USR-A and USR-B
USR-A is /dev/xvdb3 but trying to mount it in the chroot_mounts list fails 
with:
    amazon-chroot: Mounting: /usr
==> amazon-chroot: Error mounting: exit status 32
==> amazon-chroot: Stderr: mount: wrong fs type, bad option, bad superblock 
on /dev/xvdb3,
==> amazon-chroot:        missing codepage or helper program, or other error
==> amazon-chroot:
==> amazon-chroot:        In some cases useful info is found in syslog - try
==> amazon-chroot:        dmesg | tail or so.
==> amazon-chroot:
 
I think you should switch to amazon-ebs (it's not slow, you don't need 
chroot for speed) unless you want to learn every detail about CoreOS 
disk-layout, partitioning, and submit patches to Packer to get it to work 
for this very special case.


On Thursday, September 15, 2016 at 6:18:52 PM UTC+2, Sergey Esin wrote:
>
> Hi,
>
> I am newbie in Packer, would like to use Packer with amazon-chroot builder 
> to customize CoreOS-stable-1122.2.0-hvm (officia public AMI ID in EU 
> Ireland region: ami-e3d6ab90)
>
>
> Packer config is really simple:
>
> $ cat coreos-1122.2.0-hvm-aws-chroot.json
> {
>   "variables": {
>     "aws_access_key": "",
>     "aws_secret_key": ""
>   },
>   "builders": [{
>     "name": "build-aws-hmv",
>     "type": "amazon-chroot",
>     "access_key": "{{user `aws_access_key`}}",
>     "secret_key": "{{user `aws_secret_key`}}",
>     "ami_virtualization_type": "hvm",
>     "region": "eu-west-1",
>     "source_ami": "ami-0092eb73",
>     "ami_name": "packer-example {{timestamp}} coreos",
>     "tags": {
>         "component": "allapps",
>         "version": "404"
>     }
>   }],
>
>   "provisioners": [{
>     "type": "shell",
>     "inline": [
>       "docker pull centos:7"
>     ]
>   }]
> }
>
>
>
> $ ./packer validate coreos-1122.2.0-hvm-aws-chroot.json
> Template validated successfully.
>
>
>
>
>
> I am getting this error:
>
> $ ./packer build coreos-1122.2.0-hvm-aws-chroot.json
> build-aws-hmv output will be in this color.
>
> ==> build-aws-hmv: Prevalidating AMI Name...
> ==> build-aws-hmv: Gathering information about this EC2 instance...
> ==> build-aws-hmv: Error retrieving the ID of the instance Packer is 
> running on.
> ==> build-aws-hmv: Please verify Packer is running on a proper AWS EC2 
> instance.
> Build 'build-aws-hmv' errored: Error retrieving the ID of the instance 
> Packer is running on.
> Please verify Packer is running on a proper AWS EC2 instance.
>
> ==> Some builds didn't complete successfully and had errors:
> --> build-aws-hmv: Error retrieving the ID of the instance Packer is 
> running on.
> Please verify Packer is running on a proper AWS EC2 instance.
>
> ==> Builds finished but no artifacts were created.
>
>
>
>
> AMI "ami-0092eb73" that I am using in my config above was created the 
> following way:
>
> 1. Used original public CoreOS image (ami-e3d6ab90) to run instance.
> 2. Stopped the instance and took an AMI
> 3. Run the instance back and left it in running state
>
>
> What's wrong with my config?
>
>
> Do I understand right that in order to be able to use amazon-chroot 
> builder with Packer I have to leave my instance running?
>
>
>
> p.s. The following example.json works fine for me (so it's all fine with 
> AWS IAM permissions):
>
> $ cat example.json
> {
>   "variables": {
>     "aws_access_key": "",
>     "aws_secret_key": ""
>   },
>   "builders": [{
>     "type": "amazon-ebs",
>     "access_key": "{{user `aws_access_key`}}",
>     "secret_key": "{{user `aws_secret_key`}}",
>     "region": "eu-west-1",
>     "source_ami": "ami-f95ef58a",
>     "instance_type": "t2.micro",
>     "ssh_username": "ubuntu",
>     "ami_name": "packer-example {{timestamp}}"
>   }]
> }
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/packer-tool/05808450-403d-4428-bc6c-a7ea6b0e0613%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to