Dynamically Patching FOS using a PostInit script

  • Moderator

    Postinit scripts are scripts called by FOS just after the FOS Linux system inits and before the main FOS imaging program starts. The postinit scripts give us the opportunity to make adjustments to FOS before imaging occurs. These adjustments can be to initialize raid controllers, bring up specialized hardware, or in the case of this post replace or patch parts of FOS imaging scripts before imaging begins.

    One example of patching or replacing FOS components might be if you wanted a customized registration process. The FOG registration process is managed by a FOG script called fog.man.reg that’s located in the /bin in the inits. One way to update this fog.man.reg files is by unpacking the inits, updating the script and then repacking the inits and then moving the inits to the proper location on the FOG server. Instructions on unpacking and packing the inits can be found in the FOG Wiki page here

    The method I’m going to cover here is to place the updated fog.man.reg file on the FOG server in the /images/dev/postinitscripts script directory where FOS Linux will see it and execute the postinitscripts before it starts imaging.

    1. Create a file /images/dev/postinitscripts/fog.patch.man.reg
    2. Paste the contents below into fog.patch.man.reg
    # Current File in FOS Linux to be replaced
    #Patch file to send to FOS Linux virtual hard drive
    # ---------------------------------------------
    # DO NOT edit any text below this line
    # ---------------------------------------------
    . /usr/share/fog/lib/funcs.sh
    # Test path and run copy if found and matched.
    if [[ -r $newfile ]]; then
        cp -f $newfile $currfile >/dev/null 2>&1
        [[ ! $? -eq 0 ]] && echo -n "patch copy failed " || echo -n "Patch copy succeeded "
        echo -n "Patch not found"
    1. Make the script executable chmod 755 /images/dev/postinitscripts/fog.patch.man.reg
    2. Edit /images/dev/postinitscripts/fog.postinit and add the following line to the bottom of the fog.postinit script
    . ${postinitpath}fog.patch.man.reg

    note: that leading period is not a mistake it needs to be the first character on that line. Its (dot)(space)${postinitpath} to ensure your custom patch script is called correctly.

    1. Download the latest version of fog.man.reg
    wget -O /images/dev/postinitscripts/fog.reg.man.fix https://github.com/FOGProject/fos/raw/master/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.man.reg
    chmod 755 /images/dev/postinitscripts/fog.reg.man.fix
    1. Modify /images/dev/postinitscripts/fog.reg.man.fix file as needed…

    Original script credit Tom Elliot
    ref: https://forums.fogproject.org/topic/9754/custom-full-host-registration-for-1-3-4/46