how to find OS drives in dual boot system

I need to write an application that gets the drive letter of the os drives.
I normally get the the OS drive letter from the registry.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\Paging files key.
If it ia dual boot machine I wanted to list the other drive in which the system is not booted.
I wanted to list all the OS drives.
any registry key or any other way in which I can get the list of OS drives???

It depends on what you mean by ‘OS’ drive.

Whatever you’re definition, what you’re doing with that registry key won’t necessarily work. You don’t have to have a paging file.

I imagine that using the drive associated with GetSystemDirectory() would give you what you want as far as the current ‘OS’ drive, but after that, I’m not sure what to tell you to do other than parse the boot.ini or have a bunch of fun with whatever api it is that works with bcd (if you’re on Vista), followed by mount manager.

Good luck,

mm

xxxxx@yahoo.co.in wrote:

I need to write an application that gets the drive letter of the os drives.
I normally get the the OS drive letter from the registry.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\Paging files key.
If it ia dual boot machine I wanted to list the other drive in which the system is not booted.
I wanted to list all the OS drives.
any registry key or any other way in which I can get the list of OS drives???

Your question could mean several different things.

If you want to know the drive letters of all partitions that have
Windows installations on them, you can do that by enumerating all of the
drive letters on the machine, checking which ones are fixed disks, and
searching each top-level directory to see if it contains
system32\ntoskrnl.exe. That’s probably the most useful metric.

If you want to know the drive letters of all partitions that this
machine might boot too, you’ll need to read the BCD (boot configuration
data) for Vista and later, and/or boot.ini for XP and before.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

“If you want to know the drive letters of all partitions that this machine might boot”
The above is what I needed.

I can have a dual boot with both linux and windows in the same machine…

yeah I checked the boot.ini file.
I have something like the below.
But I was not sure how to map the below to the corresponding driveletter in which I have windows
installation.

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS=“Windows Server 2003, Enterprise” /noexecute=optout /fastdetect
multi(0)disk(0)rdisk(6)partition(1)\WINDOWS=“Windows Server 2003, Enterprise” /noexecute=optout /fastdetect

>>I wanted to list all the OS drives. any registry key or any other way in which I can get the list of OS drives???

>I can have a dual boot with both linux and windows in the same machine…

I do not think windows will have any mechanism to do this. You need to develop some decision based on information collected from all possible OS which your machine can have. An initial point to look for windows is already mentioned in above post by Tim you need to develop some thing similar for other OSes also.

You’ll not find boot.ini in Vista and above so I do not think it will do any good for the said task. Additionally it may not have all information in case Linux or Vista is installed as a second OS over XP, As they will not update the XP .ini file, so ini file will not have complete information in it.

Thanks
Aditya

multi(0)disk(0)rdisk(0)partition(1) etc are the physical positions the
harddisk the only method that i can suggest is to map this physical
locations to Logical location. IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS might
help.

dennis.scott

On Tue, Sep 15, 2009 at 1:53 PM, wrote:

> >>I wanted to list all the OS drives. any registry key or any other way in
> which I can get the list of OS drives???
>
> >>I can have a dual boot with both linux and windows in the same
> machine…
>
> I do not think windows will have any mechanism to do this. You need to
> develop some decision based on information collected from all possible OS
> which your machine can have. An initial point to look for windows is already
> mentioned in above post by Tim you need to develop some thing similar for
> other OSes also.
>
> You’ll not find boot.ini in Vista and above so I do not think it will do
> any good for the said task. Additionally it may not have all information in
> case Linux or Vista is installed as a second OS over XP, As they will not
> update the XP .ini file, so ini file will not have complete information in
> it.
>
> Thanks
> Aditya
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Try *QueryDosDevice*() win32 API which can give you unique volume name like
( \Device0\HardDiskVolume1); I hope from that you can write some algorithm
to match the drive letter with appropriate disk volume…

-Elango C

On Tue, Sep 15, 2009 at 5:38 PM, Dennis Scott
wrote:

> multi(0)disk(0)rdisk(0)partition(1) etc are the physical positions the
> harddisk the only method that i can suggest is to map this physical
> locations to Logical location. IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS might
> help.
>
> dennis.scott
>
>
> On Tue, Sep 15, 2009 at 1:53 PM, wrote:
>
>> >>I wanted to list all the OS drives. any registry key or any other way in
>> which I can get the list of OS drives???
>>
>> >>I can have a dual boot with both linux and windows in the same
>> machine…
>>
>> I do not think windows will have any mechanism to do this. You need to
>> develop some decision based on information collected from all possible OS
>> which your machine can have. An initial point to look for windows is already
>> mentioned in above post by Tim you need to develop some thing similar for
>> other OSes also.
>>
>> You’ll not find boot.ini in Vista and above so I do not think it will do
>> any good for the said task. Additionally it may not have all information in
>> case Linux or Vista is installed as a second OS over XP, As they will not
>> update the XP .ini file, so ini file will not have complete information in
>> it.
>>
>> Thanks
>> Aditya
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer


Elango C (இளங்கோ சொக்கலிங்கம்)
Chennai, India.
website:http://celango.blogspot.com

“Obstacles are those frightful things you see
when you take your eyes off your goal.”

>I need to write an application that gets the drive letter of the os drives.

I normally get the the OS drive letter from the registry.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory
Management\Paging files key.

The NtSystemRoot global variable of type UNICODE_STRING is also useful.

If it ia dual boot machine I wanted to list the other drive in which the system is not booted.

Impossible, unless by doing the heuristic examination of the other volume for the presense of the Windows files.

When the OS is booted from one volume, it does not care whether other volumes contain bootable OSes or not so.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

>multi(0)disk(0)rdisk(0)partition(1) etc are the physical positions the harddisk

These are the so-called ARC names.

You can find them in \ArcName object directory using undocumented (but working on all Windows versions, since WinObj works) Nt/Zw APIs like ZwQuerySymbolicLinkObject.

Then call QueryDosDevice on each existing drive letter, and compare the result with the contents of the ARC name symlink in the form of \ArcName\multi(0)disk(0)…

On a match, you know what drive letter corresponds to what boot.ini entry.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

xxxxx@yahoo.co.in wrote:

“If you want to know the drive letters of all partitions that this machine might boot”
The above is what I needed.

I can have a dual boot with both linux and windows in the same machine…

Windows doesn’t know anything about that. Are you hoping to learn about
the Linux partitions, too? If so, you’ll have to start reading the
partition tables directly, and that gets really ugly.

yeah I checked the boot.ini file.
I have something like the below.
But I was not sure how to map the below to the corresponding driveletter in which I have windows
installation.

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS=“Windows Server 2003, Enterprise” /noexecute=optout /fastdetect
multi(0)disk(0)rdisk(6)partition(1)\WINDOWS=“Windows Server 2003, Enterprise” /noexecute=optout /fastdetect

You can fetch this kind of information using WMI. Here’s a simple
VBscript that dumps this information:

dim obj, objs

Set objs =
GetObject(“winmgmts:”).InstancesOf(“Win32_LogicalDiskToPartition”)
for each obj in objs
msgbox(obj.Antecedent & vbcrlf & obj.Dependent)
next

There is probably an ioctl solution to this, but I don’t know it.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

I would reexamine the requirement to find all bootable|OS volumes on the
system.
You should not go tinkering with OS related files on other volumes.
A programming error could leave that OS volume in a state where it can
have problems booting up or otherwise.

Basically by doing this, your software is crossing the boundaries of
it’s playground.
Users would install your software on other OS if they need it there.

My $0.02 worth
Harish

-----Original Message-----
From: xxxxx@yahoo.co.in [mailto:xxxxx@yahoo.co.in]
Sent: Monday, September 14, 2009 8:51 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] how to find OS drives in dual boot system

“If you want to know the drive letters of all partitions that this
machine might boot”
The above is what I needed.

I can have a dual boot with both linux and windows in the same
machine…

yeah I checked the boot.ini file.
I have something like the below.
But I was not sure how to map the below to the corresponding driveletter
in which I have windows
installation.

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS=“Windows Server 2003,
Enterprise” /noexecute=optout /fastdetect
multi(0)disk(0)rdisk(6)partition(1)\WINDOWS=“Windows Server 2003,
Enterprise” /noexecute=optout /fastdetect


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer