Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

How to know which partition is Active?

- - - - -

  • Please log in to reply
12 replies to this topic

#1
MOONLIGHT SONATA

MOONLIGHT SONATA

    Member

  • Members
  • PipPip
  • 203 posts
Well mates, my problem started because of installing Windows XP into different partitions. I've my home hard disk partitioned into 4 primary partitions. Drive letters are C,D,G and H with letters E and F occupied by my CD/DVD drives. XP is 1st installed on C: and then I made active the Partition D: and installed XP there also. Now, as you all know probably, boot.ini is read by boot loader depending upon which partition is active. Therefore, to boot partition C: I've to incorporate its ARC path into the boot.ini that resides in Partition D:, because D: is the active partition.Here comes my problem. how could i conclusively know which partition is active at any moment and what drive letter has system assigned to it so that the editing of boot.ini could be done through a BATCH/CMD solution and if possible, even during unattended installation.

Any discussion in this regard is welcome.


REGARDS
MOONLIGHT SONATA


How to remove advertisement from MSFN

#2
strel

strel

    segmentation fault

  • Members
  • PipPipPipPip
  • 629 posts
  • OS:XP Pro x86
  • Country: Country Flag
On your example when you're installing XP on a recently active D:. Is not win creating a new boot loader in D:, as an active partition it is, which will call boot.ini in the same partition? That boot.ini in D: should have listed previously installed XP in C: as bootable. So boot.ini in C: is the one which should be edited for booting XP in D: in case C: become the active partition. Isn't it?

#3
MOONLIGHT SONATA

MOONLIGHT SONATA

    Member

  • Members
  • PipPip
  • 203 posts
Thank you, strel, for your opinion. what you said is right, but still i request you to imagine the scenario again.
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.

REGARDS
MOONLIGHT SONATA

#4
strel

strel

    segmentation fault

  • Members
  • PipPipPipPip
  • 629 posts
  • OS:XP Pro x86
  • Country: Country Flag
I think there's no point in detecting what's the active partition at install time. This is something you should state before making the install and decide if you want multiple boot loaders, one for each partition or only 1 in the first partition. But you seemed to prefer multiple, so you're going to activate each partition upon a install on it, and your problem should be edit boot.ini of the rest of the partitions to be updated to the new layout. So you don't need to detect the active partition, is the one you're installing on, you can obtain it from %HOMEDRIVE% variable.

#5
MOONLIGHT SONATA

MOONLIGHT SONATA

    Member

  • Members
  • PipPip
  • 203 posts
yeah, that i know. it's useless detecting active partition during install as install probably is running in an active partition, unless it's forced in a non-active one. you perhaps thought my emphasize is on detection during UA install, rather my thought is when i sit pretty in Partition 1 and edit the boot.ini at the root of it, from where we all are getting 100% SURE that this is the boot.ini that will be read when machine restarts? If diskmgmt.msc can guide us then why not all these through Windows XP's native command-lines and probably WMIC?

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.

thanks.

#6
Yz÷wl

Yz÷wl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

you called…

Try this:
@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)


#7
MOONLIGHT SONATA

MOONLIGHT SONATA

    Member

  • Members
  • PipPip
  • 203 posts
Well, Yz÷wl, script don't fail if it's pasted into a .cmd file and executed as it is. It only fails if i change it to something like this:
('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.

Attached Files



#8
Yz÷wl

Yz÷wl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

It didn't fail to work, I think it didn't do what you wanted from it.

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%


#9
MOONLIGHT SONATA

MOONLIGHT SONATA

    Member

  • Members
  • PipPip
  • 203 posts
Yz÷wl, I checked both these scripts. As I said earlier, i've 4 partitions, of which Partition 1(the 2nd) is currently active, though i'm writting this fast reply from Partition 0.
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.

Thanks.

REGARDS
MOONLIGHT SONATA

Edited by MOONLIGHT SONATA, 25 June 2009 - 10:00 PM.


#10
strel

strel

    segmentation fault

  • Members
  • PipPipPipPip
  • 629 posts
  • OS:XP Pro x86
  • Country: Country Flag
What about this? I'm supposing Disk 0 but it can be adjusted.

See post #13.

Edited by strel, 26 June 2009 - 01:47 PM.


#11
MOONLIGHT SONATA

MOONLIGHT SONATA

    Member

  • Members
  • PipPip
  • 203 posts
Well, strel, actpart.cmd gives following output:
Disk 0 Partition 1 is active partition with letter C:
Which actually is not.
PARTSTATE.TXT contains:
SELECT DISK 0
SELECT PART 1
SELECT PART 2
SELECT PART 3
SELECT PART 4
DETAIL PART
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.

REGARDS
MOONLIGHT SONATA

#12
MOONLIGHT SONATA

MOONLIGHT SONATA

    Member

  • Members
  • PipPip
  • 203 posts
strel, found the problem, you missed that DISKPART actually finds an active partition as SYSTEM and a partition that's booted into as BOOT.
so correct Partition NO. as well as the correct drive letter will be obtained by slightly modifying your code as noted below:
:GETACTIVEPART
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?
thanks.

#13
strel

strel

    segmentation fault

  • Members
  • PipPipPipPip
  • 629 posts
  • OS:XP Pro x86
  • Country: Country Flag
Your solution was erroneus too, "System" means an OS installed, the only pointer reliable in diskpart output is "Active: Yes". And that's it (ECHO OFF now sorry):

Attached File  actpart.cmd   688bytes   16 downloads
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.

Edited by strel, 27 June 2009 - 02:17 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN