I'm trying to resize virtual hard disks with power CLI
VMware's reference at this link:
http://www.vmware.com/support/developer/PowerCLI/PowerCLI41/html/Set-HardDisk.html
Gives this example:
-------------- Example 2 --------------
Set-HardDisk -HardDisk $harddisk -CapacityKB $extendedCapacity -HostCredential $hostCred -GuestCredential $guestCred
Extends a hard disk with the specified capacity. The command also extends the disk on the guest OS.
If I use just the -HardDisk and -CapacityKB parameters it works fine but afterward I have to go and extend the partition of the operating system itself. My question is about the statement that VMware makes that "The command also extends the disk on the guest OS." Is that supposed to mean that the command used with all the options also extends the partition in Windows to cover the whole amount of space of the virtual hard disk? Also, I'm logging in to vCenter Server using connect-viserver before I run this command - is there any reason I need the -HostCredential parameter?
Thanks
When you provide the Host and Guest credentials the cmdlet will run one of the GuestDiskExpansion scripts inside the guest.
The cmdlet needs these credentials to make the necessary VIX calls to run the script inside the guest OS.
When you are connected to an ESX(i) server instead of a vCenter you can leave out the Host credentials.
Note1 that the GuestDiskExpansion scripts only work for a limited set of guest OSs.
Note2 watch out with partitions. If you don't specify one, the cmdlet will automatically take the last partition on the vdisk.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok thanks for the info. Windows Vista and above, and 2008 have a feature inside the OS that allows you to extend the partition. XP and 2003 and below do not. I'm assuming that it is just calling that feature of the OS to use it in the OS's in which it exists - so that if I have an XP machine I'm going to still need to run partitioning software to extend the partition - or use VMware converter.
No, have a look at the scripts in the Scripts folder, you'll notice that there is also a script for XP.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK, what "scripts" folder are you referring to that allows you to resize the XP OS's partition?- something inside the XP OS itself? Some folder in the powerCLI stuff?
No, in the machine where you installed PowerCLI.
In %ProgramFiles%\VMware\Infrastructure\vSphere PowerCLI\Scripts
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK thanks - found it. How does this work though - is this powershell code that VMware is running on the VMDK files from the outside? Is there a link explaining how PowerCLI accomplishes this resizing?
Thanks
The Set-Harddisk cmdlet tries to find out which OS runs in the guest.
From there it determines, provided it is a supported OS, which script to use.
The script is run inside the guest OS, similar to what you can do with the Invoke-VMScript cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm getting an error "the specified virtual disk does not support resizing" on an XP disk. Is this because it is an IDE disk?
Hi,
Are you trying to resize system partition (where the windows is installed)? If yes, you have to specify value for the HelperVM parameter - f.e. another VM with Win XP that will be used for the resize process.
Regards,
Pavel
Or you have a snapshot on the VM where you're trying to resize?
Don't have snapshot but this definitely isn't working.
I believe you are correct about the IDE disk.
This is the error that I am getting. I get it on both Windows XP with an IDE disk and Windows 2003 Enterprise 64-bit with a SCSI disk. It increases the size of the hard drive as seen in "edit properties" of the vm sucessfully. It boots up the OS in an attempt to resize the partitition of the OS. After about 20 minutes this error pops up. The VM hard drive is resized but the OS partition stays the same size. Any ideas? Thanks
This is typically the error you get when you are trying to resize the system disk of the guest OS.
As Pavel suggested use the HelperVM parameter to resize a system disk.
Btw I would advise you to use the correct VIX version.
It normally is installed automatically when you install PowerCLI.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK thanks - that must be the issue as this VM has only one hard disk and one partition. So I have a Windows XP VM that isn't being used and I want to dedicate it as my "helperVM", how does this "helperVM" need to be configured to allow this to work? It just need network connectivity to the VM I am resizing, and a hostname that I can feed to the -helperVM parameter? Is there anything else involved in configuring this helperVM?
Thanks
The harddisk you want to resize will be connected to the helperVM as an extra disk.
The helperVM will be powered on and the harddisk will be resized in the OS of the helperVM.
You don't need network connectivity between both VMs.
Both VMs should be powered off when you launch the Set-Harddisk cmdlet.
The name that you pass via the HelperVM parameter is the name of the virtual machine, the one you would use in a Get-VM.
That is not necessarily the hostname of that guest but is the name under which the VM is known on the vSphere server.
Don't forget to pass the guest credentials of the helperVM.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
In this case, most VMs in the environment have only one partition on only one virtual disk. So if resizing disks is needed, if I understand correctly I would then have to find out where the disk I'm trying to resize is on the datastore and then add the virtual disk to my helper VM to resize it and then add it back to its original VM again once done. By the time I did all that - it seems like it wouldn't really be saving any time as opposed to running partition resizing software or using VMware converter.
That is, unless there is some scripting wizardry where I can just enter the name of the VM whose disk I am resizing, the name of my helper VM, and the script does all of the above entire process for me?
Thanks again
No, you don't have to do that yourself.
The HelperVM parameter on the Set-Harddisk cmdlet will do all that (finding, connecting, starting the helper, resizin the HD,...) for you.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for all your help. It seems that what it has come down to is that this command requires authentication to the ESX server. That is great if you have a stand-alone ESX server that your VM never moves from. But what if your VM is in a cluster where it changes hosts frequently, and you are not using centralized authentication for your ESX servers? You don't know which credentials to enter when running the command, so you have to do research to make the command work - which all amounts to more time than just running a partioning tool. I can't understand why they don't make these commands run using just authentication to vCenter server instead of requiring authentication to the local ESX host. Anyway thanks for all the effort put in - maybe next PowerCLI version will be designed to work without this limitation especially as ESXi takes over in next version?