此处以 CentOS 官方 AMI 为模板,创建自定义的 AMI。

CentOS AWS AMI Cloud Images - The CentOS Project

创建磁盘快照

首先需要从现有的 EBS 卷创建一个快照。

aws ec2 create-snapshot \
    --volume-id vol-00e5b8d5f7212c538 \
    --description "CentOS Stream 10 AMI image"

确认快照状态

在注册 AMI 之前,必须确保快照状态为 completed

aws ec2 describe-snapshots \
    --snapshot-ids snap-0d9f1946db3320bb3 \
    --query Snapshots[].State \
    --output text

注册 AMI

此处沿用 CentOS 官方镜像的 Legacy BIOS 模式(兼容性最好),并明确指定为 x86_64 架构和 gp3 磁盘类型。

aws ec2 register-image \
   --name "CentOS Stream 10 AMI Image" \
   --description "CentOS Stream 10 AMI image 20251225" \
   --architecture x86_64 \
   --block-device-mappings "DeviceName=/dev/sda1,Ebs={SnapshotId=snap-0d9f1946db3320bb3,DeleteOnTermination=true,VolumeType=gp3}" \
   --root-device-name /dev/sda1 \
   --virtualization-type hvm \
   --ena-support \
   --boot-mode legacy-bios

参考资料

Create an Amazon EBS-backed AMI - Amazon Elastic Compute Cloud

Requirements to launch an EC2 instance in UEFI boot mode - Amazon Elastic Compute Cloud

最后修改:2025 年 12 月 29 日
如果觉得我的文章对你有用,请随意赞赏