Menu

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

Help
3 days ago
22 hours ago
  • Alan Taylor

    Alan Taylor - 3 days 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 - 3 days 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";
    ?>
    
     
    👍
    1
  • Alan Taylor

    Alan Taylor - 22 hours ago

    on reflection this line of questioning is probably better suited for the DRBL forum; posted here; https://sourceforge.net/p/drbl/discussion/Help/thread/d981bc792e/

    please let me know if I need to wrap this one up and how I should? thanks

     

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.