Windows EBS Volume from snapshot at instance launch is OFFLINE

amazon ec2amazon-ebsamazon-web-serviceswindows

Using Powershell launching a Server 2012 R2 machine.
I can launch an instance from the stock Server 2012R2 AMI with a defined new EBS volume for d: drive, and upon boot, is online, and works fine.

If I take the same code and just add creation of the volume from snapshot, it boots, the volume is there, but it is shown OFFLINE. Once in disk manager, mark it online and all is again well and I have a D: drive.

I tried several different ways to create the snapshot (running, offline, detached, instance stopped). Nothing seems to make a difference.

EDIT: Also tried launching instance without volume, provisioning volume, and attaching it to instance. Same results

Thoughts?

Thanks

Cam

Code I'm using:

#configure D:\ drive
$Volume2 = New-Object Amazon.EC2.Model.EbsBlockDevice
$Volume2.DeleteOnTermination = $True
$Volume2.VolumeSize = 10
$Volume2.VolumeType = "gp2"
$Volume2.SnapshotId = "snap-xxxxxx"
#and map it 
$Mapping2 = New-Object Amazon.EC2.Model.BlockDeviceMapping
$Mapping2.DeviceName = 'xvdf'
$Mapping2.Ebs = $Volume2
#create the instance
$NewInstance = New-EC2Instance -ImageId $ImageId -MinCount 1 -MaxCount 1 -InstanceType "t2.medium" -SecurityGroupIds xxxx  -SubnetId xxxxx -UserData $UserdataBase64Encoded -KeyName XXX -AvailabilityZone us-east-1c  -BlockDeviceMapping $Mapping2

Best Answer

Stock servers for Windows Server 2012 have a default policy of OFF-LINE for new storage it finds to mount. You can change that policy, but that wouldn't be "stock" anymore. A "stock Server" has no D: drive, so you're going to have to do something.

At some point, you'll have to execute code from inside your "stock Server"+D:drive.

This example takes a disk that is offline and makes it online.

  • Windows PowerShell PS C:> Set-Disk -Number 5 -IsOffline $False

The question becomes, how do you execute this code from a "stock Server"? Amazon Windows AMI "stock Servers" contain an additional service installed by Amazon Web Services, the EC2Config service. EC2Config's "User data" enables you to inject scripts into the instance metadata during the first launch. By default, all Amazon AMIs have user data execution enabled for the initial boot.

For details, see Configuring a Windows Instance Using the EC2Config Service