Novell Home

Stop Typing in the Full Path during Imaging

Novell Cool Solutions: Tip
By Dunstan (Box) Lawrence

Digg This - Slashdot This

Posted: 10 Dec 2004
 

I saw Jan Visser's script and was inspired to make my own.

See also http://support.novell.com/cgi-bin/search/searchtid.cgi?/10070811.htm

In the process of making this work I found that mounting the linux.2 file was getting repetitive so I made a script to do it for me.

Update: The script has been updated. Formerly it contained this:

img mp <Server i.P.> <UNC Path><File Name>-`date "+%m%d%y-%H-%M-%S"`.zmg

which does not work correctly, as IMG interprets the generated name as a switch.

It has now been replaced with this (note the semicolon %H;%M):

img mp <Server i.P.> <UNC Path><File Name>-`date"+%m%d%y-__%H;%M"`.zmg

EXAMPLE: auto script

  • Place in any directory alongside a directory called 'New' and your linux.2
  • Make it executable and
  • Run as root
 #!/bin/bash
 #This section pinched from C1 install script
 validateScriptExecution()
{
   id=`id | awk '{print $1}'|awk -F"=" '{print $2}'|awk -F"(" '{print $1}'`

   if [ $id != 0 ]
   then
   echo `gettext install "%% You should have root permissions to execute this script. %%"`
      exit 1
   fi
}
validateScriptExecution
#my code
echo "changing to Directory 'New'"
cd New
pwd
echo "Deleting contents of 'New'"
cd ..
pwd
echo "Mounting Linux.2 as Directory 'New'"
 rm linux
 mv linux.2 linux.gz
 gzip -d linux.gz
 mount -o loop linux New
 echo "Mounted"
 echo "please do whatever you need to," 
 echo "then press any key to continue..."
 read $JUNK
 echo "copy menu file"
 echo "Press any key to continue..."
 read $JUNK
 cp /home/lawrenb/Documents/linux.2/menu /home/lawrenb/Documents/linux.2/New/bin
 echo "menu copied!"
 echo "Press any key to continue..."
 read $JUNK
 umount New
 gzip -9c linux > linux.gz
 mv linux.gz linux.2


menu script
please edit to conform to your environment
make it executable and
place in /bin in your linux.2 as opened by the previous script

#!/bin/bash
#Box Lawrence 2004

clear

echo "##################################"
echo "          image menu"
echo "##################################"
echo ""
echo ""
echo "[1] Restore image"
echo "[2] Restore ONLY C: Drive"
echo "[3] Create image"
echo "[0] quit"
read input

case $input in 

"1" )
# replace names with ones appropriate to your environment

echo "Please enter image name"
echo "[a] Dx2000mt"
echo "[b] D31v"
echo "[c] D230m"
echo "[d] D330m"


read input
case $input in
"a" )
img pd1    #pd = partition delete
img pd2
img pd3
img pd4

hdparm -d1 /dev/hda

# I always keep my 'live' image name the same 
# old images are renamed or moved to a different directory
# new images are created with a unique name
# please see end of script 

img rp <Server i.P.> <UNC Path><File Name>.zmg

img pc2 ntfs  # pc = partition create
img pa1       # pa = partition active
img <Server i.P.> <UNC Path>ddrive.zmg a2:p2
reboot

;;
"b" )
img pd1  
img pd2
img pd3
img pd4

hdparm -d1 /dev/hda

img rp <Server i.P.> <UNC Path><File Name>.zmg

img pc2 ntfs  # pc = partition create
img pa1  #pa = partition active
img <Server i.P.> <UNC Path>ddrive.zmg a2:p2
reboot

;;
"c" )
img pd1
img pd2
img pd3
img pd4

hdparm -d1 /dev/hda

img rp <Server i.P.> <UNC Path><File Name>.zmg

img pc2 ntfs
img pa1
img <Server i.P.> <UNC Path>ddrive.zmg a2:p2
reboot

;;
"d" )
img pd1
img pd2
img pd3
img pd4

hdparm -d1 /dev/hda

img rp <Server i.P.> <UNC Path><File Name>.zmg

img pc2 ntfs
img pa1
img <Server i.P.> <UNC Path>ddrive.zmg a2:p2
reboot

esac
;;

"2" )
echo "Please enter image name"
echo "[a] Dx2000mt"
echo "[b] D31v"
echo "[c] D230m"
echo "[d] D330m"
read input
case $input in 
"a" )
hdparm -d1 /dev/hda

img rp <Server i.P.> <UNC Path><File Name>.zmg a1:p1

reboot

;;
"b" )
hdparm -d1 /dev/hda

img rp <Server i.P.> <UNC Path><File Name>.zmg a1:p1

reboot

;;
"c" )
hdparm -d1 /dev/hda

img rp <Server i.P.> <UNC Path><File Name>.zmg a1:p1

reboot

;;
"d" )
hdparm -d1 /dev/hda

img rp <Server i.P.> <UNC Path><File Name>.zmg a1:p1

reboot

esac
;;
"3" )
echo "Please enter image name"
echo "[a] Dx2000mt"
echo "[b] D31v"
echo "[c] D230m"
echo "[d] D330m"
read input
case $input in 

"a" )
hdparm -d1 /dev/hda
# you will need to add 'date' binary to /bin for this to work (it will need to be the right one for your kernel)
# it will create you image with a unique reference 
# this solves the 'Disable overwrite' issue enabled on some zen image directories
# it also makes it easy to find the one you made
# I always rename my 'live' image to a standard name e.g. xp-hp001.zmg

img mp <Server i.P.> <UNC Path><File Name>-`date"+%m%d%y-__%H;%M"`.zmg 

reboot

;;
"b" )
hdparm -d1 /dev/hda

img mp <Server i.P.> <UNC Path><File Name>-`date"+%m%d%y-__%H;%M"`.zmg 

reboot

;;
"c" )
hdparm -d1 /dev/hda

img mp <Server i.P.> <UNC Path><File Name>-`date"+%m%d%y-__%H;%M"`.zmg 

reboot

;;
"d" )
hdparm -d1 /dev/hda

img mp <Server i.P.> <UNC Path><File Name>-`date"+%m%d%y-__%H;%M"`.zmg 

reboot

;;
"0")
clear
ash -rcfile /bin/bashrc

;;
esac
exit 0
esac

As noted in the script, this requires the 'date' binary (for the correct kernel and libs) to be placed in /bin in the linux.2

Place the edited linux.2 in your TFTP on the appropriate server.
Now when you get to the command prompt you can type 'menu' instead of 'img'

Thanks to Jan Visser for inspiring me, and thanks to Damien Schmitt See his Cool Solution here.

if you have any questions you may contact Box at lawrenb@hct.ac.uk


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

© 2014 Novell