Windows how to find disk number of mounted VHD?

Q. Once you mount a VHD on Windows, how to find the disk number ‘n’ of the mounted vhd? This is required to access the mounted VHD in the disk form as \\.\PhyiscalDriven.

Ans:

Use below diskpart command, it lists all the mounted VHDs and their corresponding disk numbers.

DISKPART> list vdisk
VDisk ### Disk ### State Type File
 --------- -------- -------------------- --------- ----
 VDisk 0 Disk 2 Attached not open Expandable S:\UBMD.vhd
 VDisk 1 Disk 1 Attached not open Expandable C:\resOCB\test_0.vhd

From the example S:\UBMD.vhd is mounted at disk number 2 and C:\resOCB\test_0.vhd is mounted at disk number 1.

Advertisements

Windows how to find the boot disk?

Q. On a Windows server how to find which physical disk is boot disk?

Ans: diskpart.exe helps to identify which is the boot disk. Use following commands:

C:\Users\Administrator>diskpart
Microsoft DiskPart version 6.1.7601
 Copyright (C) 1999-2008 Microsoft Corporation.
 On computer: SYSTEMS11
DISKPART> list disk
  Disk ###  Status         Size     Free     Dyn  Gpt
   --------  -------------  -------  -------  ---  ---
   Disk 0    Online          465 GB  1024 KB
   Disk 1    Online          100 GB  2048 KB
   Disk 2    Online         7633 MB      0 B
DISKPART> select disk 0
Disk 0 is now the selected disk.
DISKPART> detail disk
WDC WD5000AAKX-001CA0 ATA Device
 Disk ID: 84BF18DB
 Type   : SATA
 Status : Online
 Path   : 0
 Target : 0
 LUN ID : 0
 Location Path : PCIROOT(0)#PCI(1F02)#ATA(C00T00L00)
 Current Read-only State : No
 Read-only  : No
 Boot Disk  : Yes
 Pagefile Disk  : Yes
 Hibernation File Disk  : No
 Crashdump Disk  : Yes
 Clustered Disk  : No
  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
   ----------  ---  -----------  -----  ----------  -------  ---------  --------
   Volume 0                      NTFS   Partition    100 MB  Healthy    System
   Volume 1     C                NTFS   Partition    165 GB  Healthy    Boot
   Volume 2     S   VM           NTFS   Partition    299 GB  Healthy

The “detail disk” command outputs below parameter which identifies whether the selected disk is boot disk or not:
Boot Disk  : Yes

The disk selected in example was the boot disk, if it was not the case the output for this parameter would have been:
Boot Disk  : No

On Windows XP I observed that diskpart’s “detail disk” has no “Boot Disk” entry in the output. In that case we can check the list of volumes displayed as output of “detail disk”. The disk which contains the volumes which “Boot” volume is the boot disk.

Windows how to get type (IDE/ATA/SATA/SCSI/USB/Virtual) of physical disk?

Q. On Windows server given the physical disk \\.\PHYSICALDRIVEn identify whether the disk is ATA, SATA. SCSI disk, USB disk or it is a mounted VHD file.

Ans:
There is no straightforward way in C++ to do this. Windows provide SetupDiEnumDeviceInterfaces APIs to get the properties of devices. But I found it bit complex to solve the problem mentioned.

On the other hand diskpart.exe provides simple interface to identify the type of the disk. Use following commands to get the type of disk:

C:\Users\Administrator>diskpart
Microsoft DiskPart version 6.1.7601
 Copyright (C) 1999-2008 Microsoft Corporation.
 On computer: SYSTEMS11
DISKPART> list disk
  Disk ###  Status         Size     Free     Dyn  Gpt
   --------  -------------  -------  -------  ---  ---
   Disk 0    Online          465 GB  1024 KB
   Disk 1    Online          100 GB  2048 KB
   Disk 2    Online         7633 MB      0 B
DISKPART> select disk 0
Disk 0 is now the selected disk.
DISKPART> detail disk
WDC WD5000AAKX-001CA0 ATA Device
 Disk ID: 84BF18DB
 Type   : SATA
 Status : Online
 Path   : 0
 Target : 0
 LUN ID : 0
 Location Path : PCIROOT(0)#PCI(1F02)#ATA(C00T00L00)
 Current Read-only State : No
 Read-only  : No
 Boot Disk  : Yes
 Pagefile Disk  : Yes
 Hibernation File Disk  : No
 Crashdump Disk  : Yes
 Clustered Disk  : No
  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
   ----------  ---  -----------  -----  ----------  -------  ---------  --------
   Volume 0                      NTFS   Partition    100 MB  Healthy    System
   Volume 1     C                NTFS   Partition    165 GB  Healthy    Boot
   Volume 2     S   VM           NTFS   Partition    299 GB  Healthy
DISKPART>

In the information provided by “detail disk” check the entry:
Type   : SATA 

If the physical disk is ATA drive the type entry in “detail disk” appear as:
Type   : ATA

If the physical disk is SCSI drive the type entry in “detail disk” appear as:
Type   : SCSI

If the physical disk is USB drive the type entry in “detail disk” appear as:
Type   : USB

If the physical disk is mounted VHD/VHDX file the type entry in “detail disk” appear as:
Type   : Virtual