Hi,
So during boot the BIOS will give you a drive number (00h=floppy), (80h=hdd1) etc.
However given the number of combinations and emulations (USB as FDD, USB as HDD) etc these numbers are basically useless once you're not using BIOS calls any more... in long mode etc.
Assuming at this point you have implemented some device drivers for ATA/AHCI etc.. how do you go about determining the drive you actually booted off (possibly even a USB stick which would then require a full usb stack/mass storage driver) to be able to continue loading OS dependencies/files ?
Determine the real boot device
-
- Member
- Posts: 5590
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Determine the real boot device
You can get some of that information using int 0x13 ah=0x48, but not enough to determine the boot device in 100% of cases (and obviously won't work if the BIOS doesn't support that function).
You can save information about the boot device somewhere in your initrd-equivalent when your OS installs its boot information to a disk, but this won't work if the user reconfigures the disks.
Manual probing is probably your best bet, but you must do this carefully in case there are multiple devices from which your OS may have booted.
There may also be other strategies, but these are the only three I am aware of.
You can save information about the boot device somewhere in your initrd-equivalent when your OS installs its boot information to a disk, but this won't work if the user reconfigures the disks.
Manual probing is probably your best bet, but you must do this carefully in case there are multiple devices from which your OS may have booted.
There may also be other strategies, but these are the only three I am aware of.
Re: Determine the real boot device
Linux uses the kernel command line parameter root= for this.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
Re: Determine the real boot device
The most certain way is to *write* random data to a reserved sector on the boot disk using BIOS calls, then once you've using your own drivers, check each disk you find for that random data. So long as you use enough bits, that's essentially certain.
Re: Determine the real boot device
Hi,
For some things to consider:
Cheers,
Brendan
For some things to consider:
- You may have booted from network on a computer that doesn't have any disk drives of any kind.
- The OS may not have booted from a device at all (e.g. something like kexec).
- If you did boot from disk, it may be read-only (e.g. CD-ROM, a write-protected USB flash drive, etc).
- If you did boot from disk, there may be multiple physical devices involved (e.g. "BIOS RAID").
- For UEFI, the boot device may not be "yours" (e.g. UEFI system partition)
- The user may install multiple boot loaders to boot the same instance of the OS (e.g. one for hard disk MBR and one for UEFI system partition).
- The user may install multiple instances of the OS (e.g. 4 boot loaders for 4 separate instances of the same OS).
- The user may clone media (e.g. if you install the OS on one thing, the end user might clone it and replace the original with the clone); so some sort of marker written during OS installation (e.g. putting the hard disk's serial number into the boot loader) can fail.
- Multiple clones may be present (e.g. the OS might boot from CD, but there may be multiple CDs that are all identical clones).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: Determine the real boot device
On my side i would go with a volume serial number, like the one you find on any windows/dos partition. even if the serial number is small the chance you get 2 volume with the same serial, on the same computer at boot time, is slim. and since the "serial number" is set in your first sector of the partition it's loaded by the bios and you know the offset in memory. Then you just have to search for this serial when initialising your drives in your kernel.