Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Disable options in menu based on CPU
2016-03-16, 18:30
Post: #1
Disable options in menu based on CPU
Hello,

I'm trying to write a dynamic boot menu using php.
However, since i'll have to support different CPU types and architectures, i'd like to remove certain menu options (or do not display) based on the CPU type.

I know that I can use CPUID --ext29 to check if the machine supports x64; and I already supply the machines with different ipxe versions (undionly.kpxe, ipxe_x86.efi and ipxe_x64.efi)

However, somehow I need to provide the architecture while calling the PHP script; or I need an if statement in ipxe to not display the item.

I've tried putting the following options in my DHCP:

Code:
if exists user-class and option user-class = "iPXE" {
    ## filename "http://10.168.51.5/bmenu.php?host=${serial}";
       if option arch = 00:06 {
                 filename "http://10.168.51.5/bmenu.php?host=${serial}&arch=Uefix86";
         } elsif option arch = 00:07 {
                  filename "http://10.168.51.5/bmenu.php?host=${serial}&arch=Uefix64";
         } elsif option arch = 00:00 {
                 filename "http://10.168.51.5/bmenu.php?host=${serial}&arch=Legx86";
        }  else {
                 filename "http://10.168.51.5/bmenu.php?host=${serial}&arch=unknown";
        }

} else {
        if option arch = 00:06 {
                filename "ipxe_x86.efi";
         } elsif option arch = 00:07 {
                 filename "ipxe_x64.efi";
         } elsif option arch = 00:00 {
                 filename "undionly.kpxe";
        }
  }
}

however, the x64 machines do receive the ipxe_x64.efi file (so the first time it requests the arch it is indeed 00:07; however, when booted to my boot menu, it display 'arch=unknown', so the 'arch=Uefix64' is not relevant

A machine booted to undionly.kpxe does display 'Legx86'.

Also, if there is a better way to pass the arch variable into the php url, please let me know. I'm using an if statement because that works in the first load-out of ipxe Smile
Find all posts by this user
Quote this message in a reply
2016-03-16, 18:45
Post: #2
RE: Disable options in menu based on CPU
Here is an example of my ipxe bootstraping script,
as you can see here arch (among other things) is sent to PHP so that the correct menu items can be added to the script (also platform is used for this)

Code:
#!ipxe
set boot-url http://server/pxe
set esc:hex 1b && set esc ${esc:string}[            # ANSI escape character - "^["
set cls ${esc}2J  # ANSI clear screen sequence - "^[[2J"

cpuid --ext 29 && set arch amd64 || set arch x86
set nloc ${netX/busloc}
set menu-url ${boot-url}/pxe.php?mac=${netX/mac:hexraw}&bus=${netX/busid:hexhyp}&loc=${nloc}&id=${pci/${nloc}.0.2}${pci/${nloc}.2.2}-${pci/${nloc}.0x2c.2}${pci/${nloc}.0x2e.2}&chip=${netX/chip:uristring}&ip=${netX/ip}&next-server=${next-server}&arch=${arch}&platform=${platform:uristring}

isset ${vram} && params && set dovram:uint8 1 || set novram:uint8 1
isset ${version} || chain ${boot-url}/ipxe.pxe ||

iseq ${filename} ${boot-url}/pxe.php && || goto notundi
iseq ${version} 1.0.0+ && chain -ar ${boot-url}/ipxe.pxe ||
iseq ${netX/chip} undionly && || goto notundi

echo ${esc}32;1mWe have UNDI: should try upgrade${esc}22;37m
iseq ${netX/busid:hex} 01:14:e4:16:92 && chain -ar ${boot-url}/ipxe.pxe ||
iseq ${netX/busid:hex} 01:14:e4:16:b5 && chain -ar ${boot-url}/ipxe.pxe ||
#iseq ${netX/busid:hex} 01:10:ec:81:68 && chain -ar ${boot-url}/ipxe.pxe ||
#iseq ${netX/busid:hex} 00:14:e4:16:92 && chain -ar ${boot-url}/ipxe.pxe ||
:notundi

iseq ${arch} amd64 && set warch x64 || set warch x86

chain -ar ${menu-url}&boot&hostname=${hostname:uristring} | shell


This do require an extra roundtrip, an alternative would be to add this as an embeded script into ipxe where you use dhcp at the top and then "chain -ar ${filename}&arch=${arch}" at the end, that way you still keep the option to modify filename on the dhcp server but get the arch in the actuall request.

Use GitHub Discussions
Visit this user's website Find all posts by this user
Quote this message in a reply
2016-03-16, 19:07
Post: #3
RE: Disable options in menu based on CPU
(2016-03-16 18:30)Fimlore Wrote:  However, somehow I need to provide the architecture while calling the PHP script; or I need an if statement in ipxe to not display the item.

You can use the ${buildarch} and ${platform} variables in iPXE. For example, with the standard 32-bit BIOS version of iPXE you would get ${buildarch}="i386" and ${platform}="pcbios".

You can pass these to the server (e.g. "http://10.168.51.5/bmenu.php?arch=${buildarch}-${platform}"), or you can use them in client-side tests. For example: to conditionally include a menu item to run the UEFI shell, which will appear only if running the UEFI version of iPXE:

Code:
iseq ${platform} efi && item --key e uefishell UEFI shell ||

Note that ${buildarch} is the architecture for which iPXE was built, not the architecture of the CPU on which iPXE is currently running. In a standard 32-bit BIOS build of iPXE, ${buildarch} will be "i386" even if the CPU itself can run both 32-bit and 64-bit code. You need to use the cpuid command if you want to do a runtime check to see if the CPU is 64-bit-capable.

Michael
Visit this user's website Find all posts by this user
Quote this message in a reply
2016-03-16, 19:33
Post: #4
RE: Disable options in menu based on CPU
Thanks for your quick and clear replies. This was exactly what I was looking for and I was certain not to find out myself Smile

The solution provided by Michael, the platform option is actually what I need, because dhcp decides the best ipxe to load for the platform, so if the efi file loads, the legacy options are invalid so should not be displayed and vice versa.

The ipxe script you provided nikize is also very interesting, it provides great insight into advanced ipxe scripting.

I know I am asking a lot of questions. But I'm adopting ipxe as our booting method and i'd love to be able to support everything in one system, instead of having 3 solutions that do all the same but limited.
It however involves a lot of know-how in both bash and Linux.. And I'm a Windows scripting guy, so it's a challenge but fun to do.

Thanks for both of your replies.
Find all posts by this user
Quote this message in a reply
2016-03-16, 19:45
Post: #5
RE: Disable options in menu based on CPU
(2016-03-16 19:33)Fimlore Wrote:  Thanks for your quick and clear replies. This was exactly what I was looking for and I was certain not to find out myself Smile

You're very welcome!

If you'd like some more realtime assistance, then both of us are regularly available in the #ipxe IRC channel on Freenode, along with a host of other people who will be happy to point you in the right direction!

Michael
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)