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




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

2 Answers 2


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

  • This would be a better answer if it continued with exactly how to use EC2Config to make sure additional drives in the AMI are online at launch. Oct 2, 2019 at 20:07

Using Packer to make AMIs, I had the same problem - when I launched an AMI made by Packer, any drives added were offline.

I fixed it by adding to an existing PowerShell script provider in Packer the following line:

Set-StorageSetting -NewDiskPolicy OnlineAll

As this is a security sensitive environment, it's possible that a security scan will find that and flag it as a STIG violation or something like that, but it does solve the problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .