• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Linux FOG Client, Hostname Changer not working

    Scheduled Pinned Locked Moved Solved
    Linux Problems
    hostname change linux client
    3
    13
    1.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      aknisly
      last edited by

      I’m another one of the many who is getting stuck with the hostname changer. I’ve not found a solution among the myriad posts on the matter. The client installed without errors, and the log shows that it is working, although I wasn’t able to figure out the “Unable to parse sleep time” error.

      12/7/2021 4:41 PM Service Starting service
       12/7/2021 4:41 PM Bus Became bus client
      
       12/7/2021 4:41 PM Middleware::Response Success
       12/7/2021 4:41 PM Service Initializing modules
      
      ------------------------------------------------------------------------------
      ----------------------------------AutoLogOut----------------------------------
      ------------------------------------------------------------------------------
       12/7/2021 4:41 PM Client-Info Client Version: 0.11.16
       12/7/2021 4:41 PM Client-Info Client OS:      Linux
       12/7/2021 4:41 PM Client-Info Server Version: 
       12/7/2021 4:41 PM Middleware::Response Success
       12/7/2021 4:41 PM Bus::Client Connection established
      ------------------------------------------------------------------------------
      
      
      ------------------------------------------------------------------------------
      -----------------------------DefaultPrinterManager----------------------------
      ------------------------------------------------------------------------------
       12/7/2021 4:41 PM Client-Info Client Version: 0.11.16
       12/7/2021 4:41 PM Client-Info Client OS:      Linux
       12/7/2021 4:41 PM Client-Info Server Version: 
       12/7/2021 4:41 PM Middleware::Response Success
      ------------------------------------------------------------------------------
      
      
      ------------------------------------------------------------------------------
      --------------------------------DisplayManager--------------------------------
      ------------------------------------------------------------------------------
       12/7/2021 4:41 PM Client-Info Client Version: 0.11.16
       12/7/2021 4:41 PM Client-Info Client OS:      Linux
       12/7/2021 4:41 PM Client-Info Server Version: 
       12/7/2021 4:41 PM Middleware::Response Success
       12/7/2021 4:41 PM DisplayManager Module is not compatible with Linux
      ------------------------------------------------------------------------------
      
       12/7/2021 4:41 PM Service ERROR: Unable to parse sleep time
       12/7/2021 4:41 PM Service ERROR: Input string was not in a correct format.
       12/7/2021 4:41 PM Service Sleeping for 60 seconds
      
      

      I’ve unchecked and rechecked the 3 places I can find to enable this:

      • FOG Configuration>FOG Client - Hostname Changer
      • Client Settings>Service Configuration>Hostname Changer>Service Status
        *Hosts>Host Management Edit: <my host>Service Settings>Host module settings

      (Sidenote: I’m puzzled why the log shows entries for Auto Logout, Printer Manager, and Display Manager, even though I disabled those globally…)

      I also deleted and redeployed the image onto the host, with no change.

      We’re not able currently to use the FOG server as our DHCP server, although it’s not clear to me that this would resolve the issue.

      From the manual, it looks like the Windows Client GUI has an option to enable the Hostname Changer (Maybe this is out of date?), but the Linux CLI installation didn’t have any such option. (See installation log here.)

      I’ve read about using a post install script with the FOG API to retrieve the hostname from the server and change it on the host, but I think that’s beyond my limited scripting ability. If I could retrieve the hostname, I might be able to adapt a simple script. I thought this one would be the cat’s meow, but something failed, and I think that the one that wasn’t supposed to need a MySQL client may still actually need it. I realize that I could register all clients in the DHCP reservations, but that looks like a pretty big task for something that could be automated.

      Thanks much in advance!

      FOG server v. 1.5.7

      lsb_release -a
      LSB Version:	:core-4.1-amd64:core-4.1-noarch
      Distributor ID:	CentOS
      Description:	CentOS Linux release 7.6.1810 (Core) 
      Release:	7.6.1810
      Codename:	Core
      
      george1421G 1 Reply Last reply Reply Quote 0
      • george1421G
        george1421 Moderator @aknisly
        last edited by george1421

        @aknisly Well I can’t help you too much with the fog client but with a post install script you can do what you need in just a few lines as you saw. Frankly most of my tutorials for post install scripts focused on MS Windows because they typically need the most help. You can do what you need to do by copy and glue method to build your script.

        Lets start with this script to what you linked to above.

        if [ "$osId" == "50" && ! -z $hostname ]; then
             mount /dev/sda1 /mnt
             echo $hostname > /etc/hostname
             sync
             umount /mnt
        fi
        

        This has almost all of the meat in it you need. For completeness lets change it up to look like this:

        !/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/sda1 /ntfs
             echo $hostname > /etc/hostname
             sync
             umount /ntfs
        fi
        
        

        Save the above content into /images/postdownloadscripts as fog.sethostname You will probably have to be root or sudo to save in that location.

        Next make the script executable with
        chmod u+x /images/postdownloadscripts/fog.sethostname

        That should pretty much do it. Well almost. In the script you linked there is an assumption your root partition is always on /dev/sda1 So for your standard build you need to update that mount command to point to your linux root partition. You can find that by running df -h and post the results here.

        The last bit you need to do is hook your fog.sethostname into the main fog.postdownload script Edit the fog.postdownload script and insert this line exactly as I have it at the bottom of the script.

        . ${postdownpath}/fog.sethostname 
        

        For your reference here is a great example of a post install script to inject drivers into a windows image. 😉 You can look at that since I’m going to steal bits of my work to build your script. https://forums.fogproject.org/topic/11126/using-fog-postinstall-scripts-for-windows-driver-injection-2017-ed

        So you might ask yourself, so why is this so simple? Easy, the FOG developers are pretty smart.

        We startup and pull in the FOG library and do a little hose cleaning.

        !/bin/bash
        . /usr/share/fog/lib/funcs.sh
        [[ -z $postdownpath ]] && postdownpath="/images/postdownloadscripts/"
        

        Now we check to see if the OS deployment is linux and if the $hostname variable is set. Otherwise execution just bypasses this script. This is handy if you have both windows and linux in your environment, this script will only fire on a linux computer.

        if [ "$osId" == "50" && ! -z $hostname ]; then
        

        We make a mounting directory and then connect that mount directory to your root partition. This is the bit you will need to find out.

             [[ ! -d /ntfs ]] && mkdir -p /ntfs
             mount /dev/sda1 /ntfs
        

        The FOG main script will populate the $hostname variable for you. There are ways to get to the other FOG variables but $hostname is already set for you. We just basically type that variable into the /etc/hostname file. We sync the disks to flush any cached writes to the media. Then disconnect from your root partition.

             echo $hostname > /etc/hostname
             sync
             umount /ntfs
        fi
        

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

        A 1 Reply Last reply Reply Quote 0
        • S
          Sebastian Roth Moderator
          last edited by Sebastian Roth

          @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.

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          A 1 Reply Last reply Reply Quote 0
          • A
            aknisly @george1421
            last edited by

            @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.’
            Screenshot at 2021-12-08 10-57-47.png
            The ‘Mint Thin Client’ image is correctly registered as Linux:
            Screenshot at 2021-12-08 10-59-23.png

            Are there logs that I can access?
            Thanks again!

            george1421G 1 Reply Last reply Reply Quote 0
            • george1421G
              george1421 Moderator @aknisly
              last edited by

              @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 screen

              Updating 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.

              Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

              A 1 Reply Last reply Reply Quote 0
              • A
                aknisly @george1421
                last edited by

                @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…

                george1421G 1 Reply Last reply Reply Quote 0
                • george1421G
                  george1421 Moderator @aknisly
                  last edited by george1421

                  @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.

                  Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

                  A 1 Reply Last reply Reply Quote 0
                  • A
                    aknisly @george1421
                    last edited by aknisly

                    @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’?

                    george1421G 1 Reply Last reply Reply Quote 1
                    • george1421G
                      george1421 Moderator @aknisly
                      last edited by george1421

                      @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.

                      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

                      1 Reply Last reply Reply Quote 0
                      • S
                        Sebastian Roth Moderator
                        last edited by

                        @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.

                        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                        A 1 Reply Last reply Reply Quote 0
                        • A
                          aknisly @Sebastian Roth
                          last edited by

                          @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!

                          1 Reply Last reply Reply Quote 0
                          • S
                            Sebastian Roth Moderator
                            last edited by

                            @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.

                            Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                            Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                            1 Reply Last reply Reply Quote 1
                            • A
                              aknisly @Sebastian Roth
                              last edited by

                              This post is deleted!
                              1 Reply Last reply Reply Quote 0
                              • 1 / 1
                              • First post
                                Last post

                              258

                              Online

                              12.0k

                              Users

                              17.3k

                              Topics

                              155.2k

                              Posts
                              Copyright © 2012-2024 FOG Project