Get disk ‘Allocation Unit Size’ with Powershell

When you are scripting SQL Server installtion, you can use powershell to perform pre-installation tasks and checks. One of these pre-installation tasks are to prepare the disk volumes on the server. For a SQL Server, the ‘Allocation Unit Size’ should be as large as possible. For most Windows Server version this is 64K. A SQL Server should split data, log, tempdb and backup into different LUN/disks, and these should be formatted with file system NTFS and the large ‘Allocation Unit Size’ at 64K.

My current disk/letter for a standard SQL Server installation is:

  • OS + SQL Binaries + system databses = C
  • Data disk = I
  • Log disk = J
  • Tempdb disk = K
  • Backup disk = M

The function below returns the ‘Allocation Unit Size’ for a given drive/disk:

function GetDiskAllocUnitSizeKB([char[]]$drive = $null)
    $wql = "SELECT BlockSize FROM Win32_Volume " + `
           "WHERE FileSystem='NTFS' and DriveLetter = '" + $drive + ":'"
    $BytesPerCluster = Get-WmiObject -Query $wql -ComputerName '.' `
                        | Select-Object BlockSize
    return $BytesPerCluster.BlockSize / 1024;

This function can be used to check and determine of a disk satisfy your requirements for SQL Server. My verification script should look like following for my data og log disk. Firstly, get the ‘allocation unit size’ for the disk. The next check will determine if the retrieved value is null or not equal to 64K. If one of these expressions hits TRUE, the script will return.

$dataSize = GetDiskAllocUnitSize 'I';
if ($dataSize -eq $null -or $dataSize -ne 64)
    Write-Host "Data disk 'I' should have allocation unit size of 64K"

$logSize = GetDiskAllocUnitSize 'J';
if ($logSize -eq $null -or $logSize -ne 64)
    Write-Host "Log disk 'J' should have allocation unit size of 64K"

Happy scripting….



5 thoughts on “Get disk ‘Allocation Unit Size’ with Powershell

  1. Pingback: Disk ‘Allocation Unit Size’ v2 | Sveroa's Developer Blog

  2. Pingback: Unattended install for SQL Server 2008 R2 | Sveroa's Developer Blog

  3. By the way, the 64K default allocation size is true for drives in most SANs. However, if you’re using a NetApp – leave the allocation size set to the default of 4K. NetApps want everything to be 4K. Learned this at SQL PASS last year.

    • Can you provide more info on this statement about NetApp and not using 64K default allocation size for drives on SQL?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.