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][/url]), you can edit the FOG registration script as follows.

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

    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


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