Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is for a database (Postgre) VM, whose data is stored on a separate EBS volume. Can I make it so that the same EBS volume is mounted automatically (this is assuming that no other instance is using that EBS).

The reason for this would be that the db would have its data files available when it starts up.

share|improve this question
    
Presumably you are wondering how to automatically attach the volume from an Amazon EC2 API level perspective (in contrast to how to mount it afterwards, which is a secondary OS level perspective)? I suggest to adjust the question accordingly in case. –  Steffen Opel Sep 21 '12 at 8:43
add comment

4 Answers

to mount it you would need to add an entry in your fstab file (/etc/fstab)

something like this, although it is possible it will vary from this. you can man fstab for more information

/dev/xvdf1      /var/postgres       ext4    defaults    0 0

If you do a df -T you will get all the information you need

/dev/xvdf1    ext4    51605436  26338144  22645888  54% /var/postgres

so you know that the device is xvdf1 (it may be sdf1 or something like this) the second entry is where you want it mounted, the third entry is the filesystem type (which you can see as the second entry in the df -T command) and if you don't understand fstab, it's probably best to leave it as defaults and 0 0

Hope this helps.

share|improve this answer
add comment

When you attach a volume to an EC2 instance, it will remain attached to that instance until it is explicitly detached. Even when the instance is stopped, the volume will remain attached. It will have a constant device name such as /dev/sdf1.

When using a Linux instance, you can add a line to /etc/fstab to have the volume mounted into your filesystem on boot.

share|improve this answer
add comment

Presumably you are wondering how to automatically attach the volume from an Amazon EC2 API level perspective (in contrast to how to mount it afterwards, which is a secondary OS level perspective)?

The answer to this is simple, the CreateImage API (used in the AWS Management Console or the ec2-create-image command line tool in turn) automatically takes care of this:

Note
If you customized your instance with instance store volumes or EBS volumes in addition to the root device volume, the new AMI contains block device mapping information for those volumes. When you launch an instance from this new AMI, the instance automatically launches with those additional volumes.

There is a caveat to beware of, insofar the AMI creation process excludes stuff that is considered temporary from an OS level perspective - I haven't been able to find the official reference for this, but Nishant's answer to the related question Can I create an AMI that includes multiple ebs volumes (i.e. both sda and sdb) lists these correctly, as far as I recall:

   /sys
   /proc
   /dev
   /media
   /mnt
share|improve this answer
add comment

Might be better would be to create volume from snapshot during boot instead of attaching specific volume. This is more flexible - you could launch your instance in another availability zone and you won't get conflicts with existing instance. Also with new Snapshot Copy feature - http://aws.amazon.com/about-aws/whats-new/2012/12/17/announcing-ebs-snapshot-copy/ - you could copy snapshot and launch instance even in another AWS region. And finally by doing snapshot you will do backups of your data which is must-have in the cloud...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.