/var/opt/nydus/ops/customer_local_ops/operating_system/powershell
Edit: /var/opt/nydus/ops/customer_local_ops/operating_system/powershell/extend_disk.ps1 (2067B)
param(
[string]$DriveLetter = "C",
[switch]$CheckCloudbaseInit
)
$ErrorActionPreference = "Stop"
function Write-Result {
param([hashtable]$Data)
$Data | ConvertTo-Json -Depth 5 -Compress
exit 0
}
function Write-FailureResult {
param([string]$Reason, [hashtable]$Extra = @{})
$payload = @{ skipped = $false; success = $false; reason = $Reason }
foreach ($k in $Extra.Keys) { $payload[$k] = $Extra[$k] }
$payload | ConvertTo-Json -Depth 5 -Compress
exit 1
}
$DriveLetter = $DriveLetter.ToUpper()
if ($CheckCloudbaseInit) {
$cbi = Get-Service -Name "cloudbase-init" -ErrorAction SilentlyContinue
if ($cbi -and $cbi.StartType -ne "Disabled") {
Write-Result @{
skipped = $true
cloud_init_active = $true
reason = "cloudbase-init service present and enabled"
}
}
}
function To-GB([int64]$Bytes) {
return [math]::Round($Bytes / 1073741824, 1)
}
try {
Update-HostStorageCache -ErrorAction SilentlyContinue
$partition = Get-Partition -DriveLetter $DriveLetter -ErrorAction Stop
$supported = Get-PartitionSupportedSize -DriveLetter $DriveLetter -ErrorAction Stop
$volume = Get-Volume -DriveLetter $DriveLetter -ErrorAction Stop
$fsType = ($volume.FileSystemType -replace '\s','').ToLower()
$oldGB = To-GB $partition.Size
if ([int64]$partition.Size -ge [int64]$supported.SizeMax) {
Write-Result @{
skipped = $true
detected_os = "windows"
filesystem = $fsType
old_size = "$oldGB GB"
new_size = "$oldGB GB"
}
}
Resize-Partition -DriveLetter $DriveLetter -Size $supported.SizeMax -ErrorAction Stop
$after_partition = Get-Partition -DriveLetter $DriveLetter -ErrorAction Stop
$newGB = To-GB $after_partition.Size
Write-Result @{
skipped = $false
detected_os = "windows"
filesystem = $fsType
old_size = "$oldGB GB"
new_size = "$newGB GB"
}
}
catch {
Write-FailureResult $_.Exception.Message
}