# Need to detect current boot device



## pravas (Jan 6, 2011)

Hello everyone

I have two storage disks (Compact Flash and Hard disk). I can boot both from CF and HD (both have same kernel and loader). I am trying to make some modification in the loader. The idea is to figure out which device is being booted inside loader and take some measurement.

The issue is that, in boot2 as well as in bootinfo structure received by loader (from boot2) always contains the unit number of the bootable disk as 0x80. For example, if I am booting from HD then Unit number of HD and CF is 0x80 and 0x81 respectively and if booting from CF, then unit number of CF and HD is 0x80 and 0x81 respectively. As loader is same in both the devices, it cannot figure out the device it is booting from.


```
atacontrol list
ATA channel 2:
    Master:  ad4 <External Disk 0/1.1594> Serial ATA II
    Slave:       no device present
ATA channel 3:
    Master:  ad6 <ELITE PRO CF CARD 4GB/Ver2.21K> Serial ATA v1.0
    Slave:       no device present
```

I have phoenix BIOS.

I have two options.
1. Read the boot sequence for the NVRAM, for which I have to get in touch with BIOS vendor.
2. Probe the ata controller in the loader and find out the BIOS unit number assigned to ATA Channel 2 Master and ATA channel 3 Master.

I would prefer to go for the second option and hence I need some help to have some information or pointers to do this.

I am a new bee and any help in this regard will be useful.

Thanks


----------



## Orum (Jan 8, 2011)

Is there any reason you can't just remove (or disable) one of the devices temporarily?  Or is this part of a larger project?


----------



## pravas (Jan 10, 2011)

No, I cannot remove one of the devices, because both of them are internal. I can't disable one of the device, because I need both of them during boot. 

The boot device ordering is constant. First boot dev is CF and the second boot dev is HD. I have made changes in loader in such  way that, the box will always boot from CF and the loader on CF will see if there is a valid bootable image on HD. If yes, then it will load the kernel and modules from the HD, changes the vfs root mount accordingly and will boot. But if loader doesn't find an image, then it will continue booting from CF.

If by mistake CF is corrupted and BIOS skips booting from CF, then loader being the same, the loader on HD can think (unless things are taken care of)that it is booting from HD. So, the key point is to figure out the device irrespetive of the device I am booting from and that is the issue. 

Thanks
Pravas


----------



## Fernando Softov (Aug 31, 2017)

I have a very similar question.

I have a Virtual machine, with a USB and CDROM.
/dev/da0 - virtual machine HD
/dev/da1 - USB
/dev/cd0 - CDROM

I am writing my own installer, inside the installer there was a boot mfsroot /dev/md0.

So I need to know from which device the /dev/md0 was mounted, or in other words booted.
/dev/da1 or /dev/cd0.

Because I need to mount this device in /dist and extract the files I need.


----------

