OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 4:18 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Determine the real boot device
PostPosted: Fri Feb 27, 2015 4:08 am 
Offline
Member
Member

Joined: Mon Oct 15, 2007 3:04 pm
Posts: 296
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 ?


Top
 Profile  
 
 Post subject: Re: Determine the real boot device
PostPosted: Fri Feb 27, 2015 5:07 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5137
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.


Top
 Profile  
 
 Post subject: Re: Determine the real boot device
PostPosted: Fri Feb 27, 2015 5:29 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
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


Top
 Profile  
 
 Post subject: Re: Determine the real boot device
PostPosted: Fri Feb 27, 2015 1:18 pm 
Offline
Member
Member

Joined: Mon Sep 07, 2009 12:01 pm
Posts: 149
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.


Top
 Profile  
 
 Post subject: Re: Determine the real boot device
PostPosted: Fri Feb 27, 2015 4:56 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

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).

For every method of detecting the boot device there is at least one corner-case where that method will fail. You need multiple different methods; and even with many different methods there are cases where you still can't determine the actual boot device.


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.


Top
 Profile  
 
 Post subject: Re: Determine the real boot device
PostPosted: Sat Feb 28, 2015 6:38 am 
Offline
Member
Member

Joined: Sun Sep 02, 2012 11:04 am
Posts: 30
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.

_________________
OS Website


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 154 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group