ZCM imaging megapost – part 6 (PXE boot menu)
April 18, 2013 Leave a comment
So as it stands we have the base image, drivers and software side of things sorted – the final step is a deployment method that meets the original criteria of being light-touch but controlled. Using out-the-box ZCM we have two choices:
1) use hardware rules to automatically push an Imaging Bundle to new \ unknown machines
Unsuitable as a generic rule could catch staff machines that aren’t yet ready for imaging (ouch!)
2) install the ZCM Agent then link the Bundle to groups \ folders
Unsuitable as the upgrade to ZCM 11 would break existing ZDM bundles and policies
With neither of the options really appealing I looked to see if there’s a way of using the Imaging Maintenance Menu to do the job. In the current setup we often use it in manual mode and point to an image to use so automating this seemed to be a way forward. Of course with the layered image scenario we need to apply 6 images in total so typing anything in manually is definitely not an option!
Imaging using bash script
Fortunately the imaging engine hasn’t changed much over the years so there’s some previous examples out there that helped point to the solution… bash scripting. The script I’ve customised will ask for confirmation before doing anything, wipe the ISD then apply thebase image + appropriate driver pack based on machine model type. If it doesn’t find anything suitable the technician is warned about this and given the chance to back out of the process. There’s also a bit of ASCII art to brighten things up thanks to http://www.network-science.de/ascii/
If you want to use the script download it from SkyDrive rather than copy \ pasting (never trust HTML formatted text!)
Tip: the echo -en “33c” line clears the screen before the script starts
#! /bin/bash
echo -en "33c"
#DEFINE COLOURS TO BE USED FOR SCRIPT ECHO COMMANDS
RED='\e[0;31m'
YELLOW='\e[1;33m'
NC='\e[0m'
echo -e "${NC}YOUR ORGANISATION "
echo -e "${NC} ZENWorks Imaging"
echo
echo -e "${NC}*********************************************"
echo -e "${NC}Active ZCM imaging proxy address is" $PROXYADDR
echo -e "${NC}*********************************************"
echo
#THIS WILL PRODUCE A VARIABLE FROM THE "COMPUTER PRODUCT NAME" WITH SPACES REMOVED
PRODUCT=$(zisview -s | grep SMBIOS_PRODUCT)
PRODUCT=${PRODUCT:$(expr index "$PRODUCT" '"')}
PRODUCT=${PRODUCT%\"}
#REMOVE SPACES
PRODUCT=${PRODUCT// /}
echo -e "${YELLOW}This machine has been detected as a" $PRODUCT
echo
echo "zisedit data will be cleared before new image is applied"
echo
read -s -n1 -p "Continue to image machine? (y/n)" confirm
if [ "$confirm" = "y" ] ; then
zisedit -c
img rp $PROXYADDR /var/opt/novell/zenworks/content-repo/images/BASE.zmg
img rp $PROXYADDR /var/opt/novell/zenworks/content-repo/images/addon-image/SCRIPTS.zmg
#INSTALL DRIVER ADDON IMAGE BASED ON MACHINE TYPE
if [ $PRODUCT = "HARDWARE1" ]
then
img rp $PROXYADDR /var/opt/novell/zenworks/content-repo/images/addon-image/DRV_HARDWARE1.zmg
elif [ $PRODUCT = "HARDWARE2" ]
then
img rp $PROXYADDR /var/opt/novell/zenworks/content-repo/images/addon-image/DRV_HARDWARE2.zmg
else
echo -e "${RED}<---- NO drivers found ---->${NC}"
read -p "Press [Enter] key to continue or power off now to abort..."
fi
img rp $PROXYADDR /var/opt/novell/zenworks/content-repo/images/addon-image/NOVELL_CLIENT.zmg
img rp $PROXYADDR /var/opt/novell/zenworks/content-repo/images/addon-image/ZCM_AGENT.zmg
img rp $PROXYADDR /var/opt/novell/zenworks/content-repo/images/addon-image/ANTIVIRUS.zmg
reboot -f
else
echo
echo
echo -e "${RED}<---- Image NOT applied! ---->${NC}"
echo
read -p "Press [Enter] key to reboot..."
# reboot -f
fi
To test the script copy it to a USB stick then on a test machine boot into imaging maintenance mode (aka bash prompt) via PXE and run the following commands:
-
lsusb
(check if the USB stick has been detected)
-
fdisk -l
(find the device mount point)
-
mkdir /mnt/stick
(create a mount point for your USB stick)
-
mount /dev/sdb /mnt/stick
(mount USB device at /dev/sdb – substitute sdb for whatever shows up in fdisk -l)
-
cd /mnt/stick
(change to USB stick directory now it’s mounted)
-
ls
(show all files)
-
./win7image2013.sh
(run script)
Copy the script to PXE server
Once you’re happy with your script rename it so the extension is .s (in this example the script I’m using is called win7image2013.s)
- Either use WinSCP (from a Windows machine)
or on a Linux workstation use the file manager and the Connect to Server option - you need to connec to whichever ZCM server is running the PXE services for your network
- The script file needs to be placed in the /srv/tftp/ directory
- Once copied set permissions to match the other files in the directory (owner \ group = zenworks, chmod 0755)
Edit PXE menu
If everything works as expected the next step is to modify the PXE menu to include a new option that will start our imaging script.
Edit the file/srv/tftp/pxemenu.txt using your text editor of choice (make a copy first!) Look under the [Main] section and basically copy \ paste one of the lines but change the last part (where a .cfg file is specified) e.g.
option = execute ; "Windows 7 Image (2013)" ; "Windows 7 Image plus addons - 2013 release" ; pxelinux.0 ; z_image2013.cfg
This will add an additional entry into your ZCM PXE boot menu, obviously tweak to your preferences for where you want it in the list (you can even add some colours to it if you feel that way inclined)
Now you’ve specified the .cfg file to use you’ll need to create it. Easiest way to do it is to copy one of the existing files such as z_auto.cfg and duplicate it with the new name (in this example z_image2013.cfg) The .cfg file is actually telling the PXE server how to launch the preboot environment Linux boot loader, what we add is an additional IMGCMD parameter to specify which script to launch.
#====================== WARNING! ======================# # DO NOT EDIT THIS FILE! # # Modifying this file is unsupported and can have # unpredictable results on ZENworks Preboot Services #======================================================# ZENWORKSAPPEND 1 DEFAULT imaging LABEL imaging kernel boot\linux append 5 initrd=boot\initrd mode=2 rootimage=/root install=tftp://$PXESERVER/boot splash=silent vga=0x314 tftptimeout=50 $KERNEL_PARMS IMGCMD="win7image2013.s"
Important: one change that’s very easy to miss is the mode=2 setting, without this your script won’t run!
Ref: http://forums.novell.com/novell-product-discussions/endpoint-management/zenworks/configuration-management/zcm-10/zcm10-imaging/400764-starting-scripts-pxe-menu.html
Edit boot settings.txt
Although editing yet another file might look a bit of a pain at first it actually saves us a lot of time in the long run. Initially we used the method outlined here http://sysdocs.stu.qmul.ac.uk/sysdocs/StudentSystem/Linux/zen-imaging.html to add the custom imaging script file to the preboot environment. This entailed decompressing initrd, adding any additional scripts to the bin folder and then zipping it back up. Although it works well the process could get a bit arduous if you need to make a lot of changes to the script (new driver options etc).
Fortunately MickD2 on the Novell forums suggests a neater method that (as far as I can tell) copies the file from the TFTP server into the correct folder on the local machine. This makes it a lot easier to change the script file as it’s easily accessible in /srv/tftp rather than zipped up inside initrd.
To do this you need to edit the file settings.txt which can be found in the /srv/tftp/boot folder (make a copy of the file, if not the whole folder first!) and add the following lines at the bottom
tftp $TFTPIP -c get makeimage.s chmod +x *.s mv *.s bin
Test, rinse and repeat
At this point you can start a test machine from PXE, hold down CTRL+ALT and the imaging menu should now have an additional option available. Select it, hit enter and you should see PXELinux start loading up. Once you see the splash screen you can either a) be patient or b) press F2 to view the boot process. You should also be able to notice the boot loader mention that it’s using the custom .cfg file you configured earlier. Once the boot completes your script should fire up and away you go
If you have multiple PXE servers at other sites you’ll need to do all the steps above on each one (that said once you’ve done the first one it’s only a copy \ paste job so should make life a bit easier)




