Preparing a WinDRBD Disk by Using PowerShell

WinDRBD® presents data as Windows Disk objects to achieve maximum compatibility. Like physical disks, WinDRBD disks should contain a partition table, partition(s) and a file system in the partition.

Once you have configured your WinDRBD resource you will likely want to start using it. To make the resource visible to the Windows system, run following commands (replace `myres` with your resource name):

drbdadm up myres
drbdadm primary myres

Then you get a new empty virtual disk which is both offline and read only. You can see it for example by using the Control Panel's Disk Management utility (Windows meta key + R , `diskmgmt.msc`, <Enter>). To query the resource in PowerShell by WinDRBD minor number (42 in this example), use the following command:

Get-Disk | where { $_.Path -like "*#WinDRBD{0}#*" -f 42 }

Output from the command should show exactly one entry. If not, you need to fix that first.  Replace 42 with the WinDRBD minor number that you are using. If you need to find the minor  that you are using, you can enter the following command:

drbdadm dump myres

Locate your local node in the output and look for the device clause in the disk section.

To assign the disk to a PowerShell variable (`mydisk`), you can do the following:

$mydisk = Get-Disk | where { $_.Path -like "*#WinDRBD{0}#*" -f 1008 }

We now assume you did that. To show the content of the `$mydisk` variable, just enter:


Again it should print exactly one entry.

Now to set the disk both online and read/write, enter:

$mydisk | set-disk -IsOffline $false
$mydisk | set-disk -IsReadonly $false

As a last step, initialize the disk (which creates a partition table), create a partition on it, and then format the volume. You can do so with one PowerShell command:

$mydisk | Initialize-Disk -passthru | New-Partition -UseMaximumSize -DriveLetter X | format-volume

Replace `X` with the drive letter that you want to use. Note that this initialization takes the defaults which are:

  • Uses GPT for the partition style.
  • Creates one big partition on the entire disk.
  • Performs a quick format for NTFS on the partition.

That's it. You should now be able to access your new NTFS partition. To
test it you can enter the following command (replace `x` with your own drive letter):

dir x:

It should show no output because there are no (non-hidden) files on the partition yet.

If you are new to PowerShell, there is a short article that explains PowerShell syntax with a little more detail that you might find useful.

Written by JT, 02/16/2022

Reviewed by MAT, 02/21/2022