Hardware Agnostic Mobile FOG
-
Hey guys. First off, absolutely the BEST imaging/cloning solution EVER!!! I use it for physical machines and VMs.
So here’s my scenario:
We have developed images for our training department that they have tweaked and tested and are super happy with. Now they want to take them on the road and do training all over the world. We run multiple events in multiple locations and rent laptops at every location so I can’t just build one FOG server and service the entire environment. Also, I have no control over the laptops other than they have to be blank-ed after use (script from bootable USB does the trick).I found the Mobile FOG scripts and that seems to be the solution as I can load it onto a bootable USB drive (given enough storage capacity) and have multiple copies of it running around with minimal effort. Boot from USB on one of the rented laptops and have that be the server for the rest. When they are all done, use one of the other s to image the one that was used as the server.
Where i’m hung up at is that because the hardware changes from model to model, the script doesn’t work because it’s stuck on trying to monitor a certain interface that may not exist on different hardware. For example, on one laptop the NIC might enumerate as en160 while on another it may show up as enp0s25 and on yet another as enp1s0f1. The script is checking by interface so if its different the crontab job doesn’t do anything because it can’t find the interface.
Is there a way to make the script agnostic so it finds it and works?
FOG version 1.5.7 on Centos 7 via USB drive.
Thanks!!!
EDIT: so I’m not the best script writer but I can read most fairly well. It looks like the MakeFogMobile.sh script looks for the IP. I think a function could be written that checks for the interface too and compares it to the fogsettings file just it does for the IP. Then it would update the fogsettings and then the DB. I just have no idea how to write it. Isee it as something like:
while [[ -z $interf ]]; do ip=$(for interf in `ip ntable | grep dev | sort | uniq | sed -e 's/^.*dev //;/^lo/d'`) [[ -n $ip ]] && break $echo "could't enumerate the interface" >> $log sleep 5 done
Does that make sense???
-
@lenels2eng Ok here is what I’ve come up with.
Added the interface check just above the wait for IP address.
$inface=$(ip route get 1 | awk '{print $5;exit}') if [[ $inface -neq $interface ]]; then $echo "The interface has changed, assuming new hosts" >> $log $interface = $inface fi #---- Wait for an IP address ----# while [[ -z $IP ]]; do ip=$($ip -4 addr show $interface | awk -F'[ /]+' '/global/ {print $3}') [[ -n $ip ]] && break $echo "The IP Address for $interface was not found, waiting 5 seconds to test again" >> $log sleep 5 done
And then down below add the writing back the IP address to the .fogsettings file.
#---- Update .fogsettings IP ----# $echo "Updating the ipaddress field inside of $fogsettings" >> $log $sed -i "s|ipaddress='.*'|ipaddress='$ip'|g" $fogsettings #---- Update .fogsettings INTERFACE ----# $echo "Updating the interface field inside of $fogsettings" >> $log $sed -i "s|interface='.*'|interface='$interface'|g" $fogsettings
Understand I have not tested any of this only glued some code together.
-
@lenels2eng said in Hardware Agnostic Mobile FOG:
ip ntable | grep dev | sort | uniq | sed -e ‘s/^.*dev //;/^lo/d’
You will need to test this in your environment, but this “should” return the active network adapter
ip route get 1 | awk '{print $5;exit}'
Use the back ticks around that and assign it a variable if you want the interface name. Or this if you want the IP addressip route get 1 | awk '{print $NF;exit}'
The other option is to take the fog server with you. Depending on the number of images you need to push out, the FOG server could be loaded on a Raspberry Pi3, or if you need a bit more horsepower an intel NUC. So you could have a mobile fog server (already setup with the images) on a 4"x4"x2" cube as an alternative. The Pi3 would be a bit smaller and could even be solar or battery powered.
-
@george1421 Thank you, I’ll try it out today.
As for the NUC or Pi, both good options but looking to be able to hand the not so technical people in the field a USB drive they can boot off of so no other equipment needed.
If I can’t get it to go off the USB drive, then I’ll try the NUC route. I’ll let you know how it goes later today…
Thanks!!!
-
So I figured out how to add a if…then statement to the MakeFogMobile.sh script that basically compares what @george1421 said and the interface value in the fog settings file. If they are the same keep going, if not set the interface variable to the correct value. what I don’t know is what settings to update in the settings file nor how to do that and what fields in the database to change to reflect the correct interface…
can you point me in the right direction please?
-
sorry for the progress posts but it’s helping me work through this and it might help someone else noodle through something similar…
so I think I can write into the .fogsettings file by using “sed”…
sed -i “s|interface=‘.*’|interface=‘$interface’|g” $fogsettingsand possibly the only places in the DB are???:
in the globalSettings table: FOG_NFS_ETH_MONITOR and FOG_UDPCAST_INTERFACE setting the settingValue field to the new interfacein nfsGroupMembers table: ngmInterface field to the new interface.
ca;t seem to find it anywhere else so hopefully these are the only places…
-
@lenels2eng Ok here is what I’ve come up with.
Added the interface check just above the wait for IP address.
$inface=$(ip route get 1 | awk '{print $5;exit}') if [[ $inface -neq $interface ]]; then $echo "The interface has changed, assuming new hosts" >> $log $interface = $inface fi #---- Wait for an IP address ----# while [[ -z $IP ]]; do ip=$($ip -4 addr show $interface | awk -F'[ /]+' '/global/ {print $3}') [[ -n $ip ]] && break $echo "The IP Address for $interface was not found, waiting 5 seconds to test again" >> $log sleep 5 done
And then down below add the writing back the IP address to the .fogsettings file.
#---- Update .fogsettings IP ----# $echo "Updating the ipaddress field inside of $fogsettings" >> $log $sed -i "s|ipaddress='.*'|ipaddress='$ip'|g" $fogsettings #---- Update .fogsettings INTERFACE ----# $echo "Updating the interface field inside of $fogsettings" >> $log $sed -i "s|interface='.*'|interface='$interface'|g" $fogsettings
Understand I have not tested any of this only glued some code together.
-
@george1421 IT WORKS!!! (at least on the first system I tried )
so your code is MUCH more elegant than mine but it works.
Here is what I did to the script:
- I implemented a check on the interface using the code you started me on (like your code you just shared).
- I created an SQL update statement that updates two tables in the fog database:
# If the interface from fogsettings doesn't match what the system returned # # Make the change so system can still function # #---- Update the interface Setting ----# $echo "The interface does not match the interface setting in $fogsettings, updating the interface Settings server-wide." >> $log statement3="UPDATE \`globalSettings\` SET \`settingValue\`='$interface' WHERE \`settingKey\` IN ('FOG_NFS_ETH_MONITOR','FOG_UDPCAST_INTERFACE');" statement4="UPDATE \`nfsGroupMembers\` SET \`ngmInterface\`='$interface' WHERE \`ngmMemberName\`='$storageNode' OR \`ngmHostname\`='$ipaddress';" sqlStatements2="$statement3$statement4"
- adjusted the SQL execution to add in the new SQL statements:
# Builds proper SQL Statement and runs. # If no user defined, assume root [[ -z $snmysqluser ]] && $snmysqluser='root' # If no host defined, assume localhost/127.0.0.1 [[ -z $snmysqlhost ]] && $snmysqlhost='127.0.0.1' # No password set, run statement without pass authentication if [[ -z $snmysqlpass ]]; then $echo "A password was not set in $fogsettings for mysql use" >> $log $mysql -u"$snmysqluser" -e "$sqlStatements" "$database" 2>> $log $mysql -u"$snmysqluser" -e "$sqlStatements2" "$database" 2>> $log # Else run with password authentication else $echo "A password was set in $fogsettings for mysql use" >> $log $mysql -u"$snmysqluser" -p"${snmysqlpass}" -e "$sqlStatements" "$database" 2>> $log $mysql -u"$snmysqluser" -p"${snmysqlpass}" -e "$sqlStatements2" "$database" 2>> $log fi
4)updated the .ogsettings file to edit the interface entry:
#---- Update .fogsettings IP ----# $echo "Updating the ipaddress field inside of $fogsettings" >> $log $sed -i "s|ipaddress='.*'|ipaddress='$ip'|g" $fogsettings $sed -i "s|interface='.*'|interface='$interface'|g" $fogsettings
Rebooted and opened the beb interface. All looks good!!!
Now, I just need to make/capture an image to prove all is working.
Thanks!!!
-
I have been paying with this for a bit now and was working through a scenario where the OS doesn’t get an IP so trying to statically assign one, at least temporarily. I wasn’t able to get it to work but I think it just needs a little more time to work on this scenario. Otherwise, this works quite well. I did some minor tweaks so that my end user only had to boot to the USB drive and after the cron job runs keep an eye on the screen for the IP of the FOG server which I echo’ed out at the end of the script using: printf “The IP of the FOG server is: $IP \N” > /dev/console
I sent it off to a co-worker in another location and asked them to just plug in the USB drive, boot to it, wait for the message then try another machine to see if he got the FOG menu. He did and was able to register the machine with FOG and pull an image down so I’m marking this:
SOLVED!!!
I may try to go back when I have some time to finish hashing through the statically assign an IP if you don’t get one scenario…