I'm setting up a database server on EC2, and I need to ensure that an EBS volume is automatically attached and is available before the database service starts up.
I'm using SMF so I can test whether a particular filesystem is available before starting the db service, so there's no problem from that perspective, however I'm not quite sure how to tell the server to auto-attach the EBS volume during/after boot.
What would be the best strategy for this?
You just need a couple of short scripts -one to attach the EBS volume at boot time and the other to detach it on shutdown to make sure the shutdown is clean. See this AWS forum post.
You can use the
-b
flag of theec2-run-instances
orec2-register
commands to automatically create a volume from a snapshot and attach it at a specific block device location or create an empty volume. Ex:where
snap-1234abcd
is the snapshot id,50
is the size of the volume to be created. Either one is sufficient.