dsccommunity / StorageDsc

DSC resource module is used to manage storage on Windows Servers.
https://dsccommunity.org
MIT License
66 stars 51 forks source link

Disk resource trying to resize the partition even if it was not told to do so. #246

Open jojiklmts opened 4 years ago

jojiklmts commented 4 years ago

I have this very simple disk config. Just trying to set a label.

Disk CVolume
        {
             DiskId = ‘0’
             DriveLetter = ‘C’
             FSLabel = ‘System’
        }

However when the config is executed, DSC is trying to resize the disk for some reason. I am not telling it to touch the disk size. See below WARNING line.

VERBOSE: [server]: LCM: [ Start Resource ] [[Disk]CVolume]
VERBOSE: [server]: LCM: [ Start Test ] [[Disk]CVolume]
VERBOSE: [server]: [[Disk]CVolume] Test-TargetResource: Testing disk with Number ‘0’ status for drive letter ‘C’.
VERBOSE: [server]: [[Disk]CVolume] Test-TargetResource: Checking if disk with Number ‘0’ is initialized.
VERBOSE: [server]: [[Disk]CVolume] Perform operation ‘Query CimInstances’ with following parameters, ”queryExpression’ = SELECT BlockSize from Win32_Volume WHERE DriveLetter = ‘C:’,’queryDialect’ = WQL,’namespaceName’ = root\cimv2′.
VERBOSE: [server]: [[Disk]CVolume] Operation ‘Query CimInstances’ complete.
VERBOSE: [server]: [[Disk]CVolume] Test-TargetResource: Volume assigned to drive C label ” does not match expected label ‘System’.
VERBOSE: [server]: LCM: [ End Test ] [[Disk]CVolume] in 4.3440 seconds.
VERBOSE: [server]: LCM: [ Start Set ] [[Disk]CVolume]
VERBOSE: [server]: [[Disk]CVolume] Set-TargetResource: Setting disk with Number ‘0’ status for drive letter ‘C’.
VERBOSE: [server]: [[Disk]CVolume] Set-TargetResource: Checking disk with Number ‘0’ partition style.
VERBOSE: [server]: [[Disk]CVolume] Set-TargetResource: Disk with Number ‘0’ is already initialized with ‘GPT’.
VERBOSE: [server]: [[Disk]CVolume] Set-TargetResource: Partition ‘4’ is already assigned as drive C.
WARNING: [server]: [[Disk]CVolume] Set-TargetResource: Skipping resize of C from 106819485696 to 106820517376. AllowDestructive is not set to $true.
VERBOSE: [server]: LCM: [ End Set ] [[Disk]CVolume] in 3.0470 seconds.
VERBOSE: [server]: LCM: [ End Resource ] [[Disk]CVolume]

I talked with Daniel Scott-Raynsford and this seems to be the root cause: "The challenge there is that the resource is designed so that if you don't specify a size for the partition it assumes you want to make the partition/volume consume all remaining space on the disk. We could potentially implement a flag to force ignoring the size of the partition - if the partition already exists - that would resolve the problem"

PlagueHO commented 4 years ago

Suggest parameter name IgnoreSizeIfPartitionExists - this should suppress the size test in Test-TargetResource: https://github.com/dsccommunity/StorageDsc/blob/master/source/DSCResources/DSC_Disk/DSC_Disk.psm1#L831

A notification message should be included to indicate the size test was suppressed.

This should be enabled in DiskAccessPath once destructive changes are allowed - but as this feature has not been ported to that resource then we don't need to do this now.

PlagueHO commented 4 years ago

@jojiklmts - I'm just working on this, but can you confirm something for me: What was the label of C drive before and after applying the configuration? The logs you're seeing don't seem to match up with what I'd expect to see.

I would have expected to see:

  1. In the Test-TargetResource: the partition size was reported to be different.
  2. In the Set-TargetResource: The drive label should have been reported to be set to 'System'.

Neither message is shown, so this makes me think something else is wrong.

The reason Set is being run at all is because the Disk label mismatches - not because of the Disk size difference.

jojiklmts commented 4 years ago

So I removed now the "System" Label on purpose to demonstrate this.

PS C:\Windows\system32> Get-Volume -DriveLetter c

DriveLetter FileSystemLabel FileSystem DriveType HealthStatus SizeRemaining     Size
----------- --------------- ---------- --------- ------------ -------------     ----
C                           NTFS       Fixed     Healthy           85.08 GB 99.48 GB

Now I run the DSC config and I get the same as I shown before. It correctly identifies that the Label is not set correctly but before it attempts to correct it, it will stop because it is also trying to resize the volume (which it was not told to do) and it will halt because destructive change is not allowed:

VERBOSE: [S021MD9C3]: LCM:  [ Start  Resource ]  [[Disk]CVolume]
VERBOSE: [S021MD9C3]: LCM:  [ Start  Test     ]  [[Disk]CVolume]
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Test-TargetResource: Testing disk with Number '0' status for drive letter 'C'.
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Test-TargetResource: Checking if disk with Number '0' is initialized.
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Perform operation 'Query CimInstances' with following parameters, ''queryExpression' = SELECT BlockSize from Win32_Volume WHERE DriveLetter = 'C:','queryDialect' = WQL,'namespaceName' = root\cimv2'.
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Operation 'Query CimInstances' complete.
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Test-TargetResource: Volume assigned to drive C label '' does not match expected label 'System'.
VERBOSE: [S021MD9C3]: LCM:  [ End    Test     ]  [[Disk]CVolume]  in 4.4700 seconds.
VERBOSE: [S021MD9C3]: LCM:  [ Start  Set      ]  [[Disk]CVolume]
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Set-TargetResource: Setting disk with Number '0' status for drive letter 'C'.
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Set-TargetResource: Checking disk with Number '0' partition style.
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Set-TargetResource: Disk with Number '0' is already initialized with 'GPT'.
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Set-TargetResource: Partition '4' is already assigned as drive C.
WARNING: [S021MD9C3]:                            [[Disk]CVolume] Set-TargetResource: Skipping resize of C from 106819485696 to 106820517376. AllowDestructive is not
set to $true.
VERBOSE: [S021MD9C3]: LCM:  [ End    Set      ]  [[Disk]CVolume]  in 3.5320 seconds.
VERBOSE: [S021MD9C3]: LCM:  [ End    Resource ]  [[Disk]CVolume]

Now I set the Label manually to be "System" as can be seen below:

PS C:\Windows\system32> Get-Volume -DriveLetter c

DriveLetter FileSystemLabel FileSystem DriveType HealthStatus SizeRemaining     Size
----------- --------------- ---------- --------- ------------ -------------     ----
C           System          NTFS       Fixed     Healthy           85.07 GB 99.48 GB

And finally this is what DSC execution looks like when the Label is already set as "System":

VERBOSE: [S021MD9C3]: LCM:  [ Start  Resource ]  [[Disk]CVolume]
VERBOSE: [S021MD9C3]: LCM:  [ Start  Test     ]  [[Disk]CVolume]
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Test-TargetResource: Testing disk with Number '0' status for drive letter 'C'.
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Test-TargetResource: Checking if disk with Number '0' is initialized.
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Perform operation 'Query CimInstances' with following parameters, ''queryExpression' = SELECT BlockSize from Win32_Volume WHERE DriveLetter = 'C:','queryDialect' = WQL,'namespaceName' = root\cimv2'.
VERBOSE: [S021MD9C3]:                            [[Disk]CVolume] Operation 'Query CimInstances' complete.
VERBOSE: [S021MD9C3]: LCM:  [ End    Test     ]  [[Disk]CVolume]  in 4.4270 seconds.
VERBOSE: [S021MD9C3]: LCM:  [ Skip   Set      ]  [[Disk]CVolume]
VERBOSE: [S021MD9C3]: LCM:  [ End    Resource ]  [[Disk]CVolume]
jgriffiths014 commented 2 years ago

Hi, has this - or #248 been fixed yet? we're still having this issue on VMSS and the ex-colleague of mine ianwalkeruk raised this 2 years ago.

Thanks