Post Install script Hostname changer
-
Hello,
I am now working on a project where I need FOG to deploy or capture many OS (Linux) images on any part of the disk I want. I need to run a post install script to change the hostname of the image I have just deployed on a partition. I don’t know how to give it the precise name of the partition I’m gonna deploy the image on. I have seen that you have to mention the partition you want the image to be deployed on, but I have four of them where I can deploy an image and I don’t know how to make that like “automatic”, the fact that I don’t have to change the name of the partition every time in the script.
(If my english is terrible its because I’m french) -
@mdxlp No worries my french is terrible, and my english is not much better
So we have an example of a post install script for windows, what it does is search through all of the partitions on the deployment disk looking for the windows folder or file. Once that key or flag file is found it knows its the “C Drive”. You should be able to use the same concept with your task. Look for a directory or specific file (like “/etc/hostname”) to know you found the correct partition. From there you can then cat/echo the FOG hostname variable into that file.
Here is the windows focused solution
https://forums.fogproject.org/topic/11126/using-fog-postinstall-scripts-for-windows-driver-injection-2017-edLook at the fog.custominstall script. That script locates the partition with the windows directory on it.
This tutorial has the fog variables avaialble for the post install script
https://forums.fogproject.org/topic/7740/the-magical-mystical-fog-post-download-script/18?_=1686319619362$hostname is the name assigned to the computer in the FOG web ui
-
@george1421 Thank you. I’m gonna have a look at it and see what I can do with
-
-
I come back to you here because I tested things that included in my script the variables of the fog database, unfortunately I could not call or use most of these variables in my script because it did not work. After further research more specifically on windows, I heard about the netdom command. Does a command similar to netdom exist for linux ?
-
@mdxlp You may need to add this code to your fog post install script to load in all of the variables that fog has to offer into your post install script.
if [[ ! -z $mac ]]; then curl -A "" -Lkso /tmp/hinfo.sh ${web}/service/hostinfo.php -d "mac=$mac" if [[ -f /tmp/hinfo.sh ]]; then . /tmp/hinfo.sh fi fi
This basically makes a call to the fog server to collect the host info for that specific mac address. then it loads the hinfo.sh script created by the php program.
FOG is linux based, and linux can not step into the windows realm, so there is no equivalent linux command for netdom that is windows only.
-
Thank you for your help. I tried to include this piece of code at the beginning of my script and run the deployment twice but it didn’t work. By the way the variables that I would like to use are that of the fog.imagePartitionType. To introduce it simply it would be : “If imagePartitionTypeID = 3 then mounts /dev/nvmeOn1p1”, “If imagePartitionTypeID = 4 then mounts /dev/nvmeOn1p2” to rename the following part that your deploying. Hope this clarification can bring the light on my problem.
-
@mdxlp Let me tell you how I debug post install scripts. At the top of the post install script I insert an echo with something notable so you can quickly identify it. And then right after insert a
debugPause;
command.Now schedule a deploy task to your target computer, but before you hit the schedule task button tick the debug checkbox. Now schedule the deployment task.
PXE boot the target computer and it should drop you to a linux command prompt after a few screens of text you need to clear with the enter key. This is debug mode.
To start the debugging process in single step mode key in
fog
and press enter.{sidebar} If you want to remote debug your post install script get the current ip address of the target computer with
ip a s
and then set root’s password on the target computer withpasswd
. Set it to something simple like hello. Now you can connect to the target computer using ssh or putty from a remote computer. Key infog
to start the single step imaging process {/sidebar}The deployment script will stop at each
debugPause
command. Keep pressing enter until you see your echo statement you put at the beginning of the post install script. At this time if you press ctrl-c you can exit the deployment script. This will give you a command shell with all of the proper environment variables you can inspect with theset
command. Running the curl command from my previous post should produce all of the fog variables.