Aws Ec2: How to Remount Previous Ebs Volume Using Pivot_Root

AWS EC2: How to remount previous EBS volume using pivot_root?

The answer is to place the pivot_root call inside of /sbin/init on the initial (ephemeral) EBS root volume.

Here are some scripts that automate the process of launching a new Spot Instance and modifying the /sbin/init on the 1st (ephemeral) EBS volume to chain-load the system from a 2nd (persistent) EBS volume:

https://github.com/atramos/ec2-spotter

Automatically attach and mount EBS volume on new EC2 instance

You cannot directly launch a new Amazon EC2 instance with an existing Amazon EBS volume. Instead, you would need to:

  • Launch a new Amazon EC2 instance with a new root volume
  • Stop the instance
  • Detach the root volume
  • Attach the 'old' EBS volume
  • Start the instance

EC2 - New Instance Vs (remount) EBS-backed instance

What are the differences between the new instance and the instance launched via an existing EBS?

Answer- first of all, understand what EBS is, in a simple language, it is a block storage volume for use with Amazon EC2 Instance.
So Whenever you launch a new Instance via an existing EBS, all the stuff/ any manual changes on the disk which you have done previously will be automatically reflected in your new Instance, as you are using the same disk (Block Storage). It's just when you want any kind of modification like wants to change the key pair at that time we detach the volume, do the modifications and again attach the volume (disk).

Is the existing-EBS-launched instance supposed to work like the old instance without any changes, out-of-the-box?

Answer- yes Existing EBS launched instance work as the old instance, its just what kind of modification you have provided to the new instance. Suppose while launching you have changed the Type of instance, key pair, attach different security group. So all these changes will be reflected and all the manual operations done on Disk will remains same.

Persistant EBS on AWS EC2 instances

The problems you are facing are the primarily reasons why this pattern (all in the same instance) is discouraged. This works while your app is small and is not receiving a lot of traffic.

What you should do instead is to extract your database from the app instances and move it to RDS (being it semi-managed will prevent you from a lot of tasks like server patching, regular backups, configuring replica set, etc). Also RDS will provide you with easy multi-AZ deployment that will help you achieve real fault tolerance. This step is optional though - you could just spin up a new EC2 instance and manually install your DB there (but keep it dedicated to DB purpose).

You architecture should look similar to the following diagram;

ELB ---> INSTANCE 1 --> RDS DB INSTANCE
| ^
|-> INSTANCE 2 ---------|
| |
|-> INSTANCE n ---------|

You should keep your instances as stateless as possible if you want to scale. The same approach applies to files that you store in the instance it self; you should move them to S3 (or if available on your region you can also use Elastic File System)

Issue Creating EC2 with Provisioned iops EBS

Every Account has a limited number of IOPS that can be attached to the volumes.I think the limit per account is set to 10000. This may be the reason why your instances are getting terminated. Check for all volumes that you already have IOPS associated and add them up to see if you are exceeding the limit.

If this is the issue I think you can contact AWS to increase the limit.

Setting the webserver to an EBS directory

/dev/sdf is a block device and /var/www/html is a mount point. They're completely different things; analogous to a physical book and a bookmark.

You first have to attach your EBS volume to your instance. It will show up as /dev/sdf(or whatever device name you've specified). You then have to create a file system on it using mkfs.ext4 /dev/sdf. You then mount the newly created volume using mount /dev/sdf /var/www/html. To have it automatically mount at boot, edit /etc/fstab and append the following to the file:

/dev/sdf    /var/www/html     ext4      defaults,noatime    0      0

Attaching an EBS volume to AWS Batch Compute Environments

Create a instance-template, provide a bootstrap script, for the mentioned case something like:

sudo mkdir -p /<any directory name where volume will be mounted eg: dir>

aws ec2 attach-volume --volume-id <volume_id> --instance-id $(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id) --device /dev/sdf

sudo mount /dev/sdf /<above mentioned dir rg :dir>

in AWS batch definition, use the above template to launch your ec2 machine.



Related Topics



Leave a reply



Submit