After deploying Virtual Machines from a template and adding disks the next Task was to create and format the partitions.
In a VMWare environment it is very important to assure that the partitions are aligned. VMWare has a nice document that explains the details called Performance Best Practices for VMware vSphere 4.0.
Basically the recommendation is to align partition on a 64 KB boundary, not only for VMWare itsself but also for the guests.
Of course we could do this manually but I wanted to run this task of from my Deployment Server to automate the following:
- Create aligned partitions on all extra disks of the maximum size
- Format, assign drive letter and assign a label
- A safeguard to prevent overwriting existing Data
@echo off
rem Create and Format D partition
rem We don't want to overwrite existing data!
if exist D:\ goto HALT
rem Create Diskpart Script
echo select disk 1 >DiskPart.txt
echo create partition primary align=64>>DiskPart.txt
echo assign letter=D>>DiskPart.txt
rem Create Partition
DiskPart /s DiskPart.txt
rem Format Partition
format d: /FS:NTFS /V:Data /q /A:32K /y
goto EXIT
:HALT
rem Return ACCESS DENIED
set ERRORLEVEL=5
:EXITAnd the second script:
@echo off
rem Create and Format E Partition
rem We don't want to overwrite existing data!
if exist E:\ goto halt
rem Create Diskpart Script
echo select disk 2 >DiskPart.txt
echo create partition primary align=64>>DiskPart.txt
echo assign letter=E>>DiskPart.txt
rem Create Partition
DiskPart /s DiskPart.txt
rem Format
format e: /FS:NTFS /V:Profiles /q /A:32K /y
goto EXIT
:HALT
rem Return ACCESS DENIED
set ERRORLEVEL=5
:EXIT
[...] we can launch DiskPart and create the partition (see here for a scripted [...]