OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 10:39 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to know which device my kernel is booting from?
PostPosted: Sun Apr 15, 2018 7:59 am 
Offline
Member
Member

Joined: Fri Apr 13, 2018 10:18 am
Posts: 32
Location: Melbourne, VIC, Australia
Hi,
Is there a way for my kernel to know which device (HDD/CD/floppy) it's booting from? I'm using GRUB as my kernel's bootloader by the way.

_________________
Just a procrastinating uni student doing stupid things (or not doing them at all)...

SysX: https://github.com/itsmevjnk/sysx.git


Top
 Profile  
 
 Post subject: Re: How to know which device my kernel is booting from?
PostPosted: Sun Apr 15, 2018 9:12 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
"boot_device" in the multiboot information structure.

https://www.gnu.org/software/grub/manua ... cification


Top
 Profile  
 
 Post subject: Re: How to know which device my kernel is booting from?
PostPosted: Thu Oct 04, 2018 6:10 am 
Offline
User avatar

Joined: Sun Dec 24, 2017 12:55 am
Posts: 1
"But what about custom bootloader?"?

At start BIOS gives you boot drive ID in DL register. This ID may be used in int 13 (AH = 48h) to get PCI path of drive (http://www.ctyme.com/intr/rb-0715.htm).


Top
 Profile  
 
 Post subject: Re: How to know which device my kernel is booting from?
PostPosted: Thu Oct 11, 2018 10:34 am 
Offline
Member
Member
User avatar

Joined: Wed Aug 08, 2012 6:39 am
Posts: 42
Location: New York, NY
I think an important question here, is why do you care?

_________________
Cheers,

Lev


Top
 Profile  
 
 Post subject: Re: How to know which device my kernel is booting from?
PostPosted: Thu Oct 11, 2018 1:06 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
lkurusa wrote:
I think an important question here, is why do you care?

That is a good question. Let me give you a few.

1) How do you know which partition to make as the active partition?
2) What if you have more than one partition with similar bootable Operating Systems?
3) If you boot to a TUI prompt, what partition do you place in the prompt? (i.e.: A DOS like would be C:\>)
4) What partition do you use to continue loading kernel and driver files from?

Here is an example. Let's say that you have multiple partitions / multiple drives with multiple partitions each. How do you know which one of the partitions you booted from so that you know which partition to continue loading the kernel files from? This is an issue with lots of scenarios.

What if I have two drives with similar operating systems. How do I know which drive I booted from so that I load the files from the correct operating system?

I put a signature in the boot sector of the partition and then my kernel, during partition enumeration, checks for this signature, along with a few other checks, then "marks" a partition as the booted from partition. Other operating systems do this as well.

Ben
- http://www.fysnet.net/osdesign_book_series.htm


Top
 Profile  
 
 Post subject: Re: How to know which device my kernel is booting from?
PostPosted: Thu Oct 11, 2018 11:49 pm 
Offline
Member
Member
User avatar

Joined: Wed Aug 08, 2012 6:39 am
Posts: 42
Location: New York, NY
BenLunt wrote:
lkurusa wrote:
I think an important question here, is why do you care?

That is a good question. Let me give you a few.

1) How do you know which partition to make as the active partition?


Normally, this information is stored when the OS is formally "installed". It can be in /etc/fstab, in the boot configuration, or somewhere else.

An option would what Linux does, root= kernel command line argument that uniquely identifies the root partition (via UUID or slot#). Now, of course this gives the task of determining the root partition to the root user or the bootloader. Your bootloader could then ask the firmware and just pass that on to the kernel.

BenLunt wrote:
2) What if you have more than one partition with similar bootable Operating Systems?
3) If you boot to a TUI prompt, what partition do you place in the prompt? (i.e.: A DOS like would be C:\>)
4) What partition do you use to continue loading kernel and driver files from?

Here is an example. Let's say that you have multiple partitions / multiple drives with multiple partitions each. How do you know which one of the partitions you booted from so that you know which partition to continue loading the kernel files from? This is an issue with lots of scenarios.

What if I have two drives with similar operating systems. How do I know which drive I booted from so that I load the files from the correct operating system?

I put a signature in the boot sector of the partition and then my kernel, during partition enumeration, checks for this signature, along with a few other checks, then "marks" a partition as the booted from partition. Other operating systems do this as well.


I think my answer above answers all these, too. :-)

_________________
Cheers,

Lev


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: No registered users and 21 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