Tuesday, May 22, 2012

Restoring an AWS instance from a snapshot

I had created an Amazon Web Services instance. As is the default when creating an instance, it used EBS as the root device.

A few days ago, when I had it set up just the way I liked it, I created a snapshot. Then I did some experimental work, didn't like the results, and wanted to restore the snapshot to revert. Here's how to do that using the AWS Management Console:




  1. In the AWS Control Panel, click Instances, then click on your instance. Instance details will be displayed at the bottom of the page. Note the instance's name (Steve-Jenkins in my example; yours will be different), instance ID (i-4b33962d), zone (us-east-1c), and root device (sda1).
  2. If the instance is running, stop it.
  3. Click Volumes. Look at the Attachment Information column to locate the volume currently attached to your instance. Right-click this volume and select Detach Volume. (The volume's state might not change from in-use to available right away. If it doesn't, try refreshing the page.)
  4. Click Snapshots. Right-click your snapshot and select Create Volume from Snapshot. Set the size (30 GiB in my example) and Availability Zone. Make sure the Availability Zone matches the one you noted in step 1.
  5. Return to Volumes. Right-click the newly created volume and select Attach Volume. Select your instance. For Device, type in  the root device you noted in step 1, but be sure to prepend /dev/. In my example, I entered /dev/sda1.
  6. To avoid charges for the old volume that's no longer attached to your instance, right-click it and select Delete Volume.
  7. Click Instances, right-click your instance, and select Start Instance. If you created and attached the volume correctly, the instance should start without error.
Tip: If you had an Elastic IP attached to your image, don't forget to reattach it now. Click Elastic IPs, right-click the IP address, select Associate, and select your instance.

Another tip: I wanted more disk space, so I tried making the new volume larger -- 60 GiB rather than 30 GiB -- in step 4. This didn't work. I ended up with a 60 GiB volume, but only 30 GiB was in a usable boot partition. The rest was in an unallocated partition, and I couldn't find a convenient way to merge the two partitions without losing data. A better alternative might be to create a second volume and attach it to the same instance.

1 comment: