Creating an Amazon EBS-Backed Linux AMI
To create an Amazon EBS-backed Linux AMI, start from an instance that you've launched from an existing Amazon EBS-backed Linux AMI. After you've customized the instance to suit your needs, create and register a new AMI, which you can use to launch new instances with these customizations. For more information about creating an Amazon EBS-backed Windows AMI, see Creating an Amazon EBS-Backed Windows AMI in the Amazon EC2 User Guide for Microsoft Windows Instances.
The procedures described below work for Amazon EC2 instances backed by encrypted Amazon EBS volumes (including the root volume) as well as for unencrypted volumes.
The AMI creation process is different for instance store-backed AMIs. For more information about the differences between Amazon EBS-backed and instance store-backed instances, and how to determine the root device type for your instance, see Storage for the Root Device. For more information about creating an instance store-backed Linux AMI, see Creating an Instance Store-Backed Linux AMI.
Overview of Creating Amazon EBS-Backed AMIs
First, launch an instance from an AMI that's similar to the AMI that you'd like to create. You can connect to your instance and customize it. When the instance is configured correctly, ensure data integrity by stopping the instance before you create an AMI, then create the image. When you create an Amazon EBS-backed AMI, we automatically register it for you.
Amazon EC2 powers down the instance before creating the AMI to ensure that everything on the instance is stopped and in a consistent state during the creation process. If you're confident that your instance is in a consistent state appropriate for AMI creation, you can tell Amazon EC2 not to power down and reboot the instance. Some file systems, such as XFS, can freeze and unfreeze activity, making it safe to create the image without rebooting the instance.
During the AMI-creation process, Amazon EC2 creates snapshots of your instance's root volume and any other EBS volumes attached to your instance. If any volumes attached to the instance are encrypted, the new AMI only launches successfully on instances that support Amazon EBS encryption. For more information, see Amazon EBS Encryption.
Depending on the size of the volumes, it can take several minutes for the AMI-creation process to complete (sometimes up to 24 hours).You may find it more efficient to create snapshots of your volumes prior to creating your AMI. This way, only small, incremental snapshots need to be created when the AMI is created, and the process completes more quickly (the total time for snapshot creation remains the same). For more information, see Creating an Amazon EBS Snapshot.
After the process completes, you have a new AMI and snapshot created from the root volume of the instance. When you launch an instance using the new AMI, we create a new EBS volume for its root volume using the snapshot. Both the AMI and the snapshot incur charges to your account until you delete them. For more information, see Deregistering Your AMI.
If you add instance-store volumes or EBS volumes to your instance in addition to the root device volume, the block device mapping for the new AMI contains information for these volumes, and the block device mappings for instances that you launch from the new AMI automatically contain information for these volumes. The instance-store volumes specified in the block device mapping for the new instance are new and don't contain any data from the instance store volumes of the instance you used to create the AMI. The data on EBS volumes persists. For more information, see Block Device Mapping.
Creating a Linux AMI from an Instance
You can create an AMI using the AWS Management Console or the command line. The following diagram summarizes the process for creating an Amazon EBS-backed AMI from a running EC2 instance. Start with an existing AMI, launch an instance, customize it, create a new AMI from it, and finally launch an instance of your new AMI. The steps in the following diagram match the steps in the procedure below.
To create an AMI from an instance using the console
Select an appropriate EBS-backed AMI to serve as a starting point for your new AMI, and configure it as needed prior to launch. For more information, see Launching an Instance.
Choose Launch to launch an instance of the EBS-backed AMI that you've selected. Accept the default values as you step through the wizard. For more information, see Launching an Instance.
While the instance is running, connect to it.
You can perform any of the following actions on your instance to customize it for your needs:
Install software and applications
Reduce start time by deleting temporary files, defragmenting your hard drive, and zeroing out free space
Attach additional Amazon EBS volumes
(Optional) Create snapshots of all the volumes attached to your instance. For more information about creating snapshots, see Creating an Amazon EBS Snapshot.
In the navigation pane, choose Instances and select your instance. Choose Actions, Image, and Create Image.
If this option is disabled, your instance isn't an Amazon EBS-backed instance.
In the Create Image dialog box, specify values for the following fields, and then choose Create Image.
A unique name for the image.
(Optional) A description of the image, up to 255 characters.
By default, Amazon EC2 shuts down the instance, takes snapshots of any attached volumes, creates and registers the AMI, and then reboots the instance. Choose No reboot if you don't want your instance to be shut down.
If you choose No reboot, we can't guarantee the file system integrity of the created image.
You can modify the root volume, Amazon EBS volumes, and instance store volumes as follows:
To change the size of the root volume, locate the Root volume in the Type column, and fill in the Size field.
To suppress an Amazon EBS volume specified by the block device mapping of the AMI used to launch the instance, locate the EBS volume in the list and choose Delete.
To add an Amazon EBS volume, choose Add New Volume, Type, and EBS, and fill in the fields. When you then launch an instance from your new AMI, these additional volumes are automatically attached to the instance. Empty volumes must be formatted and mounted. Volumes based on a snapshot must be mounted.
To suppress an instance store volume specified by the block device mapping of the AMI used to launch the instance, locate the volume in the list and choose Delete.
To add an instance store volume, choose Add New Volume, Type, and Instance Store, and select a device name from the Device list. When you launch an instance from your new AMI, these additional volumes are automatically initialized and mounted. These volumes don't contain data from the instance store volumes of the running instance from which you based your AMI.
While your AMI is being created, you can choose AMIs in the navigation pane to view its status. Initially this will be
pending. After a few minutes the status should change to
(Optional) Choose Snapshots in the navigation pane to view the snapshot that was created for the new AMI. When you launch an instance from this AMI, we use this snapshot to create its root device volume.
Launch an instance from your new AMI. For more information, see Launching an Instance.
The new running instance contains all of the customizations you applied in previous steps.
Creating a Linux AMI from a Snapshot
If you have a snapshot of the root device volume of an instance, you can create an AMI from this snapshot using the AWS Management Console or the command line.
Some Linux distributions, such as Red Hat Enterprise Linux (RHEL) and SUSE Linux
Enterprise Server (SLES), use the Amazon EC2
associated with an AMI to verify subscription status for package updates. Creating
an AMI from an EBS snapshot does not maintain this billing code, and subsequent
instances launched from such an AMI will not be able to connect to package update
Similarly, although you can create a Windows AMI from a snapshot, you can't successfully launch an instance from the AMI.
In general, AWS advises against manually creating AMIs from snapshots.
For more information about creating Windows AMIs or AMIs for Linux operating systems that must retain AMI billing codes to work properly, see Creating a Linux AMI from an Instance.
To create an AMI from a snapshot using the console
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
In the navigation pane, under Elastic Block Store, choose Snapshots.
Choose the snapshot and choose Actions, Create Image.
In the Create Image from EBS Snapshot dialog box, complete the fields to create your AMI, then choose Create. If you're re-creating a parent instance, then choose the same options as the parent instance.
Architecture: Choose i386 for 32-bit or x86_64 for 64-bit.
Root device name: Enter the appropriate name for the root volume. For more information, see Device Naming on Linux Instances.
Virtualization type: Choose whether instances launched from this AMI use paravirtual (PV) or hardware virtual machine (HVM) virtualization. For more information, see Linux AMI Virtualization Types.
(PV virtualization type only) Kernel ID and RAM disk ID: Choose the AKI and ARI from the lists. If you choose the default AKI or don't choose an AKI, you'll be required to specify an AKI every time you launch an instance using this AMI. In addition, your instance may fail the health checks if the default AKI is incompatible with the instance.
(Optional) Block Device Mappings: Add volumes or expand the default size of the root volume for the AMI. For more information about resizing the file system on your instance for a larger volume, see Extending a Linux File System.