Issue

When deploying a clone image it is useful to have a menu item within Zim that handles the naming of the computer and restoration of the clone image (via multicast or server based imaging).

NOTE: This TID only applies to the native ZENworks imaging environment.

Solution

Update the zim.cfg file to add in additional clone restore options.

The sample zim.cfg code below will give you the ability to do the following:

  • Configure a clone master machine as an img multicast master.

  • Create a server image of a clone master machine.

  • Configure a clone target machine as an img multicast client machine .

  • Restore a clone image from the ZENworks imaging server to the target machine.

  • Populate ZISD with the computername and other appropriate attributes.

WARNING! Do NOT perform this procedure in a production environment without first fully testing in a non-production test environment.
This procedure includes script samples that will need to be integrated with your existing tftp folder structure.

Procedures

Done Task
 
1. Add clone menu
 
2. Add clone restore section
 
3. Add clone folder to server (optional)
 
4. Test updated files
    • Open your zim.cfg file in Textpad (or other preferred text editor).

    • Identify the Main Menu section of the file.

    • Add a Clone submenu entry into the main menu definition.

      Change:
      ; Main Menu
      
      Menu:Start,mnu_main,"Main Menu","Blue"
      Menu:Submenu,mnu_restore,"Restore Menu",""
      Menu:Submenu,mnu_maint,"Maintenance Menu",""
      Menu:Separator
      ; Menu:Item,logout,"Logout"
      Menu:Item,reboot,"Reboot"
       to: 
      ; Main Menu
      
      Menu:Start,mnu_main,"Main Menu","Blue"
      Menu:Submenu,mnu_restore,"Restore Menu",""
      Menu:Submenu,mnu_maint,"Maintenance Menu",""
      Menu:Submenu,mnu_clone,"Clone Menu",""
      Menu:Separator
      ; Menu:Item,logout,"Logout"
      Menu:Item,reboot,"Reboot"
    • Define the Clone Menu.

       Change: 
      ; Development Menu
      
      Menu:Start,mnu_dev,"Development Menu","Red"
      Menu:Item,dev_make_image,"Make an image"
      Menu:Item,dev_restore_image,"Restore an image"
      Menu:Separator
      Menu:Item,_previous,"Return to Maintenance Menu"
      Menu:Item,_top,"Return to Main Menu"
      
      
      ; ------------------------------------------------------
      ; Simple password authentication
      ; ------------------------------------------------------
       to: 
      ; Development Menu
      
      Menu:Start,mnu_dev,"Development Menu","Red"
      Menu:Item,dev_make_image,"Make an image"
      Menu:Item,dev_restore_image,"Restore an image"
      Menu:Separator
      Menu:Item,_previous,"Return to Maintenance Menu"
      Menu:Item,_top,"Return to Main Menu"
      
      ; Clone Menu
      
      Menu:Start,mnu_clone,"Clone Menu","Red"
      Menu:Item,clone,"Clone Master machine","",Master
      Menu:Item,clone,"Clone Client machine (multicast)","",Client
      Menu:Item,clone,"Clone Client (file on server)","",server
      Menu:Separator
      Menu:Item,_top,"Return to Main Menu"
      
      ; ------------------------------------------------------
      ; Simple password authentication
      ; ------------------------------------------------------
  1. Add clone restore section

    • Find the Development Menu Tasks section of the zim.cfg file. 
      ; ------------------------------------------------------
      ; Development Menu Tasks
      ; ------------------------------------------------------
    • Add the following text above the Development Menu Tasks entry:

      ; ------------------------------------------------------
      ; Clone Menu Tasks
      ; ------------------------------------------------------
      
      label:clone
      
      ; Set Session option based on %_itemparams% variable
      Set:Clone_Session,"%_itemparams%"
      
      ; to make sure all machines are the same hardware - use the drivers image name as the session name
      Set:clone_session_name,%drivers_image%
      
      Label:clone_computername
      
      ; Check for an AssetTag we can use for the DMI_NAME
      Set:DMI_NAME,""
      If:Var,dmi_board_asset,ne,""
      Set:DMI_NAME,"%dmi_board_asset%"
      ElseIf:Var,dmi_chassis_asset,ne,""
      Set:DMI_NAME,"%dmi_chassis_asset%"
      End:
      
      Set:COMPUTERNAME,""
      ; Read the Computername in from ZISD (if it exists)
      Zisd:Get,NetBiosName,ZISD_COMPUTERNAME
      If:Var,ZISD_COMPUTERNAME,ne,""
      Set:COMPUTERNAME,%ZISD_COMPUTERNAME%
      Else:
      Set:COMPUTERNAME,"%DMI_NAME%"
      End:
      
      ; Configure clone image name
      ; Take the drivers image name and replace drivers- with clone-
      
      Set:drivers_image_length,Len("%drivers_image%")
      Set:image_length,%drivers_image_length%
      Set:image_length,Math("-", 7)
      
      Set:clone_image_name,Right("%drivers_image%", %image_length%)
      Set:clone_image_name,clone%clone_image_name%
      
      
      ; Launch a Form to display detected hardware
      Form:Start,"clone_Info","Hardware Detected","_OkCancel^_Ok",Blue
      Form:Item,"Item1",Label,"Manufacturer"
      Form:Item,"Item2",EditBox,": %lookup_section%",ReadOnly
      Form:Item,"Item3",Label,"Model"
      Form:Item,"Item4",EditBox,": %lookup_value%",ReadOnly
      Form:Item,"Item5",Label,"Hardware Image"
      Form:Item,"Item6",EditBox,": %drivers_image%",ReadOnly
      Form:Item,"Item7",Label,"Hardware Type"
      Form:Item,"Item8",EditBox,": %machine_type%",ReadOnly
      Form:Item,"clone1",Label,"Clone Session"
      Form:Item,"clone2",EditBox,": %Clone_Session%",ReadOnly
      Form:Item,"Item9",Label,"Computer Name :"
      Form:Item,"Item10",EditBox,"%COMPUTERNAME%"
      Form:Item,"Item11",Label,"Auto Restart after imaging:"
      Form:Item,"Item12",Radiobuttons,"Yes","Yes,No"
      Form:Display,"clone_Info"
      If:Var,_Form,Eq,"_Cancel"
      Menu:Return
      End:
      Set:clone_autorestart,%_clone_Info_item12%
      Set:mcast_computer_name,%_clone_Info_item10%
      
      Goto:clone_%Clone_Session%
      
      Label:Clone_Master
      
      ; Check to see if we are making an image to the server or multicasting it out to clients
      Form:Start,"Clone_Master_check","Check Clone Master type","_BackNextCancel^_Next",Blue
      Form:Item,"Item1",Label,"Clone Master type"
      Form:Item,"Item2",RadioButtons,"Multicast","Multicast, Server"
      ; Display form
      Form:Display,"Clone_Master_check"
      If:Var,_Form,eq,"_Cancel"
        Menu:Return
      End:
      
      If:Var,_Form,eq,"_Back"
        Goto:clone
      End:
      
      Set:master_type,%_Clone_Master_check_Item2%
      
      label:Clone_Master_check
      
      If:Var,master_type,eq,"Server"
      ; We need to make an image of the machine and store it on the ZENworks server.
      ; This will be stored under the content-repo/images/clone folder by default
      ; the image will be named based on the driver information detected.
      
      ; Launch a Form to detail image information
      Form:Start,"clone_master_server","Image information","_OkCancel^_Ok",Blue
      Form:Item,"Item1",Label,"Image Path :"
      Form:Item,"Item2",EditBox,"clone",readonly
      Form:Item,"Item3",Label,"Image Name :"
      Form:Item,"Item4",EditBox,"%clone_image_name%",readonly
      Form:Display,"clone_master_server"
      If:Var,_Form,Eq,"_Cancel"
      Menu:Return
      End:
      Set:clone_image_name,%_clone_master_server_item4%
      File:Run,"img %imgmakecmd%clone/%clone_image_name%",verbose
      File:Run,"cat imglogr >> %_ZimDir%zim.log",verbose
      
      If:Var,_error,eq,"57"
      ; file exists on server.
      
      Dialog:Ask,"Warning! Image Creation Failed","Image file already exists on server\n Retry with different name?","_YesNo^_No",RED
      If:Var,_ask,eq,"_Yes"
      Set:clone_image_name,%clone_image_name%-1
      Goto:Clone_Master_check
      End:
      End:
      If:Var,_error,eq,"29"
      ; file path is invalid.
      Dialog:Ask,"Warning! Image Creation Failed","File path does not exist on server\n path is: content-repo/images/clone \n Please check that this path exists.\n\n Retry","_YesNo^_No",RED
      If:Var,_ask,eq,"_Yes"
      Goto:Clone_Master_check
      End:
      End:
      Goto:clone_update_zisd
      End:
      ; Master machine will be multicasted out to machines.
      
      Form:Start,"Clone_Master","Multicast Master","_BackNextCancel^_Next",Blue
      Form:Item,"Item1",Label,"Clients to wait for (i.e. 30)"
      Form:Item,"Item2",EditBox,"30"
      Form:Item,"Item3",Label,"Time to wait for Clients to connect (i.e. 30min)"
      Form:Item,"Item4",EditBox,"30"
      ; Display form
      Form:Display,"Clone_Master"
      
      If:Var,_Form,eq,"_Cancel"
        Menu:Return
      End:
      
      If:Var,_Form,eq,"_Back"
        Goto:clone
      End:
      
      Set:clone_master_clients,%_Clone_Master_Item2%
      Set:clone_master_time,%_Clone_Master_Item4%
      
      
      ; Now run the Multicast Master clone session
        File:Run,"img -session %clone_session_name% -master -clients=%clone_master_clients% -timeout=%clone_master_time%",verbose
        File:Run,"cat imglogr >> /zimbin/zim.log",verbose
        goto:clone_update_zisd
      
      label:Clone_Client
      
      Dialog:Ask,"", "Warning! All hard disk data on this machine will be erased.\n \nContinue?","_YesNo^_Yes",red
      If:Var,_ask,eq,"_No"
      Menu:Return
      End:
        ; Session is a multicast client
      File:Run,"img -session %clone_session_name% -client",verbose
        File:Run,"cat imglogr >> /zimbin/zim.log",verbose
      
      Goto:clone_update_zisd
      
      Label:clone_server
      If:Var,Clone_Session,eq,"Server"
        ; Session is a unicast restore from the ZENworks server
      File:Run,"img %imgrestorecmd%clone/%clone_image_name%",verbose
        File:Run,"cat imglogr >> /zimbin/zim.log",verbose
      End:
      
      
      Label:clone_update_zisd
      ; Update the information in ZISD
      
      Zisd:Put,NetBiosName,%mcast_computer_name%
      
      ; Update VendorDataENGL
      Set:VendorDataENGLSTRING,PutKeyPairStringValue("%VendorDataENGLSTRING%","Machine_Type","%machine_type%")
      
      ZISD:Put,VendorDataENGL,"%VendorDataENGLSTRING%"
      
      Set:zisd_update_count,"1"
      Label:clone_update_zisd
      
      ZISD:Write
      
      ; Trap ZISD:Write errors
      If:Var,_ERROR,ne,"0"
      If:Var,zisd_update_count,lt,"3"
      Set:zisd_update_count,math(+, 1)
       File:Run,"dd if=/dev/zero of=/dev/%HDTYPE% bs=512 seek=5 count=3",silent
      goto:clone_update_zisd
      Else:
      Dialog:Ask,"Error!","An error occurred writing information to ZISD!","_Ok",red
      End:
      End:
      
      If:Var,clone_autorestart,eq,"Yes"
      Goto:reboot
      End:
      Menu:Return
      
      
    • Save the changes to the zim.cfg.
  2. Add clone folder to server (optional)


    1. Review the ../content-repo/images/ folder structure.
    2. If there is not a clone sub-folder. Create one.

      NOTE: This folder is required if you wish to create or restore an image via the server.

  3. Test updated files


    1. Test Master options.

      • Run Zclonewiz on a machine that has been built using the ENGL deployment process.
      • PXE boot the machine to the ZENworks imaging environment / Zim menu.
      • Select the Clone Menu option.
      • Select the Clone Master machine option.
      • When prompted select the appropriate option:

        • If Multicast is selected the machine will launch a multicast master session using the drivers image name as the session.
        • If Server is selected the machine will make an image on the server.

           This will be made to the content-repo/images/clone/ folder. The image name is the drivers image name with drivers replaced with clone.
      •  All options should run successfully.
    2. Test Client options

      • PXE boot a machine that is to receive a clone image.
      • Select the Clone Menu option.
      • When prompted select the appropriate client option:

        • Select Clone Client machine (multicast) to connect to a multicast master session.

           The machine will attempt to connect to a multicast session using the drivers image name as the session.
        • Select Clone Client (file on server) to restore a clone image from the ZENworks imaging server.

           This will restore from the content-repo/images/clone/ folder. The image name is the drivers image name with drivers replaced with clone.
      •  All options should run successfully.