Monthly Archives: December 2013

Preventing PXE Linux installation boot loop

If a system is set to boot from PXE first, if you have your pxelinux symlink pointed at your OS installer, after initial installation the system will reboot and go right back into the installer, over and over again, and you’re stuck in an install loop. To prevent that, host this PHP script on your provisioning system, and ensure the pxelinux.cfg directory is recursively owned by apache/nginx.

 

<?php
// Reset a symlink in /tftpboot/pxelinux.cfg to point to harddisk instead of normal OS install. So we don't get caught in a boot reinstall loop.
// Written by Ryan Gehrig, 12/9/2013
error_reporting(E_ERROR);
$ip = $_GET['ip'];
if(empty($ip)) die('No IP Address provided (?ip=x.x.x.x)! Exiting.');
if(!preg_match('/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/', $ip)) die('Invalid IP Address specified! Exiting.');
$pxe_dir = '/tftpboot/pxelinux.cfg';

$hex_ip = trim(exec('gethostip -x '.$ip));
chdir($pxe_dir);

// Only run this if there's already a symlink
if(!file_exists($hex_ip)) die('No symlink for this IP ('.$hex_ip.'), exiting.');
# Create new link to localdisk
echo exec("rm -f $hex_ip");
echo exec("ln -s localdisk $hex_ip");
?>

Next, make sure apache or nginx owns the pxelinux files so the webserver can manage them.

chown apache: /tftboot/pxelinux.cfg -R

Lastly, in your kickstart file or AutoYast file, wget the install host/php script.

wget -q http://192.168.1.5/pxe_reset_harddisk.php?ip=x.x.x.x