VMware Cloud Community
hawks76
Enthusiast
Enthusiast

Extending Disk inside OS with Run Script in Guest/Run Program in Guest

I'm working on a workflow that i plan on publishing as an XAAS to our Windows Support Team to utilize that allows them to extend OS disks.  I have the code down to extend the vmdk, but i'm having issues extending the partition inside the OS.  I'm working of info from this blog post here.  I've also tried diskpart, but just can't seem to get this to work.  Anybody else get this to work, or maybe know how to do this?

Thanks

0 Kudos
12 Replies
daphnissov
Immortal
Immortal

The significant challenge here is not the in-guest partition extension, but the fact that you cannot programatically correlate the virtual disk IDs from the virtual hardware side to the mount points inside the guest. I've looked at that in the past and this is always the blocker. The issue arises when you have more than one disk of the same size and you wanted to extend one but not the other. There's no way to identify that disk from the other.

0 Kudos
hawks76
Enthusiast
Enthusiast

I've actually worked out identifying the disk.  I use the UUID of the disk to get the correct one.  That UUID spans vCenter and Guest OS (the guest os inherits the UUID from vCenter).  I just can't figure out the the in-guest partition extension part.  
0 Kudos
daphnissov
Immortal
Immortal

Where/how are you getting the disk's UUID?

0 Kudos
hawks76
Enthusiast
Enthusiast

this code run in the guest returns the UUID based on drive letter:

$driveletter = "%%driveLetter"

$colDiskDrives = get-wmiobject -query "Select * From Win32_DiskDrive"

 

$allDrive = @()

 

Foreach ($drive in $colDiskDrives)

{

         $o_drive = New-Object PSObject

         $a = $drive.DeviceID.Replace("\", "\\")

 

         if($drive.serialnumber -ne $null)

             {

                 $o_drive | Add-Member -type NoteProperty -Name UUID -value $drive.SerialNumber

                 $colPartitions = get-wmiobject -query "Associators of {Win32_DiskDrive.DeviceID=""$a""} WHERE AssocClass = Win32_DiskDriveToDiskPartition"

                 Foreach ($Partition in $colPartitions)

                 {

                     $b = $Partition.DeviceID

                     $colLogicalDisk = get-wmiobject -query "Associators of {Win32_DiskPartition.DeviceID=""$b""} WHERE AssocClass = Win32_LogicalDiskToPartition"

 

                     If ($colLogicalDisk.Caption -ne $null)

                         {

                             $o_drive | Add-Member -type NoteProperty -Name DriveLetter -value $colLogicalDisk.Caption.ToString()

                         }

                     Else

                         {

                             #No letter assigned.

                         }

                 }

             }

         else

         {

             #No UUID found.

         }

 

     $allDrive += $o_drive

     }

 

($allDrive | ? {$_.DriveLetter -eq "$($driveletter):"}).UUID.toUpper()

 

This code in a task, mathes the UUID returned from the guest to the UUID on the disk:

System.log(returned_uuid);

for each (var device in vm.config.hardware.device)

{

if (device instanceof VcVirtualDisk)

{

//System.log(device.backing.uuid);

//System.log(System.getModule("com.vmware.pscoe.library.util").replaceAll(device.backing.uuid,"-",""));

diskuuid = System.getModule("com.vmware.pscoe.library.util").replaceAll(device.backing.uuid,"-","").substring(0,31).toUpperCase();

if (diskuuid == returned_uuid.substring(0,31))

{

disk = device;

System.log(device);

}

}

}

 
$driveletter = "%%driveLetter"
$colDiskDrives = get-wmiobject -query "Select * From Win32_DiskDrive"
 
$allDrive = @()
 
Foreach ($drive in $colDiskDrives)
{
         $o_drive = New-Object PSObject
         $a = $drive.DeviceID.Replace("\", "\\")
 
         if($drive.serialnumber -ne $null)
             {
                 $o_drive | Add-Member -type NoteProperty -Name UUID -value $drive.SerialNumber
                 $colPartitions = get-wmiobject -query "Associators of {Win32_DiskDrive.DeviceID=""$a""} WHERE AssocClass = Win32_DiskDriveToDiskPartition"
                 Foreach ($Partition in $colPartitions)
                 {
                     $b = $Partition.DeviceID
                     $colLogicalDisk = get-wmiobject -query "Associators of {Win32_DiskPartition.DeviceID=""$b""} WHERE AssocClass = Win32_LogicalDiskToPartition"
 
                     If ($colLogicalDisk.Caption -ne $null)
                         {
                             $o_drive | Add-Member -type NoteProperty -Name DriveLetter -value $colLogicalDisk.Caption.ToString()
                         }
                     Else
                         {
                             #No letter assigned.
                         }
                 }
             }
         else
         {
             #No UUID found.
         }
 
     $allDrive += $o_drive
     }
 
($allDrive | ? {$_.DriveLetter -eq "$($driveletter):"}).UUID.toUpper()
0 Kudos
hawks76
Enthusiast
Enthusiast

Can you help with the in-guest partition expansion?
0 Kudos
daphnissov
Immortal
Immortal

This appears to be targeted towards Windows (PowerShell). I do have some code laying around if I can find it. The challenge with volume extensions is detecting how the existing volume/partition is configured and extending it in the same manner. Unless you know it's all going to be the same X way and you just code for that.

Your variable $driveletter = "%%driveLetter". How is this getting set? Replacing %%driveLetter with a drive letter causes a null value error on the last line.

0 Kudos
hawks76
Enthusiast
Enthusiast

Yes, this is geared towards Windows.  

So, the script is held in a resource.  I have the resource as a attribute on the workflow.  Then, in a task, i pass a variable in from the user input and replace it like this:

script = scriptResource.getContentAsMimeAttachment().content;

script = script.replace("%%driveLetter",driveLetter);

 
script = scriptResource.getContentAsMimeAttachment().content;
script = script.replace("%%driveLetter",driveLetter);
0 Kudos
daphnissov
Immortal
Immortal

I'm looking for my PS code but can't seem to locate it. Do you just need help with the PS in order to extend the filesystem?

0 Kudos
hawks76
Enthusiast
Enthusiast

No, i have the PS code.  I just can't get it to work when run from vro.
0 Kudos
daphnissov
Immortal
Immortal

Need some more information in that case. Can you share a full workflow with everything intact? Where are you getting a failure? Also, the driveletter variable, what is that supposed to be replaced with? Just a letter? Because if I sub that out in the PS I get a null value error.

0 Kudos
hawks76
Enthusiast
Enthusiast

Here is the full workflow.

I'm not getting any errors, but the script that runs at the end of the workflow to extend the disk inside the os just doesn't work.  same code works fine if run locally.

0 Kudos
hawks76
Enthusiast
Enthusiast

And just a side note, the disk.EnableUUID flag has to be set on the vm in order for all this to work.

0 Kudos