[ipxe-devel] can ipxe recognise if disk exist?

Levente LEVAI levail at aviatronic.hu
Tue Apr 10 19:56:30 UTC 2012


> Hi List,
>
> Im using ipxe here to boot several things. Now i have one boot-point (in
> the new menu-style  ), which is only interesting, if a harddisk
> exists on the machine, where ipxe is running. Is there a possibility to
> see an existing hardisk (boolean will do).
>
> Maybe something like this:
>
> isset ${localdrive}&&  item localboot Boot from local drive
> .
> .
> .
> :localboot
> isset ${localdrive}&&  sanboot --no-describe --drive ${localdrive}
>
>
> Regards,
>
> Oliver
>
If I understand the problem right you wish to check if a local (physical)
hdd exsists. If this is what you wish to have, here is the code I use for
something similar. There are some caveats thought, for one it works
only in pcbios and only for disks seen as bios disks. To get more some
drivers were necessary.

Sorry, this is not a decent patch (ugly, ugly me), but what you should
do is simple enough. In the file src/core/main.c:

-add  the include
#include <realmode.h> //to get bios hdd cnt form 0x00000475

-add these variables in main() to the variable declarations:
     uint16_t bios_hdd_cnt;
     char        sname[32];
     char        sval[32];

-still in main() search for the call to initialise() and startup(), and
  put this code after them:

     memset ( sname, 0, sizeof ( sname ) );
     strncpy ( sname, "bios_hdds", sizeof ( sname ) - 1 );
     memset ( sval, 0, sizeof ( sval ) );
     __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
                        "push %%ds\n\t"
                        "xorw %%ax,%%ax\n\t"
                        "movw %%ax,%%ds\n\t"
                        "xorw %%ax,%%ax\n\t"
                        "movb (0x00000475),%%al\n\t"
                        "pop  %%ds\n\t"
                        "cli\n\t" )
                    : "=a" ( bios_hdd_cnt ) );
     snprintf ( sval, sizeof ( sval ) - 1, "%d", (unsigned int)( 
bios_hdd_cnt ) );
     storef_named_setting ( sname, sval );

Rebuild. You can access the bios hdd count as ${bios_hdd_cnt}. If you need
a flag (the isset construct you mentioned) use
     if( bios_hdd_cnt > 0 ) {
         snprintf ( sval, sizeof ( sval ) - 1, "1" );
     }
instead of the
     snprintf ( sval, sizeof ( sval ) - 1, "%d", (unsigned int)( 
bios_hdd_cnt ) );
line.

I have a similar hack to check if the cpu is 64 or 32 bits. Let me know if
someone needs it.

Hope this helps.
/levente





More information about the ipxe-devel mailing list