dsccommunity / StorageDsc

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

xDisk: PartitionStyle parameter is non-configurable #137

Closed DelectableMechanisations closed 6 years ago

DelectableMechanisations commented 6 years ago

I'm having some trouble with the xDisk DSC Resource.

To give you some background I have written a DSC Bootloader script that dynamically generates a DSC Configuration Data file (.psd1) and, among other things, adds the server's disks into this. Here is the relevant sample portion of my Configuration Data file:

@{
    AllNodes = @(
        @{
            NodeName = 'TS2016-DEV01'

            Storage = @(
                @{
                    #Current Disk Size: 49.51GB (Disk Number 0)
                    #-------------------------------------------
                    DiskId             = 'SCSI\DISK&VEN_VMWARE&PROD_VIRTUAL_DISK\5&1982005&0&000000:TS2016-dev01'
                    DiskIdType         = 'UniqueId'
                    DriveLetter        = 'C'
                    FSLabel            = 'TS2016-DEV01-C-SystemOS'
                    AllocationUnitSize =  4096
                    FSFormat           = 'NTFS'
                }

                @{
                    #Current Disk Size: 10GB (Disk Number 1)
                    #-----------------------------------------
                    DiskId             = 'SCSI\DISK&VEN_VMWARE&PROD_VIRTUAL_DISK\5&1982005&0&000100:TS2016-dev01'
                    DiskIdType         = 'UniqueId'
                    DriveLetter        = 'H'
                    FSLabel            = 'TS2016-DEV01-H-TempDB'
                    AllocationUnitSize =  65536                            #Alternate Values: 65536
                    FSFormat           = 'NTFS'                           #Alternate Values: REFS
                }

                @{
                    #Current Disk Size: 11GB (Disk Number 2)
                    #-----------------------------------------
                    DiskId             = 'SCSI\DISK&VEN_VMWARE&PROD_VIRTUAL_DISK\000000:TS2016-dev01'
                    DiskIdType         = 'UniqueId'
                    DriveLetter        = 'E'
                    FSLabel            = 'TS2016-DEV01-E-SQLData'
                    AllocationUnitSize =  65536                            #Alternate Values: 65536
                    FSFormat           = 'NTFS'                           #Alternate Values: REFS
                }
            )
        }
    )
}

For completeness here is the portion of the DSC Composite resource that deals with this block of data:

    if ($Disks.Count -ge 1) {
        foreach ($Disk in $Disks) {

            #Replace any non-alphanumeric characters with a '_' (e.g. - or .)
            $DiskIdString = "$($Disk.DriveLetter + '_' + $Disk.FSLabel)" -Replace "\W",'_'

            #Provision each disk specified in the input.
            xDisk "DiskProvision_$($DiskIdString)" {
                DriveLetter        = $Disk.DriveLetter
                DiskId             = $Disk.DiskId
                DiskIdType         = $Disk.DiskIdType
                FSLabel            = $Disk.FSLabel
                AllocationUnitSize = $Disk.AllocationUnitSize
                FSFormat           = $Disk.FSFormat
                DependsOn          = '[cCdDriveLetter]CDDriveLetter'
            }
        }
    }

Running 'Test-DscConfiguration' returns $false on the C: drive (but works fine for all other disks). Checking the Verbose output reveals that it is because it is configured with MBR instead of GPT. [[xDisk]DiskProvision_C_TS2016_DEV01_C_SystemOS::[cBaseStorage]CCCStorage] Test-TargetResource: Disk with UniqueId 'SCSI\DISK&VEN_VMWARE&PROD_VIRTUAL_DISK\5&1982005&0&000000:TS2016-dev01' is initialized with 'MBR' partition style. GPT required.

Reviewing the code for this resource I can see that 'Test-TargetResource' is hardcoded to return $false if the partition style is not GPT.

    if ($disk.PartitionStyle -ne 'GPT')
    {
        Write-Verbose -Message ( @(
                "$($MyInvocation.MyCommand): "
                $($localizedData.DiskNotGPTMessage -f $DiskIdType, $DiskId, $Disk.PartitionStyle)
            ) -join '' )

        return $false
    } # if

Are there any plans to update this in the future so that it works with both GPT and MBR?

I have made my own version of this resource (cDisk) with a dedicated 'PartitionStyle' parameter that I'm happy to share.

OS: Windows Server 2016 and PowerShell v5 DSC Resource: xStorage (dev branch)

P.S. Not related to my issue but you people are doing a great job keeping all the DSC Resources up to date. I've been tinkering with DSC for about 18 months now and the quality of coding I saw back then to what I'm seeing now is just so much higher. The resources have a more modular design, there's a 'Get-Help' section on most of the functions and most of the DSC properties now have descriptions.

Keep up the good work people!

PlagueHO commented 6 years ago

Hi @DelectableMechanisations - thank you so much for the kind compliments! The community is definitely working really hard to bring the quality up of all modules in the DSC Resource kit. It makes me happy to know it is noticed :grin:

Anyway, on to the MBR: actually I had noticed this too sometime back, but for some reason never added the feature. But if you've got code and would be happy to contribute it to the resource kit then we're more than happy to accept it - the more help the better! This would be a great feature to get implemented.

tom-dudley commented 6 years ago

@DelectableMechanisations Do you mind if I make a PR on your behalf to get this useful addition merged?

rukas commented 6 years ago

It would be great if this gets merged. Would totally help my use case!