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 with Number '2' is already initialized with partition style '' but 'MBR' is required. #261

Open SergeDubovsky opened 2 years ago

SergeDubovsky commented 2 years ago

I am trying to initialize the disk in AWS. Here is the verbose log:

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Micr
osoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer OCTOPROVISION with user sid S-1-5-21-328967500-4131384653-1410793316-500.
VERBOSE: [OCTOPROVISION]: LCM:  [ Start  Set      ]
VERBOSE: [OCTOPROVISION]: LCM:  [ Start  Resource ]  [[WaitForDisk]Disk2]
VERBOSE: [OCTOPROVISION]: LCM:  [ Start  Test     ]  [[WaitForDisk]Disk2]
VERBOSE: [OCTOPROVISION]:                            [[WaitForDisk]Disk2] Test-TargetResource: Checking for disk with Number '1'.
VERBOSE: [OCTOPROVISION]:                            [[WaitForDisk]Disk2] Test-TargetResource: Found disk with Number '1' named 'AWS PVDISK'.
VERBOSE: [OCTOPROVISION]: LCM:  [ End    Test     ]  [[WaitForDisk]Disk2]  in 0.0470 seconds.
VERBOSE: [OCTOPROVISION]: LCM:  [ Skip   Set      ]  [[WaitForDisk]Disk2]
VERBOSE: [OCTOPROVISION]: LCM:  [ End    Resource ]  [[WaitForDisk]Disk2]
VERBOSE: [OCTOPROVISION]: LCM:  [ Start  Resource ]  [[Disk]VolumeD]
VERBOSE: [OCTOPROVISION]: LCM:  [ Start  Test     ]  [[Disk]VolumeD]
VERBOSE: [OCTOPROVISION]:                            [[Disk]VolumeD] Test-TargetResource: Testing disk with Number '2' status for drive letter 'D'.
VERBOSE: [OCTOPROVISION]:                            [[Disk]VolumeD] Test-TargetResource: Checking if disk with Number '2' is initialized.
VERBOSE: [OCTOPROVISION]:                            [[Disk]VolumeD] Test-TargetResource: Disk with Number '2' was not found.
VERBOSE: [OCTOPROVISION]: LCM:  [ End    Test     ]  [[Disk]VolumeD]  in 0.1090 seconds.
VERBOSE: [OCTOPROVISION]: LCM:  [ Start  Set      ]  [[Disk]VolumeD]
VERBOSE: [OCTOPROVISION]:                            [[Disk]VolumeD] Set-TargetResource: Setting disk with Number '2' status for drive letter 'D'.
VERBOSE: [OCTOPROVISION]:                            [[Disk]VolumeD] Set-TargetResource: Checking disk with Number '2' partition style.
VERBOSE: [OCTOPROVISION]:                            [[Disk]VolumeD] Set-TargetResource: Clearing disk with Number '2' of all existing partitions and volumes.
VERBOSE: [OCTOPROVISION]: LCM:  [ End    Set      ]  [[Disk]VolumeD]  in 0.2050 seconds.
PowerShell DSC resource DSC_Disk  failed to execute Set-TargetResource functionality with error message: System.InvalidOperationException: Disk with Number '2' is already initialized 
with partition style '' but 'MBR' is required. Set AllowDestructive and ClearDisk to $true to allow disk to be reinitialized. 
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost

VERBOSE: [OCTOPROVISION]: LCM:  [ End    Set      ]
The SendConfigurationApply function did not succeed.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost

VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.669 seconds

Here is the DSC:

            WaitForDisk Disk2
            {
                 DiskId = 1
                 RetryIntervalSec = 30
                 RetryCount = 5
            }

            Disk VolumeD
            {
                 DiskId = 2
                 DriveLetter = 'D'
                 FSLabel = 'Data'
                 AllowDestructive = 1
                 ClearDisk  = 1
                 PartitionStyle = 'MBR'
                 FSFormat = 'NTFS'
                 DependsOn = '[WaitForDisk]Disk2'
            }

It doesn't matter if I set MBR or GPT. It doesn't do anything with ClearDisk /AllowDestructive

Here is the data from Get-Disk on that instance:
DiskNumber            : 1
PartitionStyle        : RAW
ProvisioningType      : Fixed
OperationalStatus     : Offline
HealthStatus          : Healthy
BusType               : SAS
UniqueIdFormat        : SCSI Name String
OfflineReason         : Policy
ObjectId              : {1}\\OCTOPROVISION\root/Microsoft/Windows/Storage/Providers_v2\WSP_Disk.ObjectId="{0da1f051-af79-11ec-836a-806e6f6e6963}:DI:\\?\scsi#disk&ven_aws&prod_pvdisk#0001
                        00#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}"
PassThroughClass      : 
PassThroughIds        : 
PassThroughNamespace  : 
PassThroughServer     : 
UniqueId              : vol0395d3d476578e0b7
AdapterSerialNumber   : 
AllocatedSize         : 0
BootFromDisk          : False
FirmwareVersion       : 1.0.0.0
FriendlyName          : AWS PVDISK
Guid                  : 
IsBoot                : False
IsClustered           : False
IsHighlyAvailable     : False
IsOffline             : True
IsReadOnly            : True
IsScaleOut            : False
IsSystem              : False
LargestFreeExtent     : 0
Location              : Integrated : Adapter 2 : Port 0 : Target 1 : LUN 0
LogicalSectorSize     : 512
Manufacturer          : AWS     
Model                 : PVDISK          
Number                : 1
NumberOfPartitions    : 0
Path                  : \\?\scsi#disk&ven_aws&prod_pvdisk#000100#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}
PhysicalSectorSize    : 512
SerialNumber          : vol0395d3d476578e0b7
Signature             : 
Size                  : 8589934592
PSComputerName        : 
CimClass              : ROOT/Microsoft/Windows/Storage:MSFT_Disk
CimInstanceProperties : {ObjectId, PassThroughClass, PassThroughIds, PassThroughNamespace...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

Thank you.

SergeDubovsky commented 2 years ago

Found it. This happens with DiskID = 2, when I don't have such disk ID. Still, it would be useful to check if the disk exists and throw a more meaningful message.

Thank you.