我有一个有趣的要求,即运行 Packer amazon-chroot 构建一个临时运行的 Packer amazon-ebs 实例,因为生成的 AMI 有一些自定义的根块设备磁盘分区方案。我的 amazon-ebs 实例正在使用两个启动块设备映射,一个用于父 RHEL8 操作系统的根磁盘,以及一个辅助空设备,我想在其中使用 amazon-chroot 构建器加载具有自定义分区的 RHEL8 操作系统。
在调试模式下运行第一个父 Packer amazon-ebs 构建,我可以验证磁盘是否按预期存在于 EC2 实例上。当我在父 EC2 服务器上启动 Packer amazon-chroot build 时,我收到以下错误消息:
...
==> amibuild.amazon-chroot.source-ami: Pausing after run of step 'StepInstanceInfo'. Press enter to continue.
amibuild.amazon-chroot.source-ami: Found Image ID: ami-0238411fb452f8275
==> amibuild.amazon-chroot.source-ami: Pausing after run of step 'StepSourceAMIInfo'. Press enter to continue.
==> amibuild.amazon-chroot.source-ami: Checking the root device on source AMI...
==> amibuild.amazon-chroot.source-ami: Pausing after run of step 'StepCheckRootDevice'. Press enter to continue.
==> amibuild.amazon-chroot.source-ami: Pausing after run of step 'StepFlock'. Press enter to continue.
==> amibuild.amazon-chroot.source-ami: Pausing after run of step 'StepPrepareDevice'. Press enter to continue.
==> amibuild.amazon-chroot.source-ami: Creating the root volume...
==> amibuild.amazon-chroot.source-ami: Error creating root volume: InvalidSnapshot.NotFound: Snapshot does not exist
==> amibuild.amazon-chroot.source-ami: status code: 400, request id: f44d58c0-2b7f-4799-94da-371bf2b49651
...
搜索错误消息并没有为我在 amazon-chroot 构建器上测试提供太多可操作的更改。我正在寻找一些关于期望 amazon-chroot 构建器设置的指导,以便将初始 RHEL8 操作系统加载到 EC2 实例的辅助空磁盘上。
以下是我的amazon-ebs和amazon-chroot构建属性的相关设置
亚马逊-ebs
source "amazon-ebs" "parent" {
skip_create_ami = true
region = var.aws_region
source_ami = var.source_ami_id
ami_users = var.ami_users
snapshot_users = var.ami_users
source_ami_filter {
filters = {
name = var.source_ami_filter_name
architecture = "arm64"
root-device-type = "ebs"
state = "available"
virtualization-type = "hvm"
}
owners = [ var.source_ami_owners ]
most_recent = true
}
instance_type = "m7g.medium"
launch_block_device_mappings {
device_name = "/dev/sda1"
volume_type = var.volume_type
volume_size = var.launch_block_device_mappings_volume_size
delete_on_termination = true
}
launch_block_device_mappings {
device_name = "/dev/sdf"
volume_type = var.volume_type
volume_size = var.launch_block_device_mappings_volume_size
delete_on_termination = true
}
...
亚马逊chroot
source "amazon-chroot" "source-ami" {
region = var.aws_region
source_ami = var.source_ami_id
ami_users = var.ami_users
snapshot_users = var.ami_users
source_ami_filter {
filters = {
name = var.source_ami_filter_name
architecture = "arm64"
root-device-type = "ebs"
state = "available"
virtualization-type = "hvm"
}
owners = [ var.source_ami_owners ]
most_recent = true
}
nvme_device_path = "/dev/nvme1n1p"
device_path = "/dev/sdf"
root_device_name = "/dev/sda1"
root_volume_size = var.launch_block_device_mappings_volume_size
ami_block_device_mappings {
device_name = "/dev/sdf"
volume_type = var.volume_type
volume_size = var.launch_block_device_mappings_volume_size
delete_on_termination = true
}
...
注意,我正在为父 EC2 实例使用
m7g.medium
实例类型,它公开了 NVMe 驱动器。我可以通过以下方式验证驱动器是否符合我在父 EC2 实例上的预期:
[root@ip-172-31-77-18 packer]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 10G 0 disk
├─nvme0n1p1 259:1 0 200M 0 part /boot/efi
├─nvme0n1p2 259:2 0 512M 0 part /boot
└─nvme0n1p3 259:3 0 9.3G 0 part /
nvme1n1 259:4 0 10G 0 disk
根据 Packer 文档,我需要设置定义的
nvme_device_path
属性,但我不清楚其他设置。
我还可以在日志中验证 amazon-ebs 和 amazon-chroot 构建是否使用相同的源 AMI:
==> amibuild.amazon-chroot.source-ami: Gathering information about this EC2 instance...
==> amibuild.amazon-chroot.source-ami: Pausing after run of step 'StepInstanceInfo'. Press enter to continue.
amibuild.amazon-chroot.source-ami: Found Image ID: ami-0238411fb452f8275
和
==> amibuild.amazon-ebs.source-ami: Pausing after run of step 'StepPreValidate'. Press enter to continue.
amibuild.amazon-ebs.source-ami: Found Image ID: ami-0238411fb452f8275
只是不确定
Error creating root volume: InvalidSnapshot.NotFound: Snapshot does not exist
错误消息的来源或它指的是什么。