Menu
Amazon Elastic Compute Cloud
User Guide for Linux Instances

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

  1. 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.

  2. 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.

    1. Create a temporary directory on your instance for your X.509 private key as follows:

      Copy
      [ec2-user ~]$ mkdir /tmp/cert
    2. Copy your X.509 private key from your computer to the /tmp/cert directory on your instance, using a secure copy tool such as scp. The my-private-key parameter in the following command is the private key you use to connect to your instance with SSH. For example:

      Copy
      you@your_computer:~ $ scp -i my-private-key.pem /path/to/pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem ec2-user@ec2-203-0-113-25.compute-1.amazonaws.com:/tmp/cert/ pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem 100% 717 0.7KB/s 00:00
  3. Set environment variables for your AWS access key and secret key.

    Copy
    [ec2-user ~]$ export AWS_ACCESS_KEY_ID=your_access_key_id [ec2-user ~]$ export AWS_SECRET_ACCESS_KEY=your_secret_access_key
  4. Prepare an Amazon EBS volume for your new AMI.

    1. 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.

      Copy
      [ec2-user ~]$ aws ec2 create-volume --size 10 --region us-west-2 --availability-zone us-west-2b
    2. Attach the volume to your Amazon EBS-backed instance using the attach-volume command.

      Copy
      [ec2-user ~]$ aws ec2 attach-volume --volume-id volume_id --instance-id instance_id --device /dev/sdb --region us-west-2
  5. Create a folder for your bundle.

    Copy
    [ec2-user ~]$ mkdir /tmp/bundle
  6. Download the bundle for your instance store-based AMI to /tmp/bundle using the ec2-download-bundle command.

    Copy
    [ec2-user ~]$ ec2-download-bundle -b my-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/bundle
  7. Reconstitute the image file from the bundle using the ec2-unbundle command.

    1. Change directories to the bundle folder.

      Copy
      [ec2-user ~]$ cd /tmp/bundle/
    2. Run the ec2-unbundle command.

      Copy
      [ec2-user bundle]$ ec2-unbundle -m image.manifest.xml --privatekey /path/to/pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem
  8. Copy the files from the unbundled image to the new Amazon EBS volume.

    Copy
    [ec2-user bundle]$ sudo dd if=/tmp/bundle/image of=/dev/sdb bs=1M
  9. Probe the volume for any new partitions that were unbundled.

    Copy
    [ec2-user bundle]$ sudo partprobe /dev/sdb1
  10. List the block devices to find the device name to mount.

    Copy
    [ec2-user bundle]$ lsblk NAME 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 part

    In 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).

  11. Create a mount point for the new Amazon EBS volume and mount the volume.

    Copy
    [ec2-user bundle]$ sudo mkdir /mnt/ebs [ec2-user bundle]$ sudo mount /dev/sdb1 /mnt/ebs
  12. Open the /etc/fstab file 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, the fstab file is located at /mnt/ebs/etc/fstab.

    Copy
    [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 2

    In this example, the last line should be removed.

  13. Unmount the volume and detach it from the instance.

    Copy
    [ec2-user bundle]$ sudo umount /mnt/ebs [ec2-user bundle]$ aws ec2 detach-volume --volume-id volume_id --region us-west-2
  14. Create an AMI from the new Amazon EBS volume as follows.

    1. Create a snapshot of the new Amazon EBS volume.

      Copy
      [ec2-user bundle]$ aws ec2 create-snapshot --region us-west-2 --description "your_snapshot_description" --volume-id volume_id
    2. Check to see that your snapshot is complete.

      Copy
      [ec2-user bundle]$ aws ec2 describe-snapshots --region us-west-2 --snapshot-id snapshot_id
    3. Identify 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.

      Copy
      [ec2-user bundle]$ aws ec2 describe-images --region us-west-2 --image-id ami-id --output text IMAGES x86_64 amazon/amzn-ami-pv-2013.09.2.x86_64-s3 ami-8ef297be amazon available public machine aki-fc8f11cc instance-store paravirtual xen

      In this example, the architecture is x86_64 and the kernel image ID is aki-fc8f11cc. Use these values in the following step. If the output of the above command also lists an ari ID, take note of that as well.

    4. 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 ari ID, include that in the following command with --ramdisk-id ari_id.

      Copy
      [ec2-user bundle]$ aws ec2 register-image --region us-west-2 --name your_new_ami_name --block-device-mappings Ebs={SnapshotId=snapshot_id} --virtualization-type hvm --architecture x86_64 --kernel-id aki-fc8f11cc
  15. (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.

    Copy
    $ aws ec2 delete-volume --volume-id volume_id