Cool Solutions

Automating Non-Automatic ZENworks Imaging – Part 1



By:

February 12, 2010 6:34 am

Reads:9,330

Comments:5

Score:5

ZEN imaging is great, but out of the box it’s hardly the panacea that it can be.

Like many others, we have built our imaging using a non-monolithic image system that layers pieces on top of each other to create a finished product. All of this is done from the ZENworks Image Maintenance mode, whereas we are running commands from a Bash prompt in the imaging environment.

Our images are built from:

  1. Baseline image with the OS, sysprepped for deployment.
  2. An add-on image containing our imaging scripts
  3. A driver image for the model of computer that we’re imaging.

We worked to write some scripts that would automate the process of layering in the images but the first issue was figuring out how to get them down to the machine.

This can be accomplished by adding the following lines to the /srv/tftp/boot/settings.txt file:

cd /bin
tftp $PROXYADDR -c get addon/addons
bash /bin/addons

The settings.txt file is actually a script file that is run at the end of the ZENworks imaging environment initialization. What we’ve asked it to do is to download a file called addons that we’re storing in /srv/tftp/addon directory that will be the file that prepares our environment.

The addons file looks like this:

#!/bin/bash
#######################################################################
#-- Imaging environment preparation script
#######################################################################

## Download additional scripts
cd /bin

## Auto image script
tftp $PROXYADDR -c get addon/autoImage
chmod +x /bin/autoImage

## Download standard MBR image
if [ ! -e "/imgfiles" ]; then 
   mkdir /imgfiles
fi
cd /imgfiles
tftp $PROXYADDR -c get addon/mbr.img

This script will download all of the other scripts that we need for our environment. Additionally, it is downloading a standard MBR image that we use during the imaging process. We always image partition to partition as opposed to the entire image to work around the problem of different drive sizes. With that, the problem occurred that when a brand new hard drive is used, ZEN does not install a new master boot record so the drive ends up being unusable. We resolve this problem by rewriting the master boot record every time a drive is imaged.

This is a stripped down version of the script that we use, but over the course of these articles we will enhance it with additional functionality.

Now, for our imaging script which we will put in /srv/tftp/addon/autoImage

#!/bin/bash
########################################################################-- Standard baseline imaging script
#
#-- This script is used to pull down a baseline image to a PC.
#######################################################################

##--- [BEGIN environment configuration]
basepath=//$STORAGEADDR/images/
baseimg=xpsp3base.zmg
baseapp=addons/baseapp.zmg
driverbase=addons/driverimg/
##--- [END environment configuration]

partsize="0"
sysname=""

## Help display
function syntax {
   echo "Correct command syntax is:"
   echo "   autoImage [partsize:SIZE] [sysname:NAME]"
   echo
   echo "   partsize - Specify the size of the boot partition to be created in megabytes."
   echo "              If not specified, the entire drive will be used. ** 1 GB = 1000 MB"
   echo
   echo "   sysname - Specify the Windows name to use for this system.  If not specified,"
   echo "             the serial number for the machine will be used."
}

## Parse command line variables
for var in "$@"
do
   validcmd=0
   cmd=${var%%:*}
   if [[ $var == *:* ]]; then
      val=${var#*:}
   else
      val=""
   fi
   if [[ $cmd == partsize ]]; then
      if [[ "$val" -ne "" ]]; then
         partsize=$val
         validcmd=1
      fi
   fi
   if [[ $cmd == sysname ]]; then
      if [[ "$val" != "" ]]; then
         sysname=$val
         validcmd=1
      fi
   fi
   if [[ $cmd == help ]]; then
      syntax
      exit
   fi
   if [[ $validcmd == 0 ]]; then
      echo "Invalid command."
      echo
      syntax
      exit
   fi
done

## Check to make sure that this is being run on purpose
while true; do
   read -p "Are you sure you want to image this computer? " yn
   case $yn in
      [Yy]* ) break;;
      [Nn]* ) exit;;
      * ) echo "Please answer yes or no.";;
   esac
done

## Get computer model number information (without spaces)
## This is used to determine the name of the driver image add-on file
cpumodel=`/usr/sbin/dmidecode -s system-product-name | tr -d ' '`

## Get computer serial number from DMI
serialnumber=`/usr/sbin/dmidecode -s system-serial-number | tr -d ' '`

## Use the system's serial number if no name was specified on the
## command line
if [[ "$sysname" != "" ]]; then
   serialnumber=$sysname
fi

## Clear out all existing partitions and create one
img pd-all

## Install clean MBR
dd if=/imgfiles/mbr.img of=/dev/sda count=1 bs=446

if [ $partsize == 0 ]; then
   img pc1 ntfs
else
   img pc1 ntfs $partsize 
fi

## Clear set the workstation name to the system's serial number
zisedit computername=$serialnumber

## Download the base image
img rp $PROXYADDR "$basepath$baseimg" a1:p1

## Download the base apps image
img rp $PROXYADDR "$basepath$baseapp"

## Download the driver image
img rp $PROXYADDR "$basepath$driverbase$cpumodel.zmg"

## Set first partition to be active
img pa1

## Reboot and complete the process
reboot -f

This script will give you the option to specify the workstation name for the system as well as a partition size in the event that you need to image a machine without using the entire drive.

The system takes the workstation’s model number from DMI to determine the name of the driver image file. It also strips out all spaces for simplicity. For example, if the model number in DMI is “Latitude D630″, the driver image file name will be LatitudeD630.zmg

The script will then layer the three images onto the machine and reboot. After the reboot, it is up to my post-imaging scripts to prep the system and install all of the required applications.

The master boot record image file (mbr.img) is available below, but you can make your own if you prefer.

The way that I prefer to create the master boot record image file is to boot with some sort of Linux environment. You can use the imaging environment, however you will need some method of copying the file from the imaging environment, though if you have an FTP server available, that’s easily accomplished.

From Linux, type the following:

dd if=/dev/sda of=mbr.img bs=446 count=1

This will back up just the master boot record and will not overwrite the partition table.

If you wish to wipe out the partition table as well, start with a drive with no partitions and change the bs=446 to bs=512.

In the next article, we’ll talk about automating the process of backing up and restoring images from existing machines.

3 votes, average: 5.00 out of 53 votes, average: 5.00 out of 53 votes, average: 5.00 out of 53 votes, average: 5.00 out of 53 votes, average: 5.00 out of 5 (3 votes, average: 5.00 out of 5)
You need to be a registered member to rate this post.
Loading ... Loading ...

Categories: Uncategorized

Disclaimer: This content is not supported by Novell. It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test it thoroughly before using it in a production environment.

5 Comments

  1. By:aspirer

    very good!
    but would you please tell us how we make mbr.img file & provide the mbr.img file ?

  2. By:Provogeek

    Have a running copy of Ack’s script in 1 ZFD7 accounts and two ZCM 10 accounts.

    It is an awesome script and with properly written Windows automation scripts, you can get the same functionality as ENGL with out the cost.

  3. By:KrisSmith

    We use a similar technique but we also have a script that extracts the individual PCI device IDs (and one that does USB) and pulls driver addon Image for that device.

    This allows us to deliver drivers for any addin cards that a machine has.
    So far we have one base image & around 7000 desktops. (plus laptops)

    http://www.novell.com/communities/node/3313/delivering-right-drivers-imaging

    During the windows install we have a script that runs any .bat file in a particular directory. Those .bat files do the silent install of the drivers (and are packaged up with the addon image)

    Kris

    • By:ackitsme

      Our solution is a good fit for an installation where you have known computer models and configurations. We tend to buy systems in quantities and don’t often have internal hardware changes. With our method, we simply have one image per system model. In the rare chance that we have more than one set of hardware in a given model, we just add the extra drivers to the driver image.

      Of course, this whole point is moot with Windows 7 and their distribution share architecture.

Comment

RSS