BladeFireLight / WindowsImageTools

PowerShell Tools creating and updating Windows Images
MIT License
112 stars 27 forks source link

64K ALU Support? #11

Closed drstonephd closed 5 years ago

drstonephd commented 5 years ago

Being a DBA guy, I like some partitions to be formatted with a 64k allocation unit size. I don't see anything in an unattended xml that supports this; however, I'm adding the formatted VHDX drives before the deployment, so I could use New-DataVHD. Both NTFS and ReFS support 64K, so a 64K switch would work. For more general support, a ALU size parameter would be better.

Expected Behavior

Adding a ALU parameter value of 64KB to New-DataVHD would format a data partition using 64k allocation unit size. The OS drive would still use a 4 KB ALU.

Would there ever be a reason to use a smaller (e.g., 512) or a larger ALU for the OS partition? If so, perhaps the ALU parameter should apply for the data partition on the OS drive as well.

Current Behavior

The allocation unit size is always 4k.

Possible Solution

Add a parameter for the ALU to both New-DataVHD and Initialize-Partition

# Format drive using 4K or 64K allocation unit size rather then the default 4K (Only applies when DiskLayout = Data)
[int]
[ValidateSet(4KB, 64KB)]
$DataALU=4KB,

Update the hashtable in New-DataVHD used to pass values to Initialize-VHDPartition

$InitializeVHDPartitionParam = @{
    'Size'       = $Size
    'Path'       = $Path
    'force'      = $true
    'DiskLayout' = 'Data'
    'DataFormat' = $DataFormat
    'DataALU' = $DataALU
}

Update the data partition format code to use the ALU size.

#region Create the Primay partition
# Refresh $disk to update free space
$disk = Get-Disk -Number $disknumber | Get-Disk

$NewPartitionParam = @{
    DiskNumber = $disknumber
    Size       = $disk.LargestFreeExtent - $Recovery
}
if ($PartitionStyle -eq 'GPT') { $NewPartitionParam.add('GptType', '{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}') }
Write-Verbose "[$($MyInvocation.MyCommand)] [$disknumber] : Primary : Creating partition of [$($disk.LargestFreeExtent - $Recovery)] bytes"
Write-Verbose ($NewPartitionParam | out-string)
$windowsPartition = New-Partition @NewPartitionParam

$FileSystem = 'NTFS'
$AllocationUnitsize = 4KB
$Label = 'Windows'
if ($DiskLayout -eq 'Data')
{
    $FileSystem = $DataFormat
    $AllocationUnitsize = $DataALU
    $Label = 'Data'
}
Write-Verbose "[$($MyInvocation.MyCommand)] [$disknumber] : Primary : Formatting volume [$FileSystem]"
$null = Format-Volume -Partition $windowsPartition -NewFileSystemLabel $Label -FileSystem $FileSystem -Force -Confirm:$false -AllocationUnitSize $AllocationUnitsize
#endregion Primay Partiton

I have not tested this.

Steps to Reproduce (for bugs)

1. 2. 3. 4.

Context

Your Environment

drstonephd commented 5 years ago

I tested the changes you made. I now have a data partition with a 64k ALU. Thank you.

drstonephd commented 5 years ago

I'm new to GitHub. (Yep, dianosour here.) I'm not sure I'm the one to close this, but I will try. My first close.