Menu

ipxe boot to php static address then kernel/initrd boot without dhcp discover

Help
1 day ago
6 hours ago
  • Alan Taylor

    Alan Taylor - 1 day ago

    Hi there,
    Thanks for reading.
    on the back of the drbl and clonezilla integration I would like to accomplish a linux boot using drbl and clonezilla which does not run a 'dhcpdiscover' and instead uses an assigned address from a 'boot.php' embeded script.
    essentially my client should boot into ipxe, run a php script and then boot 'clonezilla' or 'distro-blah'
    (I did have the clonezilla menu and such working but fiddled and lost the config)
    essentially the php script assigned 'ip' should be used to integrate with drbl and mount a 'w/r' FS etc.
    always happy to provide more information and/or answer questions?
    Thanks,
    Alan
    NB =
    process outline:
    * PXE boot, ask for ip
    * kea DHCP (server1) gives ip (x) assignment and 'next server' option (server2)
    * 'next server' (server2) is contacted and ipxe and script is received
    * ipxe script is run; assigns ip (y) from pool via 'boot.php' on server2, declares kernel, initrd and boots
    * boot runs 'dhcpdiscover' received (x), negating 'boot.php' assigned ip
    * mount of 'node' FS fails for drbl/clonezilla resources on server2 as (x) is blocked
    * client drops into 'busybox'

    ipxe file;

    **#!ipxe

    obtain ip from proxy dhcp

    :start

    ifconf -c dhcp && isset ${filename} || goto start

    :boot

    boot script from php server

    chain http://192.168.3.199/boot.php?mac=${net0/mac}

    :failure
    echo Failure!
    sleep 5

    For Troubleshooting after Failure...

    shell

    php file;
    ~~~

     
  • Alan Taylor

    Alan Taylor - 1 day ago

    oh, appears that the 'php' file got truncated;

    <?php
    $mac = $_GET['mac'];
    $pool = range(ip2long('x.211'), ip2long('x.220'));

    // File for storing leases
    $lease_file = '/var/www/leases.json';
    $leases = file_exists($lease_file) ? json_decode(file_get_contents($lease_file), true) : [];

    // Assign new if not leased
    if (!isset($leases[$mac])) {
    $used_ips = array_values($leases);
    foreach ($pool as $ip_long) {
    $ip = long2ip($ip_long);
    if (!in_array($ip, $used_ips)) {
    $leases[$mac] = $ip;
    break;
    }
    }
    file_put_contents($lease_file, json_encode($leases));
    }

    $ip = $leases[$mac] ?? 'x.220'; // fallback
    header('Content-Type: text/plain');
    echo "#!ipxe\n";
    echo "set net0/ip $ip\n";
    echo "set net0/netmask 255.255.255.0\n";
    echo "set net0/gateway x.1\n";
    echo "set net0/dns x.188\n";
    echo "set net0.dhcp-server x.199\n";
    //echo "ifstat\n";
    echo "kernel tftp://x.199/nbi_img/vmlinuz-pxe ip=$ip initrd=initrd-pxe.img\n";
    echo "initrd tftp://x.199/nbi_img/initrd-pxe.img\n";
    echo "boot\n";
    //echo "boot tftp://x.199/nbi_img/vmlinuz-pxe initrd=initrd-pxe.img";
    ?>

     

    Last edit: Alan Taylor 1 day ago
  • Steven Shiau

    Steven Shiau - 6 hours ago

    I have never done this before. What I have done before is to use DHCP server to assign the fixed IP address to the specific MAC address.
    In your scenario, what need to be done is to pass the IP address in proper syntax from iPXE to the Linux system. Since they are in different stages, and the network configuration can not be passed automatically from early stage (ipxe) to the 2nd stage (GNU/Linux).
    So now you can try to pass the network configuration to the Linux kernel boot parameters, follow "ip" parameter in live-boot:
    https://manpages.debian.org/testing/live-boot-doc/live-boot.7.en.html#ip
    It should work I believe.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.