hashicorp / packer-plugin-amazon

Packer plugin for Amazon AMI Builder
https://www.packer.io/docs/builders/amazon
Mozilla Public License 2.0
76 stars 112 forks source link

Building with amazon-chroot: unable to unmount #333

Open hc-github-team-packer opened 1 year ago

hc-github-team-packer commented 1 year ago

This issue was originally opened by @anoopsaxena in https://github.com/hashicorp/packer/issues/12134 and has been migrated to this repository. The original issue description is below.


Community Note

When filing a bug, please include the following headings if possible. Any example text in this template can be deleted.

Overview of the Issue

A paragraph or two about the issue you're experiencing.

Reproduction Steps

Steps to reproduce this issue

Packer version

From packer version

Simplified Packer Template

If the file is longer than a few dozen lines, please include the URL to the gist of the log or use the Github detailed format instead of posting it directly in the issue.

Operating system and Environment details

OS, Architecture, and any other information you can provide about the environment.

Log Fragments and crash.log files

Include appropriate log fragments. If the log is longer than a few dozen lines, please include the URL to the gist of the log or use the Github detailed format instead of posting it directly in the issue.

Set the env var PACKER_LOG=1 for maximum log detail.

We're trying to build a docker image using packer in a GIt jenkins Pipeline and build fails while mounting the volume, refer the log : amazon-chroot: Prevalidating AMI Name: xx-centos-7-docker-1.0.111-snapshot amazon-chroot: gathering information about this ec2 instance... amazon-chroot: Found Image Id: ami-xxxxx amazon-chroot: Checking the root device on source AMI... amazon-chroot: Creating the root volume... amazon-chroot: Attaching the root volume to /dev/sdf amazon-chroot: Mounting the root device... amazon-chroot: Error mounting root volume: exit status 1 amazon-chroot: stderr: mount: only root can use "--options" option amazon-chroot: Detaching EBS volume... amazon-chroot: Deleting the created EBS volume...

Is there a way to specify in Packer to mount the volume, Kindly suggest.,

lbajolet-hashicorp commented 1 year ago

Hi @anoopsaxena,

From what I can see in the logs, this is mostly because of a permission issue that the build fails. If you are using chroot, this means that you already have an EC2 instance to run your builds on, do you run the build with a user that has the permission to mount/unmount the volume you are building your AMI on? As the logs suggest, you have to invoke Packer from the instance with a root account, or with sudo if you don't want to, otherwise the OS will reject your build since mount permissions require you to run the command as the superuser.