Extend Windows Ebs volume

0

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

demandé il y a un an669 vues
7 réponses
0

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?

répondu il y a un an
  • 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

    https://www.magicpowershell.com/2022/07/extend-live-ebs-volume-on-aws-ec2-instance.html

0

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?

répondu il y a un an
  • 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/....."

0

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.

https://aws.amazon.com/blogs/storage/automating-amazon-ebs-volume-resizing-with-aws-step-functions-and-aws-systems-manager/

√ 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
EXPERT
Matt-B
répondu il y a un an
0

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

répondu il y a un an
0

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

drago
répondu il y a un an
0

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

drago
répondu il y a un an
0

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

Mayank
répondu il y a un an

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions