How to know which partition is Active?
Posted 24 June 2009 - 12:36 PM
Any discussion in this regard is welcome.
Posted 24 June 2009 - 01:17 PM
Posted 25 June 2009 - 12:32 AM
1. Pressed the power button
2. BIOS POST screen
3. Boot Choice Menu displayed, imagine it like below:
First harddisk, first partition
First harddisk, second partition
First harddisk, third partition
First harddisk, fourth partition
We've two options at this stage - either push one choice from the menu and when desktop loads, start diskmgmt.msc from run box and know which partition is active, or, go back by pressing ctrl+alt+del and push a PE CD, then boot the PE and there again start any compatible application to learn which is active partition.
You may agree with me, all these are workarounds to the problem, not the solution. I want to conclusively know which partition is active and what is its drive letter, before I push a script to modify boot.ini - be it to add a /kernel=somename.exe switch, or add a /hal=440volts.dll switch to bind the booting of one OS to a specific hardware abstraction layer.
I hope I explained the necessity of my thinking in this regard.
Posted 25 June 2009 - 07:40 AM
Posted 25 June 2009 - 10:01 AM
Someone VERY VERY SPECIAL and very close to my heart both in terms of esteem and effort that he generates in me for him read my topic starter when i 1st posted it. I keep my fingers crossed. Perhaps it's my inability that i couldn't drive home the point behind this whole thinking. Sorry, mate.
Posted 25 June 2009 - 10:39 AM
@Echo off&Setlocal For /f "skip=1 delims=" %%a In ( 'Wmic Partition Where "BootPartition=True" Get DeviceID') Do Call :GetEm %%a Echo/Booted to Partition %prt% on Disk %dsk% and assigned to Drive %drv% Goto :Eof :GetEm Set dp="%*" For /f "tokens=3,5,7 delims==#, " %%a In ( 'Wmic Path Win32_LogicalDiskToPartition Get Antecedent^, Dependent^ ^|Find %dp%') Do Set "drv=%%~c"&Set "dsk=%%a"&Set "prt=%%b)
Posted 25 June 2009 - 12:01 PM
('Wmic Path Win32_LogicalDiskToPartition Get Antecedent^, Dependent^^|Find %dp%')
Output is : | is unexpected at this time.
meanwhile i'm attaching a cmd script which i made and use for adding a /hal= switch depending upon a specific HAL type. That, though a rudimentary one, still throws light why knowing active partitions' drive letter is mandatory.
Number of downloads: 7
Posted 25 June 2009 - 01:20 PM
The script was actually returning the data for the Boot partition, the trouble is that in many cases there is only one boot partition, meaning that regardless of which partition you were currently booted to the result would be the same.
I will return the code as was and provide this more compact solution to return the partition and disk of the currently booted system.
@Echo off&Setlocal For /f "tokens=3,5,7 delims==#, " %%a In ( 'Wmic Path Win32_LogicalDiskToPartition Get Antecedent^, Dependent^ ^|Find "%SystemDrive%"') Do Set "drv=%%~c"&Set "dsk=%%a"&Set "prt=%%b) Echo/Booted to Partition %prt% on Disk %dsk% and assigned to Drive %drv%
Posted 25 June 2009 - 09:58 PM
output for the earlier script is:
Booted to Partition 1 on Disk 0 and assigned to Drive D:
output for the last one you posted is:
Booted to Partition 0 on Disk 0 and assigned to Drive C:
What i understand with my limited knowledge is that the 1st output detects the active boot device and its assigned drive letter, while the 2nd one detects the currently booted partition. In case of a single partition system as we find in enterprises, both the output will be same.
One problem that always pinned me is that while WMI returns partitions as 0,1,2,3,...,
boot loader reads boot.ini and boots partitions on the basis of Partition(1),(2),(3),(4)... I thought about Get Antecedent and correlating with actual drive letters, but it was beyond my imagination that Get Antecedent^, Dependent could be used in a single query. I never found anything in net like that.
You are genius. It's imagination of a genius; Google can search only what is recorded in fine print, it can't guess what genius holds in his imagination.
This post has been edited by MOONLIGHT SONATA: 25 June 2009 - 10:00 PM
Posted 26 June 2009 - 12:11 PM
Disk 0 Partition 1 is active partition with letter C:
Which actually is not.
SELECT DISK 0
SELECT PART 1
SELECT PART 2
SELECT PART 3
SELECT PART 4
The correct description would have to be:
Disk 0 Partition 2 is active partition with letter D:
Probing the script why it failed. inform you latter.
Posted 26 June 2009 - 12:32 PM
so correct Partition NO. as well as the correct drive letter will be obtained by slightly modifying your code as noted below:
FOR /F "TOKENS=2" %%A IN ('DISKPART /S GETPARTNUM.TXT^|FINDSTR /I "Primary Logical"') DO (
ECHO>PARTSTATE.TXT SELECT DISK %HDNUM%
ECHO>>PARTSTATE.TXT SELECT PART %%A
ECHO>>PARTSTATE.TXT DETAIL PART
FOR /F "TOKENS=4" %%B IN ('DISKPART /S PARTSTATE.TXT^|FINDSTR /I "System"') DO SET PARTNUM=%%A&SET LETTER=%%B&GOTO :EOF
What you think about the static HDNUM=0?
Posted 26 June 2009 - 12:47 PM
Number of downloads: 14
And about static %HDNUM%... if you're using it on a installed OS simply value could be changed manually or user could be asked about what HD to check; and if used during an installing process, again user can be asked, or script could check with diskpart what's the HD of %HOMEDRIVE%, provided that you are probably tryining to modify the boot.ini of the active partition of the BIOS selected bootable HD.
I've been investigating what WMIC can get from BIOS and I couldn't find how to get the HD booting order, which maybe could help you.
This post has been edited by strel: 27 June 2009 - 02:17 PM