Creating new virtual hard disk are the one of the major tasks which we done on virtual Machines. In Hyper-V creating a new virtual disk using PowerShell is very easy and straight forwarded process.
Without going much deeper, today we will create a simple virtual hard disk. To create a new virtual disk we do use the "New-VHD" cmdlet.
We can create a "Fixed Size" disk or a "Dynamic" disk. The only difference between them is, if you create a "Dynamic Disk" of 5GB, it only occupied the same as much has data it store, For example, if you create a 5GB of Dynamic Disk, and it has data of 3GB, then it occupied only 3 GB of disk space.
If we create a "Fixed Size" disk, then it doesn't matter how much data it may contain, it will use the full 5GB of Disk space.
Remember : By default " New-VHD" do create a Dynamic type of disk.
The Syntax is simple, use New-VHD and provide a path where you want to create a virtual disk (name with extension) and provide the size in GB, simple
" New-VHD -Path 'F:\VirtualMachines\Hyper-V\myHDD\myHDDynamic.vhd' -SizeBytes 5GB"
In above command , we are creating a new virtual hard disk name "myHDDynamic.vhd' " with the size of 5GB.
In the above screenshot , you can see that our command is completed successfully.
In the below screenshot, you can see that "Virtual Disk" is created, but the size of disk is only 16KB, Why? if you remember as I have mentioned above that by default "New-VHD " do create dynamic disk.
Now, if you want to create a "Fixed Size" virtual hard disk, we need to use the -Fixed parameter with the above command.
New-VHD -Path 'F:\VirtualMachines\Hyper-V\myHDD\myHDDFixed.vhd' -SizeBytes 5GB -Fixed
In the above command, we are creating a new virtual hard disk with the name of "myHDDFixed.vhd' " of 5GB in size, and we have provided the -Fixed parameter to define that we need a fixed type of hard disk not dynamic one.
You may notice, that this time, the creation of new virtual hard disk may took long time, this is because that it really creating a 5GB of disk image.
In the below screenshot, you can notice that the new hard disk image is really of 5GB of file size.
That's all for today, tomorrow we will mount these hard disk to the virtual machines.
Take care and keep smiling.