Finding which partition on a particular disk is active from the command line

Only way I know how to do this is close to what @Maximus put but do the following:

diskpart.exe
select volume 1
detail partition

The output will indicate

Active: Yes/No

For example: enter image description here

You have to go through each volume to find which ones are Active and which ones are not. You can use Diskpart's list volume command to show all volumes and find the one you want to check first.


You can use wmic to do this. You may wish to export it to a text file (>output.txt) and view without word wrapping since the tabular output can get very wide.

To list all partitions (look at the BootPartition member to check if it's marked as active):

wmic partition

To list just active partitions, filter with where:

wmic partition where BootPartition=true

To filter which columns are displayed, use get:

wmic partition where BootPartition=true get DeviceID,Size

Also:

wmic partition get DeviceID,Size,BootPartition

For more information on partition members, see the Win32_DiskPartition documentation.

BootPartition

Data type: boolean Access type: Read-only

Partition is the active partition. The operating system uses the active partition when booting from a hard disk.


Take a look at the WQL syntax for more information on the usage of where. Take a look at wmic partition get /? for more information on get.


With wmic you have added advantages with remote management using the /node:<servername or ip> switch (see wmic /node /? for more information. As per Microsoft:

WMIC can be used from any computer with WMIC enabled to remotely manage any computer with WMI. WMIC does not have to be available on the remotely managed computer in order for WMIC to manage it.


If you can figure out some way of programmatically (e.g. batch script) getting the drive letter from the disk and partition index, you may wish to use a for loop with the members DiskIndex and Index (disk and partition indexes, respectively).


As a fans of Cygwin, I'll suggest use the fdisk utility from the util-linux package to do this if you're not using GPT.

If you're remoting into a system, you need to install Cygwin on that system.

If you're booting from Windows PE, you can manually download the packages and extract them using a proper decompressor which can handle .tar.bz2 files.

Packages needed to download to run fdisk

  • util-linux
  • util-linux/libblkid1
  • util-linux/libuuid1
  • cygwin
  • libiconv/libiconv2
  • gettext/libintl8
  • gcc4/libgcc1

Example (1 hdd, 1 flash drive)

$ uname -svr
CYGWIN_NT-5.1 1.7.17(0.262/5/3) 2012-10-19 14:39

$ /usr/sbin/fdisk -l | grep /dev/
Disk /dev/sda: 320.1 GB, 320072933376 bytes
/dev/sda1   *          63    83891429    41945683+   7  HPFS/NTFS/exFAT
/dev/sda2        83891430   625137344   270622957+   f  W95 Ext'd (LBA)
/dev/sda5        83891493   503332514   209720511    7  HPFS/NTFS/exFAT
/dev/sda6       503332578   625137344    60902383+   7  HPFS/NTFS/exFAT
Disk /dev/sdb: 8065 MB, 8065646080 bytes
/dev/sdb1   *          32    15753214     7876591+   b  W95 FAT32