MOONLIGHT SONATA Posted June 24, 2009 Posted June 24, 2009 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.REGARDSMOONLIGHT SONATA
strel Posted June 24, 2009 Posted June 24, 2009 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?
MOONLIGHT SONATA Posted June 25, 2009 Author Posted June 25, 2009 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 button2. BIOS POST screen3. Boot Choice Menu displayed, imagine it like below:First harddisk, first partitionFirst harddisk, second partitionFirst harddisk, third partitionFirst harddisk, fourth partitionWe'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.REGARDSMOONLIGHT SONATA
strel Posted June 25, 2009 Posted June 25, 2009 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.
MOONLIGHT SONATA Posted June 25, 2009 Author Posted June 25, 2009 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.
Yzöwl Posted June 25, 2009 Posted June 25, 2009 you called…Try this:@Echo off&SetlocalFor /f "skip=1 delims=" %%a In ( 'Wmic Partition Where "BootPartition=True" Get DeviceID') Do Call :GetEm %%aEcho/Booted to Partition %prt% on Disk %dsk% and assigned to Drive %drv%Goto :Eof:GetEmSet 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)
MOONLIGHT SONATA Posted June 25, 2009 Author Posted June 25, 2009 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.fixbini.cmd.txt
Yzöwl Posted June 25, 2009 Posted June 25, 2009 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&SetlocalFor /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%
MOONLIGHT SONATA Posted June 26, 2009 Author Posted June 26, 2009 (edited) 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.REGARDSMOONLIGHT SONATA Edited June 26, 2009 by MOONLIGHT SONATA
strel Posted June 26, 2009 Posted June 26, 2009 (edited) What about this? I'm supposing Disk 0 but it can be adjusted.See post #13. Edited June 26, 2009 by strel
MOONLIGHT SONATA Posted June 26, 2009 Author Posted June 26, 2009 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 0SELECT PART 1SELECT PART 2SELECT PART 3SELECT PART 4DETAIL PARTThe 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.REGARDSMOONLIGHT SONATA
MOONLIGHT SONATA Posted June 26, 2009 Author Posted June 26, 2009 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::GETACTIVEPARTFOR /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 PARTFOR /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.
strel Posted June 26, 2009 Posted June 26, 2009 (edited) 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):actpart.cmdAnd 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 June 27, 2009 by strel
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now