Does anyone know how to auto-mount an Elastic Block Storage (EBS) volume when starting a Windows 2003 instance in Amazon\'s Elastic Compute Cloud (EC2)?
I found the following Ruby code at http://www.ioncannon.net/system-administration/199/automounting-amazon-ebs-volumes-on-ec2-instances/ courtesy of Carson McDonald. It's for Linux/Unix but maybe you can re-swizzle this for Ruby on Windows 2003 or have it serve as a model for doing it in some other scripting language.
Note that you could pass things into your image as user data such as the ECS EBS volume ID and the device name (e.g., /dev/sdh in the following example or whatever it would be in Windows for your case). You can access the user data from the instance itself as meta-data as is roughly done below to get the instance-id. More specifically, you'd access http://169.254.169.254/1.0/user-data to get to the user-data.
#!/usr/bin/ruby
require 'rubygems'
require 'right_aws'
require 'net/http'
url = 'http://169.254.169.254/2008-02-01/meta-data/instance-id'
instance_id = Net::HTTP.get_response(URI.parse(url)).body
AMAZON_PUBLIC_KEY='your public key'
AMAZON_PRIVATE_KEY='your private key'
EC2_LOG_VOL='the volume id'
ec2 = RightAws::Ec2.new(AMAZON_PUBLIC_KEY, AMAZON_PRIVATE_KEY)
vol = ec2.attach_volume(EC2_LOG_VOL, instance_id, '/dev/sdh')
puts vol
# It can take a few seconds for the volume to become ready.
# This is just to make sure it is ready before mounting it.
sleep 20
system('mount /dev/sdh /mymountpoint')