How to know which device my kernel is booting from?

Programming, for all ages and all languages.
Post Reply
itsmevjnk
Member
Member
Posts: 32
Joined: Fri Apr 13, 2018 10:18 am
Location: Melbourne, VIC, Australia

How to know which device my kernel is booting from?

Post 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.
Just a procrastinating uni student doing stupid things (or not doing them at all)...

SysX: https://github.com/itsmevjnk/sysx.git
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

"boot_device" in the multiboot information structure.

https://www.gnu.org/software/grub/manua ... cification
User avatar
mkostoevr
Posts: 1
Joined: Sun Dec 24, 2017 12:55 am

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

Post 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).
User avatar
lkurusa
Member
Member
Posts: 42
Joined: Wed Aug 08, 2012 6:39 am
Libera.chat IRC: Levex
Location: New York, NY
Contact:

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

Post by lkurusa »

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

Lev
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

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

Post 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
User avatar
lkurusa
Member
Member
Posts: 42
Joined: Wed Aug 08, 2012 6:39 am
Libera.chat IRC: Levex
Location: New York, NY
Contact:

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

Post 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. :-)
Cheers,

Lev
Post Reply