hashicorp / packer-plugin-amazon

Packer plugin for Amazon AMI Builder

Home Page:https://www.packer.io/docs/builders/amazon

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ERROR: Couldn't find grub stages under /mnt/img-mnt

StepTNT opened this issue · comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

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

Overview of the Issue

I'm trying to build a Fedora-based AMI using the amazon-instance builder as I need this to only use the ephemeral storage.

I'm stuck at a point where I get the error in the title, and this happens during the ec2-bundle-vol command.

Reproduction Steps

Just try and create a random Fedora image that uses instance store instead of an EBS volume.

Packer version

1.9.4, via hashicorp/packer:light Docker image

Simplified Packer Template

# Base AMI to start from
 data "amazon-ami" "fedora_base" {
   most_recent = true
   owners      = ["125523088429"]
   region      = "${var.aws_region}"
 
   filters = {
     name                = "Fedora-Cloud-Base-38-*.x86_64-hvm*"
     architecture        = "x86_64"
     root-device-type    = "ebs"
     virtualization-type = "hvm"
   }
 }
...
source "amazon-instance" "amd64" {
  source_ami = "${data.amazon-ami.fedora_base.name}"
  ssh_user = "fedora"
  # SETTINGS
}
...
build {
  sources = [“source.amazon-instance.amd64”]

  # AMI TOOLS
  provisioner “shell” {
    inline = [
      “sudo dnf update -y”,
      “sudo dnf install -y wget unzip grub2 gdisk kpartx parted”,
      “sudo dnf module install ruby:3.1 -y”,
      “sudo gem install fileutils rexml grub”,
      “wget https://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip”,
      “sudo mkdir -p /usr/local/ec2",
      “sudo unzip -qq ec2-ami-tools.zip -d /usr/local/ec2”,
      “sudo bash -c ‘echo \“export EC2_AMITOOL_HOME=/usr/local/ec2/ec2-ami-tools-1.5.19\” >> /etc/profile.d/ec2-ami-tools.sh’“,
      “sudo bash -c ‘echo \“export PATH=/usr/local/ec2/ec2-ami-tools-1.5.19/bin:$PATH:\” >> /etc/profile.d/ec2-ami-tools.sh’”
    ]
  }

  # OTHER CUSTOMIZATIONS
}

Operating system and Environment details

Target AMi is based on Fedora 38.

Log Fragments and crash.log files

 ==> amazon-instance.amd64: Bundling the volume...
 ==> amazon-instance.amd64: Running: sudo -i -n ec2-bundle-vol -k /tmp/key.pem -u 166524993290 -c /tmp/cert.pem -r x86_64 -e /tmp/* -d /tmp -p image-1698331445 --batch --no-filter --grub-config /boot/grub2/grub.cfg
 2023/10/26 14:47:28 packer-plugin-amazon_v1.2.7_x5.0_linux_amd64 plugin: 2023/10/26 14:47:28 [DEBUG] Opening new ssh session
 2023/10/26 14:47:28 packer-plugin-amazon_v1.2.7_x5.0_linux_amd64 plugin: 2023/10/26 14:47:28 [DEBUG] starting remote command: sudo -i -n ec2-bundle-vol -k /tmp/key.pem -u 166524993290 -c /tmp/cert.pem -r x86_64 -e /tmp/* -d /tmp -p image-1698331445 --batch --no-filter --grub-config /boot/grub2/grub.cfg
     amazon-instance.amd64: Setting partition type to bundle "/" with...
     amazon-instance.amd64: Auto-detecting partition type for "/" at /dev/nvme0n1p5
     amazon-instance.amd64: Partition label detected using udev: "gpt"
     amazon-instance.amd64: Using partition type "gpt"
     amazon-instance.amd64: Copying / into the image file /tmp/image-1698331445...
     amazon-instance.amd64: Excluding:
     amazon-instance.amd64:      /proc
     amazon-instance.amd64:      /sys
     amazon-instance.amd64:      /dev
     amazon-instance.amd64:      /sys/kernel/security
     amazon-instance.amd64:      /dev/pts
     amazon-instance.amd64:      /sys/fs/cgroup
     amazon-instance.amd64:      /sys/fs/pstore
     amazon-instance.amd64:      /sys/fs/bpf
     amazon-instance.amd64:      /sys/kernel/config
     amazon-instance.amd64:      /
     amazon-instance.amd64:      /sys/fs/selinux
     amazon-instance.amd64:      /proc/sys/fs/binfmt_misc
     amazon-instance.amd64:      /dev/hugepages
     amazon-instance.amd64:      /dev/mqueue
     amazon-instance.amd64:      /sys/kernel/debug
     amazon-instance.amd64:      /sys/kernel/tracing
     amazon-instance.amd64:      /sys/fs/fuse/connections
     amazon-instance.amd64:      /run/credentials/systemd-sysctl.service
     amazon-instance.amd64:      /run/credentials/systemd-sysusers.service
     amazon-instance.amd64:      /run/credentials/systemd-tmpfiles-setup-dev.service
     amazon-instance.amd64:      /home
     amazon-instance.amd64:      /boot/efi
     amazon-instance.amd64:      /run/credentials/systemd-tmpfiles-setup.service
     amazon-instance.amd64:      /run/credentials/systemd-resolved.service
     amazon-instance.amd64:      /dev
     amazon-instance.amd64:      /media
     amazon-instance.amd64:      /mnt
     amazon-instance.amd64:      /proc
     amazon-instance.amd64:      /sys
     amazon-instance.amd64:      /tmp/cert.pem
     amazon-instance.amd64:      /tmp/image-1698331445
     amazon-instance.amd64:      /mnt/img-mnt
     amazon-instance.amd64: Installing GRUB on root device with gpt boot scheme
 ==> amazon-instance.amd64: ERROR: Couldn't find grub stages under /mnt/img-mnt
 2023/10/26 14:47:44 packer-plugin-amazon_v1.2.7_x5.0_linux_amd64 plugin: 2023/10/26 14:47:44 [ERROR] Remote command exited with '254': sudo -i -n ec2-bundle-vol -k /tmp/key.pem -u 166524993290 -c /tmp/cert.pem -r x86_64 -e /tmp/* -d /tmp -p image-1698331445 --batch --no-filter --grub-config /boot/grub2/grub.cfg
 ==> amazon-instance.amd64: details on what went wrong.
 ==> amazon-instance.amd64: 
 ==> amazon-instance.amd64: One common cause for this error is ec2-bundle-vol not being
 ==> amazon-instance.amd64: available on the target instance.
 ==> amazon-instance.amd64: Volume bundling failed. Please see the output above for more
 ==> amazon-instance.amd64: details on what went wrong.
 ==> amazon-instance.amd64: 
 ==> amazon-instance.amd64: One common cause for this error is ec2-bundle-vol not being
 ==> amazon-instance.amd64: available on the target instance.

Hey @StepTNT,

Thanks for opening this, this looks related to the AWS plugin more than Packer itself so I'll transfer the issue over there.

This being said, I'm not sure this is a Packer bug?

What's /mnt/img-mnt, is this a volume you manually created/mounted? I'm not certain what ec2-bundle-vol does, but it's not impossible that Fedora may need some extra customization in order to be able to bundle the rootFS into an AMI, I have not tested this.

Otherwise one consideration I may have, is this only happening with Fedora 38 instances? Do you experience this with other versions of the OS? What about other RPM-based distributions like CentOS?

Hey there, thanks for moving the issue.

I absolutely have no idea about what /img/img-mnt is, I only know that there's no such a directory in my base AMI and I don't think I'm supposed to create any since there are virtually no references to it anywhere online.

Unfortunately I cannot test with other OS versions/distros, but my guess is that ec2-bundle-vol expects to use the legacy GRUB (at least judging by AWS' docs) and Fedora 38 only has GRUB2.

I even tried overriding the bundle-vol command to specify a different GRUB config (pointing to the grub.cfg I have in the base AMI) but I still got the same error regardless.

Closing it, to create instance store AMIs there's a strict requirement to use GRUB 0.9 which is missing from the base AMI that I'm using.

Hi @StepTNT,

Thanks for confirming this, hope you find a solution to your problem!