Linux FOG Client, Hostname Changer not working
-
@aknisly Changing the hostname of Linux systems is not as straight forward as it is in the Windows world. The fog-client HostnameChanger Module is not very intelligent, just trying different things but obviously fails in your setup. Take a look at the code on github. It’s pretty easy to read even if you’re not a programmer. So if you figure out why it doesn’t work for you, just let us know…
FOG server v. 1.5.7
If you want the latest new fixes you’ll need to update to the very latest version of FOG - well at lease the latest version of the fog-client software! That said the HostnameChanger hasn’t been touched in a long time. But we can do it if you are keen to help. Usually people just take the quick solution (see George’s great post below!) and never get back to us about this. We won’t fix it if there is no real need!
(Sidenote: I’m puzzled why the log shows entries for Auto Logout, Printer Manager, and Display Manager, even though I disabled those globally…)
Good point! The fog-client is not perfect yet. Modules still get called and logging spits out way too much unformation. I would hope we can get this fixed at some point but it’s just too many open topics and few people working on it. Just opened an issue to track this on github. Though I can’t promise we’ll get to it. Feel free to help us work on this and get it fixed.
-
@george1421 Thanks very much for this quick and helpful response! A few sentences of explanation can bridge what feels like a wide chasm of knowledge.
Unfortunately, I’ve not got this working yet. Here is what I’ve done:
On the server…[admin@localhost postdownloadscripts]$ cat fog.postdownload !/bin/bash ## This file serves as a starting point to call your custom postimaging scripts. ## <SCRIPTNAME> should be changed to the script you're planning to use. ## Syntax of post download scripts are . ${postdownpath}/fog.sethostname [admin@localhost postdownloadscripts]$ cat fog.sethostname !/bin/bash . /usr/share/fog/lib/funcs.sh [[ -z $postdownpath ]] && postdownpath="/images/postdownloadscripts/" if [ "$osId" == "50" && ! -z $hostname ]; then [[ ! -d /ntfs ]] && mkdir -p /ntfs mount /dev/sda5 /ntfs echo $hostname > /etc/hostname sync umount /ntfs fi [admin@localhost postdownloadscripts]$ ls -la total 8 drwxrwxrwx. 2 fogproject root 53 Dec 8 10:22 . drwxrwxrwx. 10 fogproject root 177 Dec 7 16:52 .. -rwxrwxrwx. 1 fogproject root 238 Dec 8 09:54 fog.postdownload -rwxrwxrwx. 1 fogproject root 294 Dec 8 10:22 fog.sethostname
(I gave 777 to the fog.sethostname just in case, since fog.postdownload had those permissions.)
On the host…
pilgrim@pcsthinlinc:~$ df -h Filesystem Size Used Avail Use% Mounted on udev 1.9G 0 1.9G 0% /dev tmpfs 388M 1.5M 386M 1% /run /dev/sda5 15G 7.4G 6.0G 56% / tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 480M 4.0K 480M 1% /boot/efi tmpfs 388M 16K 388M 1% /run/user/1000
The image deployed to the host as expected, but as you can see, it didn’t get the ‘LAPTOP-10’ hostname. Does the fact that the server doesn’t list this host as a Linux OS have anything to do with it? I don’t understand why all of our hosts (both Windows and Linux) show the image OS as ‘unknown.’
The ‘Mint Thin Client’ image is correctly registered as Linux:
Are there logs that I can access?
Thanks again! -
@aknisly Fist of all I’m hoping the form just ate your leading pound on the bash files.
Just for clarity a bash script needs to always start with
#!/bin/bash
If not, she won’t run.
Everything else looks good. We might want to add in a few “debugging” echos.
!/bin/bash . /usr/share/fog/lib/funcs.sh [[ -z $postdownpath ]] && postdownpath="/images/postdownloadscripts/" Echo Updating target computer to host name [ $hostname ] debugPause if [ "$osId" == "50" && ! -z $hostname ]; then [[ ! -d /ntfs ]] && mkdir -p /ntfs mount /dev/sda5 /ntfs echo $hostname > /etc/hostname sync echo Host name updated on target computer debugPause umount /ntfs fi
That should then print when your scripts starts to run and if the
if
statement was satisfied it should say host updated.Now the last bit is a tip I use when debugging post install scripts. To setup the deploy task but check the debug option. Then pxe boot the target computer. In the debug mode you will be dropped to the FOS Linux command prompt. To start imaging just key in the word
fog
. This will single step you through the imaging process. Right after the last partclone screen is displayed is when the post install scripts will run. You should see on the screenUpdating target computer to host name [ $hostname ]
Then because we put a debugPause in right after that echo the script will stop waiting for an enter key press. Ensure the hostname value is being set. If that bit looks OK press enter. Hopefully the next time it stops will be at
Host name updated on target computer.
If you have an error or something else press Ctrl-C and exit the imaging program. You will now be able to check to ensure your partition is mapped correctly or what ever happened. You can simply restart deployment by keying in
fog
again to restart the imaging process in debug mode. -
@george1421 Wow! Whatever they’re paying you, it’s not enough…:-)
RE: the leading # on the first line: <pounds forehead with open palm> Duh. I knew that. I just mindlessly followed the script as you had posted it.
I love the debugging magic; that’s a game-changer. All is well up to line 8. I can’t figure out why, but I’m getting
line 8: [: missing ']'
Sorry for being slow…
-
@aknisly Just remove the square brackets around the $hostname variable. Its only decoration. I didn’t really debug the script (I should have), but that’s all part of learning (i.e. falling flat on your face and then trying to figure out what happened).
Know that when you are in debug mode and hit that error in the script you can hit crtl-c to blow out of deployment. Then fix the script on the fog server and rerun
fog
to start the deployment over again.Wow! Whatever they’re paying you, it’s not enough…:-)
All the cookies and soda I can consume is my pay.
-
@george1421 Done. It took digging deeper into BASH scripting, and thinking through what the script was attempting to do, but it finally worked. Notably, the 2-condition test in the ‘if’ statement was giving me grief until I separated it into two double brackets (two single brackets may have worked?). I know there are a dozen ways of doing this, but this worked for me. Also, the ‘$osId’ needed to be ‘$osid’, and the /etc/hostname needed to be in the mounted directory instead of in the FOS environment.
For others wanting to use this, here is the complete script as I adapted it to work, with the debugging elements removed.#!/bin/bash . /usr/share/fog/lib/funcs.sh [[ -z $postdownpath ]] && postdownpath="/images/postdownloadscripts/" if [[ "$osid" == "50" ]] && [[ ! -z $hostname ]] then [[ ! -d /imagefs ]] && mkdir -p /imagefs mount /dev/sda5 /imagefs echo $hostname > /imagefs/etc/hostname sync umount /imagefs fi
A few more notes for others trying to make something like this work:
- For anyone else having trouble with scripting, the debugging option is a life-saver. I ended up putting a debugPause (preceded by an “echo” or similar output statement) after every line to narrow my problem down.
- It took me longer than it should have to figure out the details of the ‘if’ statements in @george1421’s sample script. The -z checks for a null value (in this case for $hostname the “!” is not, so this is saying if the $hostname variable is not null, then… Here is a good guide on these.
*@george1421 has listed the FOG variables available in FOS (FogOS) here. I didn’t find this in the wiki. In that same thread, he notes a way to get a pile of other variables from the FOG server by running a script.
*For a short primer on the post-install script concept itself, this post and a few others in that thread were the best I found.
Again, @george1421, many, many thanks for your prompt, patient help. I’ve just made a donation to the FOG project in your honor.
If I could have an account for the wiki, I’d be happy to put some of this info together in a tutorial for changing hostname and post-install scripting.
Who marks this as ‘solved’?
-
@aknisly Very well done! I realize the path to get here was a bit rough. BUT you have now learned something for the next time you want to adjust something else using a post install script (its that giving a fish vs teaching how to fish, thing).
As I’ve told others, “If it worked correctly the first time, what would you have learned?” So we applaud you on working through this and then posting your success here.
-
@aknisly This just confirms why we don’t get to fix the HostnameChanger module in the fog-client. My post on what to look at in the fog-client was ignored. Nevermind.
-
@sebastian-roth (Belated reply…) Thanks for this helpful explanation. I certainly am not critical of the unfinished work here–what you have already is one incredible work of science/art.
I did take a look at the code, and have a rough idea of what is being attempted there. But it’s true that the post-install script is pretty low-hanging fruit once you get your head under the hood. If I hadn’t been able to get what I wanted with that, I’d be happy to help with the fog-client and the HostnameChanger module, but as it is, unfortunately, I’m pressed to move on to other priorities.
I would be happy to make some notes in the wiki (which is still the first place I check) if that is an option. Apparently self-registering an account is disabled?
I’d also like to mark this topic solved, but can’t figure out how. Can you do that?
Again, huge kudos for this project. And 5-stars for responsive devs on the forum! -
@aknisly said in Linux FOG Client, Hostname Changer not working:
If I hadn’t been able to get what I wanted with that, I’d be happy to help with the fog-client and the HostnameChanger module, but as it is, unfortunately, I’m pressed to move on to other priorities.
Thanks for being open and honest. Good you were not afronted by my last reply.
I would be happy to make some notes in the wiki (which is still the first place I check) if that is an option. Apparently self-registering an account is disabled?
We work on updating and moving all the contents from the wiki to https://docs.fogproject.org and you are very welcome to help us. Please send me a private message with your github account name and we’ll permit you to the fog-docs repo.
-
This post is deleted!