Wednesday, June 21, 2017

Setting Up Fog Project On Hyper-V and using PFSense

This post is how to setup the FOG Cloning Project on Hyper-V.  This post is going to show you how to setup Fog On Ubuntu 16.04, on a Hyper-V host and how to redirect the TFTP for saving images and set the pxe boot settings in PFSense so the client machines can boot off the virtualized FOG Server.  The FOG server will also be setup with 2 Hard disks.  One for the OS and Fog Project which will include an apache webserver and mysql database the other a larger virtual drive where we will store the images that you will be saving and using to restore (clone) the other client machines.  This is how we are going to configure our setup.


  • DHCP/DNS: Will be handled by PFSENSE
  • Hyper-V: Will run Fog, handle the backups etc.
  • Fog:  2 Disk VM 80GB for OS and 500GB for Storage.
    Will run the fog services and TFTP Server.


The first thing we're going to do is go through some settings we need to setup PFSense so we don't need to setup a DHCP and DNS server on our virtualized fog.  Were going to let PFSense handle that because if we want to add another PFSense firewall and enable carp, this would give us a failover for our DHCP and DNS Server if we were to lose one of the firewalls.  These settings are for a multi-network setup with different VLANs.  If you're going to set this up on a single SMB network there will be some modification involved (which I will document later)

PFSENSE Settings

For PFSENSE we really just need to modify some settings in the DHCP Server.  The FOG server is going to take care of the network booting and the TFTP server as we stated earlier but we need PFSENSE to point to the FOG Server.  Besides the IP range, mask and gateway the settings we are going to set are the TFTP and Network Booting.  Make sure your DNS is set to your PFSENSE Firewall first.  We set the TFTP server to the IP address of our FOG Server (192.168.1.4) and we enable netbooting with the FOG IP address again.  We make the Default BIOS file name "undionly.kpxe"








That is all that is required for configuring PFSENSE


Configuring Ubuntu 16.04 Server in Hyper-V

For running A fog Server on Hyper-V we are going to use a Gen1 Hyper-V Guest.  We have the network were going to use FOG on VLAN 9.  I have a network LAGG setup it the network adapter shows up as a team, the settings setup though will be very similar if your using a LAGG or not.  



So we create our vlan in the Intel driver in this case vlan9.



Then we create our virtual switch in the virtual switch manager.  This is a tagged VLAN.



Here are our virtual machine settings for our FOG Server.



As you can see we have our Integration Services Enabled, 2 VHDX Files 1 80GB the other 500GB and we are using a the standard network adapter.  I have the FOG Server configured with non-dynamic Disks for better though put performance, 8GB of non-dynamic ram and 2 virtual processors.

Configure The FOG Server

For FOG I am going to be using 16.04 LTS, I am going to be installing a GUI with it so once all that is setup and configured.  The only thing installed on the server version of Ubuntu is the OS and the GUI.  You may want to double check your settings and ensure you remove the unattended-upgrades packages as there have been issues with fog.

Now we want to automount our "images" drive (our send vhdx) so when you do updates and reboot we don't have to remount the drive.  We edit the fstab file sudo vi /etc/fstab

Shown in the image below we add our 500GB vhdx is /dev/sdb1 and below we have what we are mounting the drive as.

/dev/sdb1         /images     ext4     defaults         0         1

Now you may need to play with permissions depending on what your needs are, if your looking for quick and dirty you can go with 777 but you should never go with 777.




The FOG installer will do the rest and it can be downloaded at https://fogproject.org/



Enabling the Hyper-V Integration Services for Linux Distributions that Ship with LIS Drivers and Services Already Installed

First we edit the "modules" file located in /etc/initramfs-tools using this command: 

sudo vi /etc/initramfs-tools/modules

and enter the following lines: 
hv_vmbus 
hv_storvsc 
hv_blkvsc 
hv_netvsc

Save and exit the file.  Run sudo update-initramfs –u then reboot the virtual machine.

Once the guest virtual machine is rebooted, the LIS drivers and services will be registered in the system.

You can verifying Hyper-V Linux Integration Services by running the following command

lsmod or lsmod | grep hv

The above command should list the Hyper-V LIS drivers and services. You'll need to look for hid_hyperv, hv_netvsc, hv_utils, hv_storvsc and hv_vmbus for the successful activation of LIS


Now we install Fog.

It is recommended that you move the extracted fog file to the /opt directory and execute the installer from there.  You can read more about Installing FOG from the project Wiki and I have done a tutorial on how to install Fog Server on my YouTube page.

So we download and fog and extract it.  The current version of Fog Project as of this writing is 1.4.3.  I renamed the folder from fog_1.4.3 to fog after extracting moved the fog folder to the opt directory by sudo mv fog /opt

then cd /fog/bin and sudo ./installfog.sh



The FOG installer will get and setup all required packages.  By default it leaves mysql with no password so I would suggest securing it by installing it before, or after and modifying the fog setting in the fog settings file located in your fog install directory in this case /opt/fog/.fogsettings.


FOG INSTALLER
This is a Ubuntu virtual machine running on Hyper-V so we select choice 2 and we want a Normal Server Install.  I want my IP to be 192.168.1.4 so in PFSENSE you can statically assign the IP before hand or you can do it after but it is best to have what you want planned out before hand.


Now unless your using multiple interfaces you want to keep your default interface in this case eth0.



Then we get asked again if we want FOG to handle DHCP and DNS and since PFSENSE is handling this we say no to both.  Then we get asked for internationalization and for this I selected no.



Fog then goes and get all required packages and installs them.



Here we get asked about the MySQL password and for the purposes of this post it is blank but as will all things you should secure it with a password.



Once all the installs for the database are done, we need to open the browser and verify the schema is up to date, otherwise this can cause us problems and it is easier to reinstall then to try fix the problem.



After updating the Schema, we can finish our install


Updating MySQL Schema in the browser before continuing the fog install.

Here is the screen after the setup is complete.



Remember the default username is fog and the password is password and you should change the GUI login at minimum.



Now that we have this all setup we can start imaging.  I pulled an image from a client machine and I got 4.35GB/min transfer rate on a 1 gig lan connection.  As you can see to pull an image took 10 minutes and to push one took about 20 minutes.




The progress also shows up in the tasks menu in the web based GUI with all the same information as shown below.


Fog Image Capture (Pull)

FOG Image Deploy (Push)

How to migrate PFSense Over to KEA DHCP Server from ISC DHCP Server

I am a PFSENSE User and I manage PFSENSE for some other organizations and the time has come to make the switch for the DHCP Server over to K...