Custom Full Host Registration for 1.3.4
-
@Tom-Elliott So I got a chance to try the bootmenu link you posted and I get a chainlink error and could not boot: input/output error followed by the ipxe.org link. This is fixed by re-running the fog installer and then the ipxe booted normally. Not sure if I did that correctly but all I did was run that wget and it seemed like it downloaded the bootmenu.class.php.
-
@JGallo said in Custom Full Host Registration for 1.3.4:
I get a chainlink error and could not boot: input/output error followed by the ipxe.org link
What we need there is to capture this chainlink error. With that patched file installed call the following url from a browser and post the results here. http://<fog_server_ip>/fog/service/ipxe/boot.php?mac=00:00:00:00:00:00` That will provide us with the text that is used to create the iPXE boot menu.
-
@george1421
#!ipxe
set fog-ip 10.170.200.20
set fog-webroot fog
set boot-url http://${fog-ip}/${fog-webroot}
cpuid --ext 29 && set arch x86_64 || set arch i386
iseq ${platform} efi && set key 0x1b || set key 0x1b
iseq ${platform} efi && set keyName ESC || set keyName Escape
prompt --key ${key} --timeout 3000 Booting… (Press ${keyName} to access the menu) && goto menuAccess || sanboot --no-describe --drive 0x80
:menuAccess
login
params
param mac0 ${net0/mac}
param arch ${arch}
param platform ${platform}
param username ${username}
param password ${password}
param menuaccess 1
param debug 1
isset ${net1/mac} && param mac1 ${net1/mac} || goto bootme
isset ${net2/mac} && param mac2 ${net2/mac} || goto bootme
:bootme
chain -ar http://10.170.200.20/fog/service/ipxe/boot.php##params -
@JGallo And this what you get when you call the boot.php file with the mac address I gave you?
If so can you tail the apache error log and see if php is throwing an error. This IS an incomplete iPXE menu, which means that something is wrong with that patched file.
The head of a valid ipxe menu should look like this:
#!ipxe set fog-ip 192.168.1.53 set fog-webroot fog set boot-url http://${fog-ip}/${fog-webroot} cpuid --ext 29 && set arch x86_64 || set arch i386 goto get_console :console_set colour --rgb 0x00567a 1 || colour --rgb 0x00567a 2 || colour --rgb 0x00567a 4 || cpair --foreground 7 --background 2 2 || goto MENU :alt_console cpair --background 0 1 || cpair --background 1 2 || goto MENU :get_console console --picture http://192.168.1.53/fog/service/ipxe/bg.png --left 100 --right 80 && goto console_set || goto alt_console :MENU menu colour --rgb 0x00567a 0 || cpair --foreground 1 1 || cpair --foreground 0 3 || cpair --foreground 4 4 || item --gap Host is unregistered item --gap -- ------------------------------------- item fog.local Boot from hard disk item fog.memtest Run Memtest86+ item fog.keyreg Update Product Key item fog.deployimage Deploy Image item fog.multijoin Join Multicast Session item fog.quickdel Quick Host Deletion item fog.sysinfo Client System Information (Compatibility)
-
@george1421 That is what I get. I will try to tail the apache logs and see if anything I can get there. If I restore the the original boot.php file, should expect different results when calling the boot.php file with the mac address: 00:00:00:00:00:00?
-
@JGallo I would expect your results to be similar to my (unpatched) results. You could always try mac address 00:00:00:00:00:01 if for some reason you have mac address 00:00:00:00:00:00 registered. The key is to pick a mac address that should not exist in your FOG server.
-
@george1421 Here is what I got from the Apache2 error logs:
Mon Apr 03 07:35:02.274680 2017] [mpm_prefork:notice] [pid 29017] AH00163: Apache/2.4.25 (Ubuntu) OpenSSL/1.0.2k configured – resuming normal operations [Mon Apr 03 07:35:02.274758 2017] [core:notice] [pid 29017] AH00094: Command line: ‘/usr/sbin/apache2’ [Mon Apr 03 07:53:37.005326 2017] [php7:error] [pid 32151] [client 10.170.75.39:54182] PHP Fatal error: Uncaught Error: Call to undefined method BootMenu::attemptLogin() in /var/www/fog/lib/fog/bootmenu.class.php:1168\nStack trace:\n#0 /var/www/fog/lib/fog/bootmenu.class.php(398): BootMenu->verifyCreds()\n#1 /var/www/fog/service/ipxe/boot.php(35): BootMenu->__construct(Object(Host))\n#2 {main}\n thrown in /var/www/fog/lib/fog/bootmenu.class.php on line 1168 [Mon Apr 03 08:04:43.824595 2017] [php7:error] [pid 32177] [client 10.170.75.145:9807] PHP Fatal error: Uncaught Error: Call to undefined method BootMenu::attemptLogin() in /var/www/fog/lib/fog/bootmenu.class.php:1168\nStack trace:\n#0 /var/www/fog/lib/fog/bootmenu.class.php(398): BootMenu->verifyCreds()\n#1 /var/www/fog/service/ipxe/boot.php(35): BootMenu->__construct(Object(Host))\n#2 {main}\n thrown in /var/www/fog/lib/fog/bootmenu.class.php on line 1168 [Mon Apr 03 08:05:16.450267 2017] [php7:error] [pid 32148] [client 10.170.75.145:49460] PHP Fatal error: Uncaught Error: Call to undefined method BootMenu::attemptLogin() in /var/www/fog/lib/fog/bootmenu.class.php:1168\nStack trace:\n#0 /var/www/fog/lib/fog/bootmenu.class.php(398): BootMenu->verifyCreds()\n#1 /var/www/fog/service/ipxe/boot.php(35): BootMenu->__construct(Object(Host))\n#2 {main}\n thrown in /var/www/fog/lib/fog/bootmenu.class.php on line 1168 [Mon Apr 03 08:07:51.285042 2017] [php7:error] [pid 32147] [client 10.170.75.39:22602] PHP Fatal error: Uncaught Error: Call to undefined method BootMenu::attemptLogin() in /var/www/fog/lib/fog/bootmenu.class.php:1168\nStack trace:\n#0 /var/www/fog/lib/fog/bootmenu.class.php(398): BootMenu->verifyCreds()\n#1 /var/www/fog/service/ipxe/boot.php(35): BootMenu->__construct(Object(Host))\n#2 {main}\n thrown in /var/www/fog/lib/fog/bootmenu.class.php on line 1168 [Mon Apr 03 08:08:12.152556 2017] [mpm_prefork:notice] [pid 29017] AH00169: caught SIGTERM, shutting down [Mon Apr 03 08:08:24.966309 2017] [mpm_prefork:notice] [pid 1000] AH00163: Apache/2.4.25 (Ubuntu) OpenSSL/1.0.2k configured – resuming normal operations [Mon Apr 03 08:08:24.966502 2017] [core:notice] [pid 1000] AH00094: Command line: ‘/usr/sbin/apache2’ [Mon Apr 03 08:09:45.609312 2017] [php7:error] [pid 1021] [client 10.170.75.39:5052] PHP Fatal error: Uncaught Error: Call to undefined method BootMenu::attemptLogin() in /var/www/fog/lib/fog/bootmenu.class.php:1168\nStack trace:\n#0 /var/www/fog/lib/fog/bootmenu.class.php(398): BootMenu->verifyCreds()\n#1 /var/www/fog/service/ipxe/boot.php(35): BootMenu->__construct(Object(Host))\n#2 {main}\n thrown in /var/www/fog/lib/fog/bootmenu.class.php on line 1168 [Mon Apr 03 08:25:26.514047 2017] [php7:error] [pid 2705] [client 10.170.75.159:18805] PHP Fatal error: Uncaught Error: Call to undefined method BootMenu::attemptLogin() in /var/www/fog/lib/fog/bootmenu.class.php:1168\nStack trace:\n#0 /var/www/fog/lib/fog/bootmenu.class.php(398): BootMenu->verifyCreds()\n#1 /var/www/fog/service/ipxe/boot.php(35): BootMenu->__construct(Object(Host))\n#2 {main}\n thrown in /var/www/fog/lib/fog/bootmenu.class.php on line 1168 [Mon Apr 03 08:31:42.110324 2017] [mpm_prefork:notice] [pid 1000] AH00169: caught SIGTERM, shutting down [Mon Apr 03 08:31:54.914304 2017] [mpm_prefork:notice] [pid 1032] AH00163: Apache/2.4.25 (Ubuntu) OpenSSL/1.0.2k configured – resuming normal operations [Mon Apr 03 08:31:54.914503 2017] [core:notice] [pid 1032] AH00094: Command line: ‘/usr/sbin/apache2’
-
@JGallo It looks like line 1168 is causing the error in the patched boot menu file.
From DM: The OP is also using the ldap plugin too. Only worth mentioning since the error being thrown is referencing attemptLogin().
[editor note] I fixed the previous thread to include the error log in a code block for easier review[end note]
-
I’m sorry, you’ll need to install the working branch then. I’ve moved attemptLogin to fogbase now and it appears the changes I suggested, I overlooked that change sorry.
-
So I pushed up RC-2 for 1.4.0 in a semi-official manner rather than have you jump directly on working branch.
-
@Tom-Elliott Thank you. I went ahead and updated to 1.4.0-rc-2 and it seems like like post init scripts are running because I get a message that says Patching registration files and eventually states that it’s Done Patching Registration files. Unfortunately it’s not copying the file I have set up to copy. So we know that the post init scripts are running. Not sure if the copy script is working because when testing a host by trying to do a full register of a host I still get asked questions I removed from my custom fog.man.reg
-
@Tom-Elliott @george1421 This is what I have as far as post init scripts:
code for fog.postinit
#!/bin/bash ## This file serves as a starting point to call your custom pre-imaging/post init loading scripts. ## <SCRIPTNAME> should be changed to the script you're planning to use. ## Syntax of post init scripts are . ${postinitpath}fog.postselect
code for fog.postselect
#!/bin/bash . /usr/share/fog/lib/funcs.sh # place script commands here that should execute every time for every FOS action # I added some additional check here just in case you wanted to highly customize the postinit script's actions. This section is not mandatory. if [[ -n $mode && $mode != +(*debug*) && -z $type ]]; then case $mode in wipe) # fog wipe disk ;; checkdisk) # fog check disk ;; badblocks) # fog disk surface test ;; autoreg) # fog quick registration ;; manreg) # fog full registration . ${postinitpath}patch.fullreg ;; inventory) # fog full inventory ;; quickimage) # fog quick image ;; *) # all other generic operations ;; esac # place script commands here that should be run for any of the utility functions else case $type in down) # fog image deploy ;; up) # fog image capture ;; *) # the code should never get here, we'll just add so the script doesn't break ;; esac # place script commands here that should be run for either image capture or deploy fi
code for patch.fullreg
#!/bin/bash dots "Patching Registration files" debugPause cp -f ${postinitpath}fog.reg.man.fix /bin/fog.reg.man dots "Done Patching Registration files" debugPause
and finally the custom code I modified that removed questions we don’t need to be asked during full host registration
#!/bin/bash . /usr/share/fog/lib/funcs.sh . /bin/fog.donate clearScreen displayBanner disks="" disk="" hd="" getHardDisk sysman="" sysman64="" sysproduct="" sysproduct64="" sysversion="" sysversion64="" sysserial="" systype="" biosversion="" biosvendor="" biosdate="" mbman="" mbproductname="" mbversion="" mbserial="" mbasset="" cpuman="" cpuversion="" cpucurrent="" cpumax="" mem="" hdinfo="" caseman="" casever="" caseserial="" casesasset="" sysserial64="" systype64="" biosversion64="" biosvendor64="" biosdate64="" mbman64="" mbproductname64="" mbversion64="" mbserial64="" mbasset64="" cpuman64="" cpuversion64="" cpucurrent64="" cpumax64="" mem64="" hdinfo64="" caseman64="" casever64="" caseserial64="" casesasset64="" dots "Using disk device" echo $hd echo " * Starting host registration" mac=$(getMACAddresses | base64) exists=$(curl -ks --data "mac=$mac" http://${web}service/man.hostexists.php 2>/dev/null) checkAndSet() { local testvar="$1" local onlynum="$2" [[ -z $testvar ]] && return if [[ $onlynum =~ [Tt][Rr][Uu][Ee] && $testvar =~ ^[0-9]+$ ]]; then echo $testvar | base64 elif [[ $testvar =~ ^[0-9,]+$ ]]; then echo $testvar | base64 else return fi } setIDs() { local varVar="$1" local str="$2" local csvstyle="$3" local dummy="$4" local max="$5" local res="" local url="" local oIFS=$IFS local line="" while [[ -z ${!varVar} ]]; do [[ $csvstyle =~ [Tt][Rr][Uu][Ee] ]] && echo -n " Enter the $str IDs separated with , to associate with computer (? for listing): " || echo -n " Enter the $str ID to associate with computer (? for listing): " read dummy dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//') case $dummy in [?]) url="http://${web}service/${str}listing.php" clearScreen res=$(echo -e $(curl -ks $url 2>/dev/null)) i=0 IFS=$'\n' for line in $res; do let i+=1 echo $line if [[ $i -eq $max ]]; then [[ $csvstyle =~ [Tt][Rr][Uu][Ee] ]] && echo -n " Press [Enter] to proceed or enter the $str IDs separated with , to associate with computer: " || echo -n " Press [Enter] to proceed or enter the $str ID to associate with computer: " read dummy case $dummy in [?]|"") i=0 clearScreen continue ;; esac case $csvstyle in [Tt][Rr][Uu][Ee]) [[ $dummy =~ ^[0-9,]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy) || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max" break ;; *) [[ $dummy =~ ^[0-9]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy "true") || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max" break ;; esac i=0 dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//') clearScreen fi done ;; ""|0) printf -v "$varVar" 0 ;; *) dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//') [[ -z $dummy ]] && setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max" case $csvstyle in [Tt][Rr][Uu][Ee]) [[ $dummy =~ ^[0-9,]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy) || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max" ;; *) [[ $dummy =~ ^[0-9]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy "true") || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max" ;; esac ;; esac done IFS=$oIFS } [[ $exists != "#!ok" ]] && handleError "Unable to register host: $exists ($0)\n Args Passed: $*" host="" imageid="" blImage="" keyEnter="" res="" while [[ $res != "#!ok" ]]; do echo -n " * Enter hostname for this computer: " read host if [[ ${#host} -gt 15 ]]; then host=${host:0:15} echo " | Truncated to 15 characters: $host" usleep 2000000 fi host=$(echo $host | base64) res=$(curl -ks --data "host=$host" http://${web}service/hostnameloop.php 2>/dev/null) [[ $res != "#!ok" ]] && echo "$res" done imageid="" setIDs "imageid" "image" "" "" 20 if [[ $(curl -ks http://${web}service/locationcheck.php 2>/dev/null) == "##" ]]; then while [[ -z $askme ]]; do echo -n " Would you like to assign a location for this host? (y/N) " read askme case $askme in [Nn]|[Nn][Oo]|"") askme="N" ;; [Yy]|[Yy][Ee][Ss]) setIDs "locationid" "location" "" "" 20 location64=$locationid ;; *) askme="" echo " * Invalid input, please try again" ;; esac done fi echo " * You entered all required information, " askme="" while [[ -z $askme ]]; do echo -n " Would you like to deploy image to this computer now? (y/N) " read askme case $askme in [Nn]|[Nn][Oo]|"") askme="N" ;; [Yy]|[Yy][Ee][Ss]) tmp="" ret="" retry=3 while [[ $ret != "#!ok" && ! $retry -eq 0 ]]; do echo " * Enter FOG GUI Username and Password" echo -n " Username: " read username echo -n " Password: " read -s password user64=$(echo $username | tr -d '\012' | base64) pass64=$(echo $password | tr -d '\012' | base64) ret=$(curl -ks --data "mac=$mac&username=$user64&password=$pass64" http://${web}service/checkcredentials.php 2>/dev/null) case $ret in '#!ok') echo echo " * This host will reboot and deployment will start!" ret=$tmp realdoimage=$(echo -n 1 | base64) break ;; '#!il') echo echo " * Error: Invalid Login! ($retry remaining)" let retry-=1 ;; esac done askme="Y" ;; *) askme="" echo " * Invalid input, please try again" ;; esac done dots "Attempting to register host" res="" while [[ -z $res ]]; do res=$(curl -ks --data "mac=$mac&advanced=$(echo -n 1 | base64)&host=$host&imageid=$imageid&doimage=$realdoimage&location=$location64&username=$user64" http://${web}service/auto.register.php 2>/dev/null) echo "$res" usleep 2000000 done . /bin/fog.inventory usleep 2000000
-
@JGallo OK the forum really manged your code in the post.
Let go back to basics. Insert this code in your fog.postinit
echo "Installing Patch" debugPause cp -f ${postinitpath}fog.reg.man.fix /bin/fog.reg.man echo "Done Patching" debugPause
If that doesn’t work then we will need to install the debug kernel parameters again and figure out what is going wrong on the other end. If you see the Installing Patch in registration mode then we know the script is being called.
-
@george1421 Yes. It is successful in echoing those words. I went as far as actually echoing “Installing my patch” and it works. LOL. So we know the script is being called but not too sure on the file copy. If I place the debug flags back, can I pull the fog.man.reg file to inspect it and confirm the file copy?
-
@JGallo Right in the code I provided, if you are in debug mode it will pause just before copying the file and just after copying the file.
On the pause just after copying the file press ctrl-c to break out of the script. Then inspect the file date. If its not correct then manually key in the copy command to see what error is thrown. I might suspect I have the source path off for some reason.
You might also want to key in
echo "${postinitpath}"
on the command line (after the control-c) to see if the postinitpath is properly set. -
@george1421 So placed the debug flags back. Once the patching was done, I hit control-c and inspected /bin/fog.man.reg and looks like the original file because my changes aren’t there. I also echoed the postinitpath and it returned a blank line.
Could I theoretically set the postinit path prior to cp the custom fog script? Or instead of using the variable postinit to manually enter the postinitpath?
-
@JGallo well in this case the postinitpath should be set by the master fog script. If it is not set correctly then things will fall down.
You could manually set it, but if you are still in debug mode, could you post the output of this command
df -h
at this point for the postinitpath to work, the FOS engine needs a connection back to the fog server over nfs to reach the script. Since the postinit script…Wait that variable needs to be set, because the main fog program calls the postinit by issuing
. ${postinitpath}fog.postinit
Instead of having you keep thrashing this around let me look at it tonight, there has to be something missing.
-
@george1421 I will wait. While in debug mode, I typed
df -h
and got
filesystem Mounted on /dev/root /
-
@george1421 said in Custom Full Host Registration for 1.3.4:
echo “Installing Patch”
debugPausecp -f ${postinitpath}fog.reg.man.fix /bin/fog.reg.man
echo “Done Patching”
debugPauseI might recommend a script of:
currfile="/bin/fog.man.reg" newfile="${postinitpath}fog.reg.man.fix" . /usr/share/fog/lib/funcs.sh echo "Testing path for our fixed file at ${postinitpath}fog.man.reg.fix" debugPause # Test path and run copy if found and matched. if [[ -r $newfile ]]; then echo "Found file preparing to copy" debugPause cp -f $newfile $currfile >/dev/null 2>&1 [[ ! $? -eq 0 ]] && echo "Copy Failed" || echo "Copy Succeeded" debugPause else echo "Failed to find file sorry" debugPause fi
-
@JGallo Ok setting this up on my home dev box, I’ve come to the conclusion that this works as I outlined IF I would have frick’n spelled the manual registration file correctly.
the real name is /bin/fog.man.reg and not fog.reg.man
Even Tom missed it because he copied my script to start with.
Using tom’s script but with the proper file names it works. It was working with the file names I was using, except it didn’t overwrite the manual registration file.
[moderator note, I’m going to correct Tom’s post to reflect the proper file names in question]