I have a windows Server 2008 Vm with an OS vmdk and an application vmdk. When my application vmdk runs out of space, I want to be able to grow the vmdk and the partition inside of it, without having to reboot the vm.
Is this possible?
One way to do it is to give enough space through thin provisioning and let it grow when application uses/writes data into disk.
Or you could manually increase the size of hardisk by going to edit settings and increasing it. Say if you have 50gb you could make it 100gb and then go into vm rescan disks and expand the partition. This does not need a reboot.
Ok thanks. Is it possible to create an automated task to do this with something like VIX? For example, have a script that goes out and increases the vmdk, then logs into the VM with VIX and increases the partition size from within the VM?
I scripted something like this for automated VM deployments in PowerCLI.
Below you can find some snippets and a function that can automatically resize and format new partitions on VMs through executing scripts inside the GuestOS via Invoke-VMScript. You may need to adjust some parameters and variables of course.
Get-HardDisk -VM $VM | Set-HardDisk -CapacityKB ($Disk1GB * 1MB) -Confirm:$false if($Disk2GB -gt 0) {
New-HardDisk -VM $VM -CapacityKB ($Disk2GB * 1MB) -Storageformat Thin -Confirm:$false
}
if($Disk3GB -gt 0) {
New-HardDisk -VM $VM -CapacityKB ($Disk3GB * 1MB) -Storageformat Thin -Confirm:$false
}
function Run-GuestScript {
param(
[string]$admingroup,
[string]$domain,
[bool]$extend,
[bool]$format
)
if(($admingroup -ne "") -and ($domain -ne "")) {
Write-Host "Adding $admingroup to the local Adminstrator group..."
Invoke-VMScript -ScriptText "([adsi]`"WinNT://./Administrators,group`").Add(`"WinNT://$domain/$admingroup,group`")" -VM $VM -GuestCredential $LocalAdminCredentials
}
if($extend -eq 1) {
Write-Host "Extending partition C:\"
Invoke-VMScript -ScriptText 'out-file c:\install\diskpartscript.txt -Encoding ASCII -InputObject "select volume 2`r`n extend`r`n"' -VM $VM -GuestCredential $LocalAdminCredentials
Invoke-VMScript -ScriptText "diskpart /s c:\install\diskpartscript.txt" -ScriptType bat -VM $VM -GuestCredential $LocalAdminCredentials
}
if($format -eq 1) {
Write-Host "Partitioning other new disks..."
$script = '
$NumDisks = (Get-Wmiobject -class "Win32_DiskDrive").count
for($CurrentDisk = 1; $NumDisks -gt $CurrentDisk; $CurrentDisk++) {
for($j=67; gdr($NextFreeLetter = [char]++$j) 2>$null) {}
out-file c:\install\diskpartscript.txt -Encoding ASCII -InputObject "select disk $CurrentDisk`r`n online disk noerr`r`n attributes disk clear readonly`r`n clean`r`n create partition primary`r`n format fs=ntfs quick`r`n assign letter=$NextFreeLetter"
diskpart /s c:\install\diskpartscript.txt
} '
Invoke-VMScript -ScriptText $script -VM $VM -GuestCredential $LocalAdminCredentials
}
}
The Set-HardDisk PowerCLI cmdlet also includes parameters to extend guest partitions:
http://www.vmware.com/support/developer/PowerCLI/PowerCLI51/html/Set-HardDisk.html
OK thanks. This is a bit complex to decipher - is there a simple 2 or three liner that simply gets one hard disk and sends a command to increase the size of the OS partition?