Modifying the init image to truncate hostname to 15 characters


  • Moderator

    FOG Version: 0.32
    OS Version: Ubuntu 10.04 LTS Server i386

    I have the problem of naming hosts after users. Usually it’s LastnameFirstname, and sometimes this goes over the 15 character limit allowed by FOG. The database limits the host name to 16 characters, but the registration script only allows 15 characters (see function isSafeHostName() in /var/www/fog/commons/functions.include.php).

    Normally if you do a full registration via PXE and you put in a host name longer than 15 characters, the hostname gets switched to the MAC address of the host (without the “:”).

    The webUI lets you use 16 characters, which matches the database field length.

    Updating your init.gz via ([url]http://www.fogproject.org/wiki/index.php/Modifying_the_Init_Image[/url]), you can edit the FOG registration script as follows.

    Once you have the init file unzipped and mounted, edit the initmountdir/bin/fog.man.reg file. Look for:
    [CODE]
    echo
    echo -n " Enter the hostname of this computer: “;
    read host;
    [/CODE]
    insert
    [CODE]
    if [ ${#host} -gt 15 ]
    then
    host=${host:0:15};
    echo " Truncated to 15 characters: $host”;
    fi
    [/CODE]
    just before
    [CODE]
    host=echo $host | base64;
    [/CODE]

    save the file and exit. Do the steps in the wiki to exit the init environment and gzip it back.

    Now if you are doing a full registration and inventory, you no longer have to count the hostname to make sure it doesn’t go over 15 characters. It will truncate it and alert you to the new truncated name, and proceed with the next steps.

    Note: If you reinstall or upgrade FOG, your customizations to init.gz may be lost. Always backup init.gz before doing FOG updates other than kernel swaps.


  • Moderator

    woohoo!


  • Senior Developer

    This functionality is now a part o FOG 0.33b as well as checks to ensure hostname is unique.


Log in to reply
 

372
Online

38982
Users

10712
Topics

101680
Posts

Looks like your connection to FOG Project was lost, please wait while we try to reconnect.