Determine which is a Bootable Drive and System Drive?
Hello Guys
How to Determine which drive is bootable and which is a system drive. For example i have two drives on my machine physicaldrive0 and physicaldrive1. I determine the System Drive of my Machine by Calling GetSystemDirectory() and then determining whether its c: or d: or whatever. Then i do a deviceiocontrol to determine which physicaldrive the partition c: or d: belongs to. That gives me the physicaldrive with which the system has booted. But Consider the case of two drives say physicaldrive0 and physicaldrive1. I may have used physicaldrive0 for booting but my active partition that is c: is in physicaldrive1 and hence i get physicaldrive1 as system drive. How to determine the bootable drive?
Just as a note , You can get the scenario of bootable and system drives when u have two harddisks and u install a fresh copy of windows by selecting physicaldrive1. At that instant Windows formats physicaldrive0 as well and copies boot.ini,autoexec.bat,io.sys etc,, on to physicaldrive0 and rest of the stuff onto physicaldrive1.
Thank you very much and waiting for ur replies
Regards
Kandukondein
Re: Determine which is a Bootable Drive and System Drive?
Take a look at DeviceIoControl()...the lpOutBuffer will give the following information...
Code:
lpOutBuffer
Pointer to a buffer that will receive a PARTITION_INFORMATION data structure.
In the PARTITION_INFORMATION check out the "BOOLEAN BootIndicator; "
Re: Determine which is a Bootable Drive and System Drive?
Thank you let me check that quickly...
Re: Determine which is a Bootable Drive and System Drive?
Quote:
Originally Posted by kandukondein
How to Determine which drive is bootable and which is a system drive.
Could you be a bit more specific? What exacly you need to find out? What drives are bootable? Or maybe what drive was booted for current Windows session?
As you pointed, there might be several drives bootable, and which one exacly was booted (IDE1, IDE2, SCSI), depends on BIOS (and SCSI controller, if it was selected) configuration. And even in this case each bootable partition can have a number of load options (boot.ini), which will define what drive will finally be a system drive.
Moreover, the system may be booted from removable drive (Windows PE platform).
Re: Determine which is a Bootable Drive and System Drive?
IGor,
Quote:
Could you be a bit more specific? What exacly you need to find out? What drives are bootable? Or maybe what drive was booted for current Windows session?
Yes I need the drive that was booted for current windows session. Bootable and System drives are same for Single IDE machines but when it comes to multiple IDEs there could be chance for bootable drive to be different from current System Drive which has windows in it.
I have two IDE Drives. BIOS uses IDE 0 for booting but Windows is resident in IDE 1. Hence When Windows boots up and u go to disk management u can see IDE 0 as boot drive and IDE 1 as System Drive. I want to know whether there is an API directly or a DeviceIOControl in some way which would say IDE 0 is Bootable drive and IDE 1 as System Drive.
Right now i am able to Iterate my disks and am able to get IDE 1 as my Bootable as well as System Drive. This is because i know that my Windows is installed in D:\Windows. I do a DeviceIOControl with
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS on D: I get the corresponding disk number as 1(physicalDrive1). But the System had actually booted with C: which is in IDE 0.
Vanaj,
I am still trying ur hint. As far as i know i can determine whether that disk has a bootindicator set. But from that is it possible to determine which partition is bootable? For example in my case i got the Bootindicator set for IDE0 but how do i know from that , that it is C:\ supposing my IDE0 has both c:\ E:\ F:\ . Because i can get the extants of the Drive only not the friendly name.
Right now i am thinking of using the same DISK EXTENTS Deviceiocontrol to compare the extents and then determining what drive it is :eek: . I still feel that there should be a decent way to do this. :confused:
Thank you guys for ur generous help
Kandukondein.
Re: Determine which is a Bootable Drive and System Drive?
If this is not a dual boot system you can extract the info from the boot.ini file as to the disk/partition.
Re: Determine which is a Bootable Drive and System Drive?
Quote:
Originally Posted by kandukondein
Yes I need the drive that was booted for current windows session.
Afraid, you cannnot do that. Windows doesn't bother about what drive was used to run ntloader.
There might be an indirect way to find out what drive might have been used for running current Windows session. You read in the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control key the value of SystemBootDevice parameter - it would be something like
Quote:
multi(0)disk(0)rdisk(0)partition(1)
Now you iterate through boot.ini files you can find in your system HarddriveX\Partition1 partitions and search for this string. The file you found the string in is probably the file that have been used for booting, and therefore the partition (and drive) it resides in is probably boot partition (drive).
Re: Determine which is a Bootable Drive and System Drive?
Quote:
Originally Posted by Vanaj
If this is not a dual boot system you can extract the info from the boot.ini file as to the disk/partition.
It's funny, in multi boot system you can have a boot.ini on every physical drive of your system. The number of such drives could be even more than two or three... :wave:
Re: Determine which is a Bootable Drive and System Drive?
Quote:
Originally Posted by Igor Vartanov
It's funny, in multi boot system you can have a boot.ini on every physical drive of your system. The number of such drives could be even more than two or three... :wave:
Yes I'm aware of this that is why I said "If this is not a dual boot system".
Re: Determine which is a Bootable Drive and System Drive?
Quote:
Originally Posted by Vanaj
Yes I'm aware of this that is why I said "If this is not a dual boot system".
I'm not sure about "dual boot system" term. In general it's used for single boot.ini configuration with dual boot option. And in such configuration the partition which contains the boot.ini is a boot partition (the system partition detection never was a problem). Therefore, we never need to peer into boot.ini in such configuration.
But if your "dual boot" means the presence of two or more bootable physical drives in system, indeed you need to look through boot.ini files - but the thing is that the uniqueness of system boot partition record cannot be guaranteed across multiple boot.inis.
The information about what drive controller and drive device was used for bootstrapping is lost right after ntloader starts running the protected mode, since Window doesn't need it after that, I believe.