OSDev.org
https://forum.osdev.org/

How to know which device my kernel is booting from?
https://forum.osdev.org/viewtopic.php?f=13&t=32865
Page 1 of 1

Author:  weedboi6969 [ Sun Apr 15, 2018 7:59 am ]
Post subject:  How to know which device my kernel is booting from?

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.

Author:  iansjack [ Sun Apr 15, 2018 9:12 am ]
Post subject:  Re: How to know which device my kernel is booting from?

"boot_device" in the multiboot information structure.

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

Author:  mkostoevr [ Thu Oct 04, 2018 6:10 am ]
Post subject:  Re: How to know which device my kernel is booting from?

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

Author:  lkurusa [ Thu Oct 11, 2018 10:34 am ]
Post subject:  Re: How to know which device my kernel is booting from?

I think an important question here, is why do you care?

Author:  BenLunt [ Thu Oct 11, 2018 1:06 pm ]
Post subject:  Re: How to know which device my kernel is booting from?

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

Author:  lkurusa [ Thu Oct 11, 2018 11:49 pm ]
Post subject:  Re: How to know which device my kernel is booting from?

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/