Converting your Instance Store-Backed AMI to an Amazon EBS-Backed AMI
You can convert an instance store-backed Linux AMI that you own to an Amazon EBS-backed Linux AMI.
Important
You can't convert an instance store-backed Windows AMI to an Amazon EBS-backed Windows AMI and you cannot convert an AMI that you do not own.
To convert an instance store-backed AMI to an Amazon EBS-backed AMI
Launch an Amazon Linux instance from an Amazon EBS-backed AMI. For more information, see Launching an Instance. Amazon Linux instances have the AWS CLI and AMI tools pre-installed.
Upload the X.509 private key that you used to bundle your instance store-backed AMI to your instance. We use this key to ensure that only you and Amazon EC2 can access your AMI.
Create a temporary directory on your instance for your X.509 private key as follows:
[ec2-user ~]$mkdir /tmp/certCopy your X.509 private key from your computer to the
/tmp/certdirectory on your instance, using a secure copy tool such as scp. Themy-private-keyparameter in the following command is the private key you use to connect to your instance with SSH. For example:you@your_computer:~ $scp -ipk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem 100% 717 0.7KB/s 00:00my-private-key.pem/path/to/pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pemec2-user@ec2-203-0-113-25.compute-1.amazonaws.com:/tmp/cert/
Set environment variables for your AWS access key and secret key.
[ec2-user ~]$export AWS_ACCESS_KEY_ID=[ec2-user ~]$your_access_key_idexport AWS_SECRET_ACCESS_KEY=your_secret_access_keyPrepare an Amazon EBS volume for your new AMI.
Create an empty Amazon EBS volume in the same Availability Zone as your instance using the create-volume command. Note the volume ID in the command output.
Important
This Amazon EBS volume must be the same size or larger than the original instance store root volume.
[ec2-user ~]$aws ec2 create-volume --size 10 --regionus-west-2--availability-zoneus-west-2bAttach the volume to your Amazon EBS-backed instance using the attach-volume command.
[ec2-user ~]$aws ec2 attach-volume --volume-idvolume_id--instance-idinstance_id--device /dev/sdb --regionus-west-2
Create a folder for your bundle.
[ec2-user ~]$mkdir /tmp/bundleDownload the bundle for your instance store-based AMI to
/tmp/bundleusing the ec2-download-bundle command.[ec2-user ~]$ec2-download-bundle -bmy-s3-bucket/bundle_folder/bundle_name-m image.manifest.xml -a $AWS_ACCESS_KEY -s $AWS_SECRET_KEY --privatekey/path/to/pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem-d /tmp/bundleReconstitute the image file from the bundle using the ec2-unbundle command.
Change directories to the bundle folder.
[ec2-user ~]$cd /tmp/bundle/Run the ec2-unbundle command.
[ec2-user bundle]$ec2-unbundle -m image.manifest.xml --privatekey/path/to/pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem
Copy the files from the unbundled image to the new Amazon EBS volume.
[ec2-user bundle]$sudo dd if=/tmp/bundle/image of=/dev/sdb bs=1MProbe the volume for any new partitions that were unbundled.
[ec2-user bundle]$sudo partprobe /dev/sdb1List the block devices to find the device name to mount.
[ec2-user bundle]$lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT /dev/sda 202:0 0 8G 0 disk └─/dev/sda1 202:1 0 8G 0 part / /dev/sdb 202:80 0 10G 0 disk └─/dev/sdb1 202:81 0 10G 0 partIn this example, the partition to mount is
/dev/sdb1, but your device name will likely be different. If your volume is not partitioned, then the device to mount will be similar to/dev/sdb(without a device partition trailing digit).Create a mount point for the new Amazon EBS volume and mount the volume.
[ec2-user bundle]$sudo mkdir /mnt/ebs[ec2-user bundle]$sudo mount/dev/sdb1/mnt/ebsOpen the
/etc/fstabfile on the EBS volume with your favorite text editor (such as vim or nano) and remove any entries for instance store (ephemeral) volumes. Because the Amazon EBS volume is mounted on/mnt/ebs, thefstabfile is located at/mnt/ebs/etc/fstab.[ec2-user bundle]$sudo nano /mnt/ebs/etc/fstab# LABEL=/ / ext4 defaults,noatime 1 1 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0/dev/sdb /media/ephemeral0 auto defaults,comment=cloudconfig 0 2In this example, the last line should be removed.
Unmount the volume and detach it from the instance.
[ec2-user bundle]$sudo umount /mnt/ebs[ec2-user bundle]$aws ec2 detach-volume --volume-idvolume_id--regionus-west-2Create an AMI from the new Amazon EBS volume as follows.
Create a snapshot of the new Amazon EBS volume.
[ec2-user bundle]$aws ec2 create-snapshot --regionus-west-2--description "your_snapshot_description" --volume-idvolume_idCheck to see that your snapshot is complete.
[ec2-user bundle]$aws ec2 describe-snapshots --regionus-west-2--snapshot-idsnapshot_idIdentify the processor architecture, virtualization type, and the kernel image (
aki) used on the original AMI with the describe-images command. You need the AMI ID of the original instance store-backed AMI for this step.[ec2-user bundle]$aws ec2 describe-images --regionIMAGES x86_64 amazon/amzn-ami-pv-2013.09.2.x86_64-s3--image-idus-west-2ami-id--output textami-8ef297beamazon available public machine aki-fc8f11cc instance-store paravirtual xenIn this example, the architecture is
x86_64and the kernel image ID isaki-fc8f11cc. Use these values in the following step. If the output of the above command also lists anariID, take note of that as well.Register your new AMI with the snapshot ID of your new Amazon EBS volume and the values from the previous step. If the previous command output listed an
ariID, include that in the following command with--ramdisk-id.ari_id[ec2-user bundle]$aws ec2 register-image --regionus-west-2--nameyour_new_ami_name--block-device-mappings Ebs={SnapshotId=snapshot_id} --virtualization-type hvm --architecture x86_64 --kernel-idaki-fc8f11cc
(Optional) After you have tested that you can launch an instance from your new AMI, you can delete the Amazon EBS volume that you created for this procedure.
$aws ec2 delete-volume --volume-idvolume_id

