Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I have an EC2 instance with "instance store" device as a root device. Now, I would like to attach an EBS volume to that same instance, only that I want it to be the root device. Is this possible? What happens to the instance store device in such a case?

1 Answer

0 votes
by (44.4k points)

You can migrate your running instance to an EBS backed AMI. This is how to do it:

  • Boot up a normal S3 AMI backed instance (or since you've got already got an instance you are happy with, use that)
  • Make an EBS volume of equivalent size as your root sda1 partition (currently the default is 10G for an m1.small and possibly others)
  • Attach that EBS volume to a free block device on the instance using the web console or CLI tools (e.g. /dev/sdd)
  • Stop the services on the instance (e.g. /etc/init.d/mysql stop etc.)
  • Copy the transitory root volume to the compass point volume:

dd bs=65536 if=/dev/sda1 of=/dev/sdd

  • Check the EBS volume for consistency:

fsck /dev/sdd

  • Mount the EBS volume onto the instance:

mount /dev/sdd /root/ebs-vol

  • Remove the /mnt entry from the fstab on your EBS vol:

vim /root/ebs-vol/etc/fstab

  • Unmount the EBS volume:

umount /dev/sdd

  • Create a pic of the compass point volume victimisation the AWS management console (or instruction API tools)
  • Make note of the snapshot id
  • Register the snapshot image with AWS and note the AMI id created when registering to remember to specify the kernel and ramdisk image (these should be the same as those used in your current instance):

ec2-register -s snap-12345 -a i386 -d "Description of AMI" -n "name-of-image" -k aki-12345 -r ari-12345

  • To create an instance with over 10G of persistent storage you've got to use the command line interface tools. e.g. for 20G

ec2-run-instances ami-54321 -t m1.small -n 1 -g default --availability-zone=eu-west-1a -k ec2-key1 -b /dev/sda1=snap-12345:20:false

  • If you boot up an instance based on one of these AMIs with > default volume size, once it's started up you can do an online resize of the filesystem:

resize2fs /dev/sda1

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...