Page 1 of 1
[SOLVED] Get device booted
Posted: Sun Apr 07, 2013 1:10 am
by HugeCode
Hi all. I'm trying to load my kernel reading filesystem and I don't know which disk should I read.
Does anybody have any idea how can I get the device which was booted? If it was HDD or floppy, primary or secondary bus, master or slave....
I don't think that reading first sector on each drive and then comparing it with actual bootsector would be accurate (there can be same OS on two HDDs).
Re: Get device booted
Posted: Sun Apr 07, 2013 2:01 am
by dozniak
BIOS gives the bootloader information about boot device in DL upon giving it control.
It's up to bootloader to save it. iirc GRUB puts it into boot_device variable somewhere in multiboot info block.
Re: Get device booted
Posted: Sun Apr 07, 2013 4:04 am
by HugeCode
Thanks... BTW does the DL=3 mean primary bus slave, or secondary bus master?
Re: Get device booted
Posted: Sun Apr 07, 2013 6:36 am
by Combuster
No, it most likely means a bug.
Re: Get device booted
Posted: Sun Apr 07, 2013 7:49 am
by Mikemk
Combuster wrote:No, it most likely means a bug.
Unless you are booting from the third floppy disk on the system.
Re: Get device booted
Posted: Sun Apr 07, 2013 8:47 am
by HugeCode
Oh uh oh. What about DL=0x80/0x81? Master/Slave or Primary/Secondary bus?
Re: Get device booted
Posted: Sun Apr 07, 2013 9:59 am
by Combuster
I've actually seen drive 0x80 to be:
- ATA primary master
- ATA primary slave
- ATA secondary master
- A bootable CD
- SCSI drive
- SATA drive (various channels)
- All other options I haven't seen with my own eyes.
I've also seen fixed drives changing numbers and/or disappearing from your system when booting from removable media, and some hard drives never being given a number at all.
You get the idea yet?
If you're in an emulator with just your OS, you can bet on it that a harddisk boot will give DL=0x80 for that harddisk, and floppy boots give 0x00. On real machines, guessing is the best you can do.