Format NTFS disk with allocation unit size of 64K via PowerShell

In a previous post I showed you how to get the allocation unit size of a Windows disk. In this post I will show you how to set it using PowerShell.

To set the allocation unit size in the GUI, follow the normal steps to format a drive and in the Format Partition box select 64K in the Allocation unit size drop-down per the below:

20160829170230

Provide a Volume Label if desired, then click Next and Finish, after which your drive will be formatted with NTFS with an allocation unit size of 64K.

To do this in PowerShell, run the script below:

$Disk = Get-Disk -Number 1
Set-Disk -InputObject $Disk -IsOffline $false
Initialize-Disk -InputObject $Disk
New-Partition $Disk.Number -UseMaximumSize -DriveLetter E
Format-Volume -DriveLetter E -FileSystem NTFS -AllocationUnitSize 65536 -NewFileSystemLabel DATAFILES -Confirm:$false

The script above will get Disk 1 in Disk Management and initialize it, bring it online, assign it letter E, format it with NTFS and an allocation unit size of 64K and assign it the label DATAFILES.

I found a great script here for performing the same task as above.

References:
Format-Volume
PowerShell Script to Configure SQL Server Storage

Convert sparse disk to thick disk

After adding a customer supplied vmdk file to a VM in vCenter I noticed that it was a sparse disk:

20130531115021

It was originally created in VirtualBox which uses this format. To take advantage of the features of thick disk we had to convert it using the vmkfstools command. To do this perform the following steps:

1. SSH onto the ESX server and navigate to the folder containing the vmdk file in sparse format.

[root@ESX1]# cd /vmfs/volumes/san-datastore1/VM1

2. Run the following command to convert VM1.vmdk to VM1-thick.vmdk:

vmkfstools -i VM1.vmdk -d eagerzeroedthick  VM1-thick.vmdk

The result will be as follows:

[root@ESX1]# vmkfstools -i "VM1.vmdk" -d eagerzeroedthick "VM1-thick.vmdk"
Destination disk format: VMFS eagerzeroedthick
Cloning disk 'VM1.vmdk'...
Clone: 100% done.

3. Once it completes remove the old sparse disk and then add the newly created thick disk, which is VM1-thick.vmdk, to the VM. You will now see that the format of the disk has changed to thick:

20130531120533

4. Power on the VM and ensure it is working properly.

Reference: vmkstools command syntax