Scripts for Imaging
Novell Cool Solutions: Feature
By Henny van der Ben
Reader Rating
from 2 ratings
|
Digg This -
Slashdot This
Posted: 29 Sep 2005 |
See this article for more information./p>
Overview
During the linux boot process the variable $PROXYADDR gets its value from the zenimage server. With this variable it is possible to make a universal script to get a text file from the zenimage server.
One of the advantages of copying the "menu" separate from LINUX.2 is that it is very easy to adjust without starting a LINUX station. It is a plain text file in the TFTP directory on the zenimage server.
For this reason we adjust LINUX.2 by adding the script GETMENU.S and adjust the script PROMPT.S
GETMENU.S and PROMPT.S
Explanation
- Start a Linux machine.
- Copy LINUX.2 from <Zen-server>\SYS\TFTP.
- Rename LINUX.2 to LINUX.GZ
- Extract LINUX.GZ
- Mount the extract file.
- Add a task in PROMPT.S.
- Create the file GETMENU.S.
- Make PROMPT.S bootable.
- Unmount the file.
- Gzip the file.
- Rename the file to LINUX.2
- Copy LINUX.2 to <Zen-server>\SYS\TFTP.
Work to do
For the transport between the zenimage server and the linux machine I have used a USB stick. The stick must have a minimum of 64 Mb free space, because when extracted, LINUX.2 will be approximately 50 Mb.
Start a terminal session on your Linux machine and go to your USB stick.
Go to the root of the stick (cd /) and make a new directory zen. (md /zen)
To rename, extract, and mount LINUX.2, you can use the following script.
mount.s
With the following command you can make or change the script:
pico mount.s
#!/bin/bash # # # Author: # Henny@vanderben.com, 2005 # # Version: # 1.0 07 july 2005 # # Function: # Rename, unzip en mount LINUX.2 to ZEN ###################################################################### echo "Linux.2 rename in linux.gz" mv linux.2 linux.gz echo "" echo "Uzip Linux.gz" gzip -d linux.gz echo "" echo "Mount Linux in zen" mount -o loop linux /zen cd /zen
Make the script executable.
chmod 777 mount.s
Start the script.
./mount.s
Go to the bin directory.
cd bin
prompt.s
pico prompt.s
#!/bin/ash . /bin/config.s manual mountFloppyifLS120 if [ $? != 0 ]; then echo "Failed to mount floppy drive. If there is a floppy in the drive, REMove it before running img"; fi export MANUALREBOOT=YES export SHELLACTIVE=YES . /bin/getmenu.s ash -rcfile /bin/bashrc
Place . /bin/getmenu.c before ash -rcfile /bin/bashrc.
getmenu.s
pico getmenu.s
#!/bin/bash # # # Author: # Sibrand@Minnen.net, Henny@vanderBen.com # # Version: # 1.0 07 july 2005 # # Function: # Get imaging menu from TFTP server, make it bootable en start menu.s ######################################################################### # Get menu.txt van ZEN server and rename it in /bin/menu.s tftp -c get $PROXYADDR:menu.txt /bin/menu.s # make menu.s executable chmod 777 /bin/menu.s # start menu.s menu.s
Make GETMENU.S executable.
chmod 777 getmenu.s
umount.s
To dismount, gzip and rename LINUX, you can use the following script.
pico umount.s
#!/bin/bash # # # Author: # Henny@vanderben.com, 2005 # # Version: # 1.0 07 july 2005 # # Function: # Unmounten ZEN en zip en rename LINUX to LINUX.2 #################################################################### echo "Unmount ZEN" cd / umount /zen echo "" echo "Zip Linux in linux.gz" gzip -9c linux > linux.gz echo "" echo "Rename Linux.gz to linux.2" mv linux.gz linux.2 echo "" echo "Ready"
Make the script executable.
chmod 777 umount.s
LINUX.2 is ready to use. Unmount the USB stick (umount /media /<USB>) and copy the new file in the TFTP directory on the zenworks image server.
The adjustment for LINUX.2 is ready.
MENU.TXT
The menu is divided into three blocks:
- Variables
- Functions
- Program
Only the variables need to be adjusted to let the menu work the way you want it to.
Variables
UNC
The path to the ZENworks image server <Volume>/<Complete path>
###################################### Path to images on Zen server unc=<Volume>/<Complete path>
Table #D
This table is used to build the driver menu. There are four columns. Every row is a menu item. Don't use spaces because they are used as separators.
- Column 1 #D
- Column 2 Name of driver
- Column 3 Item number in menu (maximum= 9, if you need more items you should build a second driver menu)
- Column 4 Complete name from zmg file in image directory
###################################### TABLE: #D driver-name # # Column 1: Table must begin with #D # Column 2: Type must be without spaces # Column 3: Number is item number in menu # Column 4: Complete name from zmg file in image directory # # Maximum 9 items # ###################################### <#D> <type1> <1> <driver1.zmg> <#D> <type2> <2> <driver2.zmg> <#D> <type3> <3> <driver3.zmg> <#D> <type4> <4> <driver4.zmg> <#D> <type5> <5> <driver5.zmg> <#D> <type6> <6> <driver6.zmg> <#D> <type7> <7> <driver7.zmg> <#D> <type8> <8> <driver8.zmg> <#D> <type9> <9> <driver9.zmg>
Table #I
This table consists of the names of the standard zmg files. There are two columns.
- Column 1 #I
- Column 2 Name ZMG image
###################################### TABLE: #I image-name # # Column 1: Table must begin with #I # Column 2: Complete name from zmg file in image directory # ###################################### #I xpsp2nl.zmg #I sysprep.zmg #I install.zmg #I txtfiles.zmg #I addinf.zmg
Functions
We have chosen to work with functions and not to add any programs. One of the examples is the function CLS, to clear the screen. CLS is not standard in this LINUX version so we wrote a function.
The following functions are used in this menu.
Clear
###################################### Clear screen
cls()
{
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
do
echo ""
done
}
Use first HDD
###################################### 1st HDD active
acthdd()
{
hdparm -d1 /dev/hda1
}
Remove all partitions from HDD
###################################### REMove partitions
REMpart()
{
img pd4
img pd3
img pd2
img pd1
}
Remove only first partition from HDD
###################################### REMove C: partition
REMc()
{
img pd1
}
Make first partition active HDD
###################################### Activate partitions
actpart()
{
img pa1
}
Read the names from the general images
###################################### Get imagename from TABLE #I
restpart()
{
grep "^\#I " $0|while read comment imagefile
do zenimg
done
}
Read the image names from Table #I
- Do as long there is #I
- Read the comment (Column 2) and place it in the variable image file
- Execute the function zenimg
Restore the image
###################################### Restore images
zenimg()
{
img rp $PROXYADDR //$PROXYADDR/$unc/$imagefile a1:p1
}
Driver menu
- Place the first part from the menu on the screen.
- Do as long there is #D.
- Read the comment and place Column 2 in variable menu item, 3 in variable number and 4 in variable image file.
- Place item number and menu item on the screen.
- Wait for input from user.
- Compare the input with menu item.
- Execute function zenimg.
- Test if the input is 0, then leave the menu else reboot workstation.
###################################### Driver menu
drvmnu()
{
cls
echo "##########################"
echo "####### Driver menu ######"
echo "##########################"
echo ""
echo ""
########### Definition menu
grep "^\#D " $0|while read comment menuitem nummer naam
do echo " "[$nummer] $menuitem
done
echo " [0] Exit"
read drvimg
########### ZMG item restore
grep "^\#D " $0|while read comment menuitem nummer imagefile
do if test $drvimg -eq $nummer
then
zenimg
fi
done
if test $drvimg -ne 0
then
echo "reboot"
else
cls
echo "Thanx"
fi
}
Program
Clear the screen and show the menu.
cls echo "###################################################" echo "####### Image menu #######" echo "###################################################" echo "" echo "" echo " [1] Restore Workstation" echo " [2] Restore Workstation with custom C: partition" echo " [3] Restore C: drive" echo " [4] Create image" echo " [0] Exit" read image case $image in
When the user chooses Option 1, the following will be executed:
- Go to 1st HDD.
- Remove all the partitions.
- Make a FAT32 partition from 10Gb.
- Make in the free space an NTFS partition.
- Restore the general images.
- Make the 1st partition active.
- Start the driver menu.
"1" ) ###################################### 1st HDD active acthdd ###################################### REMove partitions REMpart ###################################### Make 1st partitions 10Gb FAT32 img pc1 fat32 10240 ###################################### Make 2nd partition NTFS img pc2 ntfs ###################################### Restore general images restpart ###################################### Make 1st partition active actpart ###################################### Restore driver image drvmnu ;;
When the user chooses Option 2, the following will be executed:
- Ask the user the size of the 1st partition.
- Go to 1st HDD.
- Remove all the partitions.
- Make a FAT32 partition with the correct size.
- Make in the free space an NTFS partition.
- Restore the general images.
- Make the 1st partition active.
- Start the driver menu.
"2" ) cls echo "Size C: partition (in Mb):" read part ###################################### 1st HDD active acthdd ###################################### REMove partitions REMpart ###################################### Make 1st partitions 10Gb FAT32 img pc1 fat32 $part ###################################### Make 2nd partition NTFS img pc2 ntfs ###################################### Restore general images restpart ###################################### Make 1st partition active actpart ###################################### Restore driver image drvmnu ;;
When the user chooses Option 3, the following will be executed:
- Go to 1st HDD.
- Remove only the 1st partition.
- Make a FAT32 partition from 10Gb.
- Restore the general images.
- Make the 1st partition active.
- Start the driver menu.
"3" ) echo "Restore C:" ###################################### 1st HDD active acthdd ###################################### REMove partitions REMc ###################################### Make 1st partitions 10Gb FAT32 img pc1 fat32 10240 ###################################### Restore general images restpart ###################################### Make 1st partition active actpart ###################################### Restore driver image drvmnu ;;
When the user chooses Option 4, the following will be executed:
- Go to 1st HDD.
- Ask the user the name for the image file without .zmg.
- Make the image.
- Leave the menu.
"4" ) cls echo "Give name of image without zmg" read naam img mp $PROXYADDR //$PROXYADDR/$unc/$naam.zmg ;;
When the user chooses Option 4, the following will be executed:
- Leave the menu.
"0" ) ;; esac exit 0
Complete MENU.TXT
#!/bin/bash # # # Author: # Sibrand@Minnen.net, Henny@vanderBen.com , 2005 # # Version: # 1.0 07 july 2005 # # Function: # Editable menu for PXE imaging without modifying Linux.2 # All the menu commands are in the standard kernel which # comes with ZENworks. ########################################################################### ############################### Variables ############################# ########################################################################### ###################################### Path to images on Zen server unc=/ ###################################### TABLE: #D driver-name # # Column 1: Table must begin with #D # Column 2: Type must be without spaces # Column 3: Number is item number in menu # Column 4: Complete name from zmg file in image directory # # Maximum 9 items # ###################################### <#D> <type1> <1> <driver1.zmg> <#D> <type2> <2> <driver2.zmg> <#D> <type3> <3> <driver3.zmg> <#D> <type4> <4> <driver4.zmg> <#D> <type5> <5> <driver5.zmg> <#D> <type6> <6> <driver6.zmg> <#D> <type7> <7> <driver7.zmg> <#D> <type8> <8> <driver8.zmg> <#D> <type9> <9> <driver9.zmg> ###################################### TABLE: #I image-name # # Column 1: Table must begin with #I # Column 2: Complete name from zmg file in image directory # ###################################### #I xpsp2nl.zmg #I sysprep.zmg #I install.zmg #I txtfiles.zmg #I addinf.zmg ########################################################################### ############################### Functions ############################# ########################################################################### ###################################### Clear screen cls() { for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 do echo "" done } ###################################### 1st HDD active acthdd() { hdparm -d1 /dev/hda1 } ###################################### REMove partitions REMpart() { img pd3 img pd2 img pd1 } ###################################### REMove C: partition REMc() { img pd1 } ###################################### Activate partitions actpart() { img pa1 } ###################################### Restore images zenimg() { img rp $PROXYADDR //$PROXYADDR/$unc/$imagefile a1:p1 } ###################################### Restore images from TABLE image name restpart() { grep "^\#I " $0|while read comment imagefile do zenimg done } ###################################### Driver menu drvmnu() { cls echo "##########################" echo "####### Driver menu ######" echo "##########################" echo "" echo "" ########### Definition menu grep "^\#D " $0|while read comment menuitem nummer naam do echo " "[$nummer] $menuitem done echo " [0] Exit" read drvimg ########### ZMG item restore grep "^\#D " $0|while read comment menuitem nummer imagefile do if test $drvimg -eq $nummer then zenimg fi done if test $drvimg -ne 0 then echo "reboot" else cls echo "Thanx" fi } ########################################################################### ############################### Begin program ############################# ########################################################################### ###################################### Image menu cls echo "###################################################" echo "####### Image menu #######" echo "###################################################" echo "" echo "" echo " [1] Restore Workstation" echo " [2] Restore Workstation with custom C: partition" echo " [3] Restore C: drive" echo " [4] Create image" echo " [0] Exit" read image case $image in "1" ) ###################################### 1st HDD active acthdd ###################################### REMove partitions REMpart ###################################### Make 1st partitions 10Gb FAT32 img pc1 fat32 10240 ###################################### Make 2nd partition NTFS img pc2 ntfs ###################################### Restore general images restpart ###################################### Make 1st partition active actpart ###################################### Restore driver image drvmnu ;; "2" ) cls echo "Size C: partition (in Mb):" read part ###################################### 1st HDD active acthdd ###################################### REMove partitions REMpart ###################################### Make 1st partitions 10Gb FAT32 img pc1 fat32 $part ###################################### Make 2nd partition NTFS img pc2 ntfs ###################################### Restore general images restpart ###################################### Make 1st partition active actpart ###################################### Restore driver image drvmnu ;; "3" ) echo "Restore C:" ###################################### 1st HDD active acthdd ###################################### REMove partitions REMc ###################################### Make 1st partitions 10Gb FAT32 img pc1 fat32 10240 ###################################### Restore general images restpart ###################################### Make 1st partition active actpart ###################################### Restore driver image drvmnu ;; "4" ) cls echo "Give name of image without zmg" read naam img mp $PROXYADDR //$PROXYADDR/$unc/$naam.zmg ;; "0" ) ;; esac exit 0
Reader Comments
- Decent, but techs/users would have to know the name of the image file(s). There could be times when multiple images may be needed.
Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

