Extend Windows Ebs volume


Is there automated way with SSM or powershell to extend ebs volume on a ec2 instance

asked 2 years ago748 views
7 Answers

Hi, our environment does not allow to automate the resize. can only resize when requested. My task is now to extend it but I am looking for the automated way to do this via powershell or ssm?

answered 2 years ago
  • You can use the method in the blog I mentioned above, step 5 Extend the file system Extend the file system

    The most critical (and challenging) part of this automation is the ability to “extend” the file system on the OS layer. It is relatively easy to expand an EBS volume on the AWS layer. However, this additional space is useless unless the file system on the OS is extended to take advantage of the newly provisioned space. This process requires a good understanding of the various scenarios that you might come across, for example, different operating systems and volume types. Then, write the appropriate scripts to extend the volume on the OS layer.

    For Windows, we wrote a PowerShell script that used DiskPart, and for Linux our bash script used growpart. For more information about how to extend the file system after resizing the EBS volume, see the following:

    Extending a Windows File System after Resizing a Volume
    Extending a Linux File System After Resizing a Volume

    We followed the same approach used in earlier steps to deploy the scripts to the instance:

    Write the script and store in S3.
    Write an SSM document that downloads the script from S3 and executes it.
    In your Lambda, use the SSM client and the send_command method to run the SSM document on the instance.
  • you can refer the below blog for the powershell script that will extend the EBS volume by providing the drive letter, size to increase and instance name as an input and it will extend the EBS volume from AWS end as well as from OS end



on the EBS volume side, I did these powershell commands

new-ec2volume -VolumeType gp2 -size 10 -AvailabilityZone us-west-1b Add-EC2Volume -InstanceId xxxx -VolumeId vol-xxxxxxxxxx -Device xvdb

Then on the guest

I am using these commands and put in a powershell script.

$diskNumber = (Get-Disk | ? { $_.PartitionStyle -eq "RAW" }).Number Initialize-Disk -Number $diskNumber -PartitionStyle "MBR" $part = New-Partition -DiskNumber $diskNumber -UseMaximumSize -IsActive -DriveLetter "e" Format-Volume -DriveLetter $part.DriveLetter -Confirm:$FALSE

I am able to run these commands on the guest and it creates the drive fine.

But When i try to run using send-ssmcommand

nothing happens

Send-SSMCommand -InstanceId i-xxxxxxxxxx -Parameter @{commands = "/Users/xxxxxx/powershell/ssm_add_drive.ps1"} -DocumentName "AWS-RunPowerShellScript"

any idea?

answered 2 years ago
  • Assuming you pre-loaded the ssm_add_drives.ps1 on your instance, can you try putting the full path to the script (ex c:\users\username\script.ps1) instead of "/Users/....."


Hi There

You can use Powershell to extend an EBS volume using the resize-partititon cmdlet. Just be aware that it is always recommended to backup your data before changing the volume size.

See https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/recognize-expanded-volume-windows.html#recognize-expanded-volume-windows-powershell

Check out this blog for a fully automated solution for extending EBS volumes using Step Functions and SSM.

1. Monitor when a volume reaches 80% capacity and trigger the automation.
2. Run through a series of checks before proceeding, because certain systems were excluded. Some EC2 instances in our fleet had custom-built applications that required manual disk expansion. Other EC2 instances were managed by teams that had specific governance policies requiring tighter control of any infrastructure changes.
3. Take a snapshot of the volume as a safety measure in the unusual event that data corruption occurs.
4. Expand the volume by 20% on the AWS layer using Lambda.
5.  Extend the file system on the OS using Systems Manager documents that download and execute scripts stored in Amazon S3.
6. Check the status and make sure that the volume expanded and extended correctly.
7. Send an email notification summarizing the action that the automation performed successfully using Amazon SES.


√ If my answer addressed your question adequately, please consider clicking the ACCEPT button. It helps the community find answers to similar questions more quickly

profile pictureAWS
answered 2 years ago

if I ran following commands from aws console, it works. but not from send-ssmcommand

$diskNumber = (Get-Disk | ? { $_.PartitionStyle -eq "RAW" }).Number Initialize-Disk -Number $diskNumber -PartitionStyle "MBR" $part = New-Partition -DiskNumber $diskNumber -UseMaximumSize -IsActive -DriveLetter "e" Format-Volume -DriveLetter $part.DriveLetter -Confirm:$FALSE

answered 2 years ago

I did not preload the script to my instance. IS there a way to run the script from my laptop?

answered 2 years ago

ok I uploaded the powershell script to a s3 bucket. How do i specify the send-ssmcommand to get it from the bucket?

answered 2 years ago

you can refer the below blog for the powershell script that will extend the EBS volume by providing the drive letter, size to increase and instance name as an input and it will extend the EBS volume from AWS end as well as from OS end

Extend EBS Volume Using Powershell Script

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions