Novell Home

Run Bash Scripts from the PXE Menu

Novell Cool Solutions: Feature
By Art Flores

Digg This - Slashdot This

Posted: 29 Mar 2007
 

Editor's Note: Art sent along this nice note with his excellent submission. "Over the years, Cool Solutions has really helped me out, so I am glad to offer something back to the Cool Solutions community. Thanks for all of the Cool Solutions, and keep up the good work."

Thank you, Art! It is exactly this kind of sentiment that keeps the lights on around here. Ten years of contributions have built Cool Solutions into a vast repository of some of the most creative and practical ideas in the world. Here's hoping you never get tired of sharing.

Would you like to run your own bash scripts from the Preboot Services (PXE) Menu? Novell provides all of the tools you need. Here is a print screen of the ZEN preboot menu editor showing my custom menu options.



Software tools used for building a custom PXE Menu

We are running Novell NetWare 6.5 SP5, and ZENworks Desktop Management 7 SP1 hot patch 2.

The Preboot Services Menu Editor (Preworx) utility is provided by Novell, and can be found on the CD or download. Look for the directory named "Menu Editor".

To add the bash scripts to the initrd (initial ram disk image), I installed and used SLES 10, which can be downloaded from Novell's web site.

To transfer my new initrd file that I built on the SLES 10 machine, I used an FTP server that I have running on a NetWare box. If you decide to use an FTP server, you will need sufficient rights to upload and download files. Another option would have been to install the Novell Client for Linux.

If you have ever written DOS batch files, learning the Bash should be easy for you. I learned about using bash scripts from the Novell ATT ZENworks class, Cool Solutions, and Google. There are lots of great web sites out there to learn more about bash scripting.

Building the Menu

To make it easier to keep track of menu and script name changes during the development process, I put everything into a text document. This way I could copy/paste changes when I needed to. I have pasted the text I used for your convenience.

*********************************************************

ZEN Maintenance Menu

 0 Backup Hard Disk
 1 Backup D: Drive
 2 Create Partitions
 3 Maintenance Mode ZEN Imaging
 4 Repair ZEN Imaging Agent
 5 Restore Hard Disk
 6 Restore D: Drive
 7 Restore XP Standard Image
 8 Start ZEN Imaging

Heading
Information
Help
Command
Name of bash script
   
Backup Hard Disk
Create Full backup of hard disk to ZEN image on the server.
Create a Full backup of a user's disk to a ZEN image.
LoadLin.dnx cmds\z_auto0.cmd
buhd.s

Backup D: Drive
Create a backup of D: drive to a ZEN image on the server.
Create a backup of a user's D: drive to a ZEN image.
LoadLin.dnx cmds\z_auto1.cmd
budd.s

Create Partitions
Create new partitions of C:70% NTFS and D:30% FAT32.
Create new partitions to prepare for an image restore. 
LoadLin.dnx cmds\z_auto2.cmd
parthd.s

Maintenance Mode ZEN Imaging 
Boot into the Novell ZEN Linux bash command line over PXE.
Boot over the network using PXE to the Linux prompt.
LoadLin.dnx cmds\z_maint.cmd

Repair ZEN Imaging Agent
Clear out the ZENworks Image Safe Data store.
Run the dd utility to clear out the ZISD store.
LoadLin.dnx cmds\z_auto4.cmd
clearisd.s

Restore Hard Disk
Restore a Full backup from a ZEN image on the server.
Restore a user's disk from a ZEN image on the server.
LoadLin.dnx cmds\z_auto5.cmd
rsthd.s

Restore D: Drive
Restore the D: drive from a backup on the server.
Restore a user's D: drive from a backup on the server.
LoadLin.dnx cmds\z_auto6.cmd
rstdd.s

Restore XP Standard Image
Restore the Windows XP Standard Image to drive C:.
Restore the Windows XP Standard Image to drive C:.
LoadLin.dnx cmds\z_auto7.cmd
rstxpstd.s

Start ZEN Imaging
Start ZEN Imaging client over PXE.
Start ZEN Imaging client over the network using PXE.
LoadLin.dnx cmds\z_auto.cmd

*********************************************************

Building and testing your bash scripts

I tested my scripts by booting up to the bash prompt over PXE, downloading the script, and running it under Novell's runScript.s. Here is an example of how I tested a script named buhd.s.

# cd bin
/bin# tftp $TFTPIP ?c get buhd.s

Tip: When developing your scripts, save them to the sys:\tftp directory. It is much quicker and easier to download them using tftp instead of ftp.

Tip: If you would like to upload files using tfpt, edit the sys:\system\tftp.ini file, change the line WriteProtect=1 from 1 to 0, and reload the tftp.nlm.

This next command will run your bash script.

/bin# runScript.s buhd.s

I found the code for adding color to my scripts at these links.

Here is a paste of my buhd.s script (backup hard disk).

#!/bin/bash
. /bin/runScript.s /bin/chkatg.s

NC='\e[0m'
RED='\e[0;31m'
WHITE='\e[1;37m'
YELLOW='\e[1;33m'

MachineName=$(zisview computername)
if [ -n "$MachineName" ]; then
   echo Found $MachineName
else
   tmp=$(hwinfo --bios | grep "302-")
   MachineName=${tmp:16:9}
fi
setterm -clear
echo -e "${YELLOW}Office Of The Texas Attorney General, Child Support Division.${NC}\n\c"
echo -e "${WHITE}ZEN Imaging is authorized for IT Network Services use only.  ${NC}\n\c"
echo
echo "  Backup hard disk to a ZEN image on the server to VOL2:\Backup\."
echo
echo -e "  Create a full backup of the hard disk for machine ${WHITE}$MachineName${NC}\n\c"
echo
read -s -n1 -p "Continue create full backup? (y/n)" confirm

if [ "$confirm" = "y" ] ; then

   img mp $PROXYADDR //$PROXYADDR/vol2/backup/$MachineName.zmg

   if [ $? = 0 ] ; then
      echo The full backup of the hard disk to a ZEN image completed for $MachineName.
      sleep 10
      reboot -f
   else
      setterm -clear
      cat /bin/imglogr
      echo -e "  ${RED}Full backup of the hard disk failed!${NC}\a\n\c"
      echo
      echo Error log generated from script buhd.s >>/bin/imglogr
      cp /bin/imglogr /bin/$MachineName".log"
      tftp $TFTPIP -c put $MachineName".log"
      read -s -n1 -p "Please contact the Help Desk...press any key to reboot."
      reboot -f
   fi
   
else
   setterm -clear
   echo
   echo
   read -s -n1 -p "Program aborted, press any key to reboot."
   reboot -f
fi

Tip: When using the special shell variable $? for a return value, and a script doesn't work right, use the command echo $? to see what number is being returned. $? reads the exit status of the last command executed.

Adding your scripts to Initrd

Here is the link that I followed to add my bash scripts to the initrd.
65.4.2 Adding Files to the Initrd or Root File Systems

Calling your custom scripts from the PXE menu

Here is an example of how I got the menu calls to work. I copied the file sys:\tftp\cmds\z_auto.cmd, and named it sys:\tftp\cmds\z_auto0.cmd. Z_auto0.cmd calls the script buhd.s.

Here is a paste of the contents of z_auto0.cmd.

KERNEL boot/linux
APPEND initrd=boot/initrd install=tftp://$TFTPIP/boot rootimage=/root PROXYADDR=$PROXYADDR TFTPIP=$TFTPIP splash=silent PXEBOOT=YES mode=2 IMGCMD="runScript.s /bin/buhd.s"

Troubleshooting Tips

  1. Some of our switches are 8 to 10 years old, so we have been configuring our switch ports to use forced mode instead of auto-negotiate. To check to see if you are connecting at 100/Full or 100/Half, use this command as the bash prompt.

    Ethtool ?eth0

    If you have a half duplex connection, imaging will run very slow. To fix this issue, I added the following line of code to the file sys:\tftp\boot\settings.txt file.

    ethtool -s eth0 autoneg off speed 100 duplex full


  2. If an automated imaging request fails, or if after an image restore the computer name is not correct, the ZENworks Imaging Windows Agent (ZISWIN) may be experiencing problems in the ZENworks Image Safe Data (ZISD) store. To check if ZISWIN is having problems:

    1. Click Start Run, type in ZISWIN and press Enter.
    2. If you see the message "No image-safe data on this machine.", something is using this disk space, and there is not enough free disk space for ZISWIN to write in the ZISD store.


    3. To fix this problem, the DD command must be used to clear the ISD. Boot up to the Linux Bash prompt, and type in the command:

      dd if=/dev/zero of=/dev/hda bs=512 seek=5 count=3


  3. If you run ZISWIN and check the history file, you may see the following error:

    C:\ZISWIN.HST is not a valid ZENworks Imaging Agent history file.

    To fix this problem, delete the file, reboot, and you should see messages in the history now.


  4. If you run ZISWIN and check the history file, you may see the following error:

    Error occurred while saving the image-safe data. No message available for this error (-107).

    To fix this problem, run the DD command as specified in tip 2.

If you have any questions you may contact Art at Art.FloresTAKETHISOUT@cs.oag.state.tx.us


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell