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)?
在亚马逊的弹性计算云(EC2)中启动Windows 2003实例时,是否有人知道如何自动安装弹性块存储(EBS)卷?
2 个解决方案
#1
4
Setup:
- Make sure the EBS volume is formatted and labeled (in the example I used the label PDRIVE).
- Setup a drive mapping using Ec2ConfigServiceSettings.exe
- Install Java on the instance
- Install the EC2 API command line tools
- Install a copy of your cert and private key
- Install a copy of curl.exe (open source tool)
确保EBS卷已格式化并标记(在示例中我使用了标签PDRIVE)。
使用Ec2ConfigServiceSettings.exe设置驱动器映射
在实例上安装Java
安装EC2 API命令行工具
安装证书和私钥的副本
安装curl.exe的副本(开源工具)
You can use the group policy editor to set this script as your startup script. See http://technet.microsoft.com/en-us/library/cc739591(WS.10).aspx for more information.
您可以使用组策略编辑器将此脚本设置为启动脚本。有关详细信息,请参阅http://technet.microsoft.com/en-us/library/cc739591(WS.10).aspx。
REM @echo off
REM setlocal ENABLEDELAYEDEXPANSION
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 100 /so AttachEbsBoot /d "Starting attach-ebs-boot.cmd"
REM local variables
REM Make sure you include the directory with curl.exe and the EC2 command line tools in the path
set path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;c:\Utils;C:\ebin\ec2\bin
set JAVA_HOME=c:\java
set EC2_HOME=c:\ebin\ec2
set EC2_CERT=<your_cert>
set EC2_PRIVATE_KEY=<your_private_key>
REM Please note: you should use the Ec2 Config Serive Settings application to ensure
REM that your EBS volume is mapped to a particular drive letter.
REM
REM edit as needed
set EBS_DRIVE=P:
set EBS_DEVICE=xvdp
REM Test to see if the drive is already attached. If it is then we're done.
if exist %EBS_DRIVE%\nul (goto done)
REM get the EBS volume ID from the user data and the instance ID from the meta-data
for /f "delims=" %%a in ('curl http://169.254.169.254/latest/user-data') do (set EBS_VOLUME=%%a)
for /f "delims=" %%b in ('curl http://169.254.169.254/latest/meta-data/instance-id') do (set INSTANCE_ID=%%b)
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 102 /so AttachEbsBoot /d "Volume == %EBS_VOLUME%"
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 103 /so AttachEbsBoot /d "Instance == %INSTANCE_ID%"
REM attach the volume
REM
REM Use a series of set command to build the command line
SET COMMAND_LINE=%EBS_VOLUME%
SET COMMAND_LINE=%COMMAND_LINE% -i
SET COMMAND_LINE=%COMMAND_LINE% %INSTANCE_ID%
SET COMMAND_LINE=%COMMAND_LINE% -d
SET COMMAND_LINE=%COMMAND_LINE% %EBS_DEVICE%
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 104 /so AttachEbsBoot /d "calling ec2attvole %COMMAND_LINE%"
call ec2attvol.cmd %COMMAND_LINE%
:DONE
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 101 /so AttachEbsBoot /d "Exiting attach-ebs-boot.cmd"
REM Events logged in the System event log
REM source === AttachEbsBoot
REM
REM Event 100 - Script start
REM Event 101 - Script end
REM Event 102 - Volume ID
REM Event 103 - Instance ID
REM Event 104 - Command line for ec2attvol
#2
3
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.
我在http://www.oncannon.net/system-administration/199/automounting-amazon-ebs-volumes-on-ec2-instances/中找到了以下Ruby代码,由Carson McDonald提供。它适用于Linux / Unix,但也许你可以在Windows 2003上为Ruby重新调整它,或者让它作为用其他脚本语言执行它的模型。
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.
请注意,您可以将内容作为用户数据传递到图像中,例如ECS EBS卷ID和设备名称(例如,以下示例中的/ dev / sdh或适用于您的Windows中的任何内容)。您可以将实例本身的用户数据作为元数据访问,如下所示,以获取实例ID。更具体地说,您可以访问http://169.254.169.254/1.0/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')
#1
4
Setup:
- Make sure the EBS volume is formatted and labeled (in the example I used the label PDRIVE).
- Setup a drive mapping using Ec2ConfigServiceSettings.exe
- Install Java on the instance
- Install the EC2 API command line tools
- Install a copy of your cert and private key
- Install a copy of curl.exe (open source tool)
确保EBS卷已格式化并标记(在示例中我使用了标签PDRIVE)。
使用Ec2ConfigServiceSettings.exe设置驱动器映射
在实例上安装Java
安装EC2 API命令行工具
安装证书和私钥的副本
安装curl.exe的副本(开源工具)
You can use the group policy editor to set this script as your startup script. See http://technet.microsoft.com/en-us/library/cc739591(WS.10).aspx for more information.
您可以使用组策略编辑器将此脚本设置为启动脚本。有关详细信息,请参阅http://technet.microsoft.com/en-us/library/cc739591(WS.10).aspx。
REM @echo off
REM setlocal ENABLEDELAYEDEXPANSION
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 100 /so AttachEbsBoot /d "Starting attach-ebs-boot.cmd"
REM local variables
REM Make sure you include the directory with curl.exe and the EC2 command line tools in the path
set path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;c:\Utils;C:\ebin\ec2\bin
set JAVA_HOME=c:\java
set EC2_HOME=c:\ebin\ec2
set EC2_CERT=<your_cert>
set EC2_PRIVATE_KEY=<your_private_key>
REM Please note: you should use the Ec2 Config Serive Settings application to ensure
REM that your EBS volume is mapped to a particular drive letter.
REM
REM edit as needed
set EBS_DRIVE=P:
set EBS_DEVICE=xvdp
REM Test to see if the drive is already attached. If it is then we're done.
if exist %EBS_DRIVE%\nul (goto done)
REM get the EBS volume ID from the user data and the instance ID from the meta-data
for /f "delims=" %%a in ('curl http://169.254.169.254/latest/user-data') do (set EBS_VOLUME=%%a)
for /f "delims=" %%b in ('curl http://169.254.169.254/latest/meta-data/instance-id') do (set INSTANCE_ID=%%b)
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 102 /so AttachEbsBoot /d "Volume == %EBS_VOLUME%"
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 103 /so AttachEbsBoot /d "Instance == %INSTANCE_ID%"
REM attach the volume
REM
REM Use a series of set command to build the command line
SET COMMAND_LINE=%EBS_VOLUME%
SET COMMAND_LINE=%COMMAND_LINE% -i
SET COMMAND_LINE=%COMMAND_LINE% %INSTANCE_ID%
SET COMMAND_LINE=%COMMAND_LINE% -d
SET COMMAND_LINE=%COMMAND_LINE% %EBS_DEVICE%
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 104 /so AttachEbsBoot /d "calling ec2attvole %COMMAND_LINE%"
call ec2attvol.cmd %COMMAND_LINE%
:DONE
C:\WINDOWS\system32\eventcreate /l SYSTEM /t information /id 101 /so AttachEbsBoot /d "Exiting attach-ebs-boot.cmd"
REM Events logged in the System event log
REM source === AttachEbsBoot
REM
REM Event 100 - Script start
REM Event 101 - Script end
REM Event 102 - Volume ID
REM Event 103 - Instance ID
REM Event 104 - Command line for ec2attvol
#2
3
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.
我在http://www.oncannon.net/system-administration/199/automounting-amazon-ebs-volumes-on-ec2-instances/中找到了以下Ruby代码,由Carson McDonald提供。它适用于Linux / Unix,但也许你可以在Windows 2003上为Ruby重新调整它,或者让它作为用其他脚本语言执行它的模型。
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.
请注意,您可以将内容作为用户数据传递到图像中,例如ECS EBS卷ID和设备名称(例如,以下示例中的/ dev / sdh或适用于您的Windows中的任何内容)。您可以将实例本身的用户数据作为元数据访问,如下所示,以获取实例ID。更具体地说,您可以访问http://169.254.169.254/1.0/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')