Page 1 of 1

How to know which device my kernel is booting from?

Posted: Sun Apr 15, 2018 7:59 am
by itsmevjnk
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.

Re: How to know which device my kernel is booting from?

Posted: Sun Apr 15, 2018 9:12 am
by iansjack
"boot_device" in the multiboot information structure.

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

Re: How to know which device my kernel is booting from?

Posted: Thu Oct 04, 2018 6:10 am
by mkostoevr
"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).

Re: How to know which device my kernel is booting from?

Posted: Thu Oct 11, 2018 10:34 am
by lkurusa
I think an important question here, is why do you care?

Re: How to know which device my kernel is booting from?

Posted: Thu Oct 11, 2018 1:06 pm
by BenLunt
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

Re: How to know which device my kernel is booting from?

Posted: Thu Oct 11, 2018 11:49 pm
by lkurusa
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. :-)