Set the boot mode of an AMI - Amazon Elastic Compute Cloud
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Set the boot mode of an AMI

When you create an AMI using the register-image command, you can set the boot mode of the AMI to either uefi or legacy-bios.

To convert an existing Legacy BIOS-based instance to UEFI, or an existing UEFI-based instance to Legacy BIOS, you need to perform a number of steps: First, modify the instance's volume and operating system to support the selected boot mode. Then, create a snapshot of the volume. Finally, use register-image to create the AMI using the snapshot.

You can't set the boot mode of an AMI using the create-image command. With create-image, the AMI inherits the boot mode of the EC2 instance used for creating the AMI. For example, if you create an AMI from an EC2 instance running on Legacy BIOS, the AMI boot mode will be configured as legacy-bios.

Warning

Before proceeding with these steps, you must first make suitable modifications to the instance's volume and operating system to support booting via the selected boot mode; otherwise, the resulting AMI will not be usable. The modifications that are required are operating system-specific. For more information, see the manual for your operating system.

To set the boot mode of an AMI (Amazon CLI version 1.19.34 and later and version 2.1.32 and later)

  1. Make suitable modifications to the instance's volume and operating system to support booting via the selected boot mode. The modifications that are required are operating system-specific. For more information, see the manual for your operating system.

    Note

    If you don't perform this step, the AMI will not be usable.

  2. To find the volume ID of the instance, use the describe-instances command. You'll create a snapshot of this volume in the next step.

    aws ec2 describe-instances --region us-east-1 --instance-ids i-1234567890abcdef0

    Expected output

    ... "BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "AttachTime": "", "DeleteOnTermination": true, "Status": "attached", "VolumeId": "vol-1234567890abcdef0" } } ...
  3. To create a snapshot of the volume, use the create-snapshot command. Use the volume ID from the previous step.

    aws ec2 create-snapshot --region us-east-1 --volume-id vol-1234567890abcdef0 --description "add text"

    Expected output

    { "Description": "add text", "Encrypted": false, "OwnerId": "123", "Progress": "", "SnapshotId": "snap-01234567890abcdef", "StartTime": "", "State": "pending", "VolumeId": "vol-1234567890abcdef0", "VolumeSize": 30, "Tags": [] }
  4. Note the snapshot ID in the output from the previous step.

  5. Wait until the snapshot creation is completed before going to the next step. To query the state of the snapshot, use the describe-snapshots command.

    aws ec2 describe-snapshots --region us-east-1 --snapshot-ids snap-01234567890abcdef

    Example output

    { "Snapshots": [ { "Description": "This is my snapshot", "Encrypted": false, "VolumeId": "vol-049df61146c4d7901", "State": "completed", "VolumeSize": 8, "StartTime": "2019-02-28T21:28:32.000Z", "Progress": "100%", "OwnerId": "012345678910", "SnapshotId": "snap-01234567890abcdef", ...
  6. To create a new AMI, use the register-image command. Use the snapshot ID that you noted in the earlier step. To set the boot mode to UEFI, add the --boot-mode uefi parameter to the command.

    aws ec2 register-image \ --region us-east-1 \ --description "add description" \ --name "add name" \ --block-device-mappings "DeviceName=/dev/sda1,Ebs={SnapshotId=snap-01234567890abcdef,DeleteOnTermination=true}" \ --architecture x86_64 \ --root-device-name /dev/sda1 \ --virtualization-type hvm \ --ena-support \ --boot-mode uefi

    Expected output

    { "ImageId": "ami-new_ami_123" }
  7. To verify that the newly-created AMI has the boot mode that you specified in the previous step, use the describe-images command.

    aws ec2 describe-images --region us-east-1 --image-id ami-new_ami_123

    Expected output

    { "Images": [ { "Architecture": "x86_64", "CreationDate": "2021-01-06T14:31:04.000Z", "ImageId": "ami-new_ami_123", "ImageLocation": "", ... "BootMode": "uefi" } ] }
  8. Launch a new instance using the newly-created AMI. All new instances created from this AMI will inherit the same boot mode.

  9. To verify that the new instance has the expected boot mode, use the describe-instances command.