diGriz's Chunk of Web

bash$ :(){ :|:&};:


N.B. I have been clobbering FOG for a while and come to the conclusion it really is wandering now a path of self destruction. Adding new functionality is horrible, forwards and backwards compatibility is going to be a nightmare and the whole system, relies on manually configuring huge chunks of it that could be cleanly automatically detected. Even simple things like partition tables have been completely fscked up and handled badly. A shame, FOG has so much to offer. I need to continue my work on LanWarden but maybe I will return to opensource imaging and start a project anew; meanwhile the instructions below are enough to get FOG running sanely and vaguely safely on a Debian box

Installing FreeGhost on Debian

This just contains some rough Work-In-Progress notes for installing FreeGhost (aka FOG) under Debian. I'll tidy this up once everything is stable, hell maybe I'll even roll a Debian package :)

These instructions also fix a number of flaws in FOG. Patches to apply can be found in my website at http://www.digriz.org.uk/files/fog/patches/.

Identified Problems in FreeGhost

Accurate for version 0.15...

Installing FOG Under Debian

Packages to Install

Aptitude will handle the dependencies so do not worry about the 'extras' like mysql-client and such.

Installing The FOG System

DIY initrd

All this static IP's being hardcoded all over the place give me the shakes so by using the IPAPPEND functionality (although not recommended, in our case I think it is justified as the machine is being nuked) we can auto-detect the location of the FOG webserver without the need for DNS.

Tweak the 'usr/local/fog/lib/funcs.sh' in the standard init.gz file so that the 'setupDNS()' function is just:

 # engage lazilator, saves us tweaking code everywhere for now
 # TODO: stop being lazy and do this properly
 function setupDNS()
 {
        bootip=`grep bootserver /proc/net/pnp`
        bootip=${bootip:11}
 
        web=$bootip/fog/
        ftp=$bootip
 
        storageip=$bootip
        storage=$storageip:/images
        if [ "$type" = "up" ]; then
                storage=${storage}/dev
        fi
 } 

Then in the initrd mounted directory type:

 ln -s /sbin/init init
 find . | cpio --quiet -H newc -o | gzip -9 -n > ../initrd.img 

This will give you a more automagical initrd.img file. Of course you could just use my initrd.img and bzImage (I re-rolled the kernel as there was guff in there that was not needed, my kitchen sink .config is also available).

Installing the FOG Base

Run the following commands:

 $ cd /usr/src
 $ wget http://fog.website/fog-latest.tar.gz
 $ tar -zxf fog-latest.tar.gz
 
 $ mkdir fog-patches
 $ cd fog-patches
 $ wget http://www.digriz.org.uk/files/fog/<various-patches>
 
 # mkdir -p /var/lib/fog/tftpboot /var/lib/fog/pxelinux.cfg
 # cp /usr/src/fog-latest/packages/tftp/boot.txt /var/lib/fog/tftpboot
 # cp -r /usr/src/fog-latest/packages/tftp/fog/images /var/lib/fog/tftpboot
 # cp -r /usr/src/fog-latest/packages/tftp/fog/kernel /var/lib/fog/tftpboot
 # ln -s /usr/lib/syslinux/pxelinux.0 /var/lib/tftpboot/
 # ln -s /var/lib/fog/tftpboot     /var/lib/tftpboot/fog
 # ln -s /var/lib/fog/pxelinux.cfg /var/lib/tftpboot/
 
 # mkdir -p /var/lib/fog/images/dev
 # chown -R www-root /var/lib/fog/images
 # chmod 777 /var/lib/fog/images/dev
 # touch /var/lib/fog/images/.mntcheck /var/lib/fog/images/dev/.mntcheck
 # ln -s /var/lib/fog/images /images
 
 # mkdir -p /usr/share/fog/
 # cp -r /usr/src/fog-latest/packages/web /usr/share/fog/
 # cp -r /usr/src/fog-latest/packages/service /usr/share/fog/
 # cp /usr/src/fog_0.15/packages/init.d/ubuntu/FOGMulticastManager /etc/init.d
 # ln -s /etc/init.d/FOGMulticastManager /etc/rc2.d/S99FOGMulticastManager
 # ln -s /usr/share/fog/web /var/www/fog
 # ln -s /etc/apache2/sites-available/fog /etc/apache2/sites-enabled/fog
 
 # cd /usr/share/fog/web/
 # patch -p1 < /usr/src/fog-patches/* 

Edit '/usr/share/fog/service/etc/config.php' so that:

 define( "UPDSENDERPATH", "/usr/bin/udp-sender");
 define( "MULTICASTLOGPATH", "/var/log/fog-multicast.log" );
 define( "MULTICASTDEVICEOUTPUT", "/dev/null" ); 

Now create the file '/var/lib/fog/pxelinux.cfg/default':

 DISPLAY fog/boot.txt
 PROMPT 1
 TIMEOUT 30
 
 DEFAULT fog.local
 
 LABEL fog.local
         localboot 0
 
 # okay, using IPAPPEND could be considered Evil(tm) however as
 # hopefully our imaging time is less than our lease time we
 # should be on safe ground...right?
 LABEL fog.reg
         kernel fog/bzImage
         append initrd=fog/initrd.img mode=autoreg quiet
         IPAPPEND 1
 
 LABEL fog.reginput
         kernel fog/bzImage
         append initrd=fog/initrd.img mode=manreg quiet
         IPAPPEND 1
 
 LABEL fog.debug
         kernel fog/bzImage
         append initrd=fog/initrd.img mode=onlydebug quiet
         IPAPPEND 1 

Type:

 # chown www-data:root /var/lib/fog/pxelinux.cfg
 # chmod 755 /var/lib/fog/pxelinux.cfg
 # chown root:root /var/lib/fog/pxelinux.cfg/default
 # chmod 444 /var/lib/fog/pxelinux.cfg/default 

Change '/etc/default/tftpd-hpa' to say:

 #Defaults for tftpd-hpa
 RUN_DAEMON="yes"
 OPTIONS="-l -v -m /var/lib/fog/tftp-remap /var/lib/tftpboot /var/lib/fog/tftpboot /usr/lib/syslinux /var/lib/fog/pxelinux.cfg" 

Create the file '/var/lib/fog/tftp-remap' that contains:

 re      \/\(.*\)        /var/lib/tftpboot\1
 re      .*              /var/lib/tftpboot/\0 

Edit the file '/etc/exports' and make it contain the following:

 /images     *(ro,sync,no_wdelay,insecure_locks,no_root_squash,insecure,no_subtree_check)
 /images/dev *(rw,sync,no_wdelay,no_root_squash,insecure,no_subtree_check) 

And now run:

 # /etc/init.d/FOGMulticastManager start
 # /etc/init.d/nfs-kernel-server restart
 # /etc/init.d/tftpd-hpa start 

Priming Apache2

Dribbling Deadrat/Ubuntu/Gentoo lusers will probably think libapache2-mod-php5 is the way forward...ho ho, they'll learn one day and the hard way. For the rest of us that know better mod_fcgid is the way forward.

Create the file '/etc/apache2/sites-available/fog' and make it contain the following:

 # removes the ajax guff from the logs
 # N.B. only works from inside a <Virtualhost/> element
 #      otherwise you make this global (should be harmless though)
 <IfModule mod_setenvif.c>
   SetEnvIf Request_URI "/bandwidth\.(update|phpgraph)\.php$" dontlog
 
   #CustomLog /var/log/apache2/access_log common env=!dontlog
 </IfModule>
 
 <Directory /usr/share/fog/web/>
   Options -All
 
   <IfModule mod_fcgid.c>
     <Files *.php>
       Options +ExecCGI
 
       SetHandler fcgid-script
       FCGIWrapper /usr/bin/php-cgi .php
     </Files>
   </IfModule>
 </Directory> 

FOG Existing Alongside Your Existing PXE Infrastructure

As FOG development is a fast moving target (and unfortunately it's design has been a bit head-in-the-sand to the rest of the world about it) making it the centre of your TFTP/PXE world is probably a bad idea. You probably want to have the option to install OS's from your menu, run memdisk, run RIP, run memtest86+ all from a cute menu. FOG does not do this :-/

The solution is to continue running your master one but to have FOG as the default entry with a low timeout.

How do we do this, well you use pxelinux with a COM module that allows you to use an alternative TFTP server. The COM module is 'cooked' with:

 nasm -f bin -l pxechain.lst -o pxechain.cbt pxechain.asm 

Then to use it with pxelinux you have a menu entry like:

 LABEL fog
   MENU LABEL FOG
   COMBOOT /pxelinux.cfg/pxechain.cbt
   APPEND 10.123.21.4::pxelinux.0