Automated Installer - Example I

I would like to introduce how we (G11n Team in Prague) use the Automated Installer (AI).

We have a lot of machines for Solaris and OpenSolaris testing which are reinstalled almost every day. The Automated Installer makes things easier and is really great help now! It took a lot of time to solve all the problems which we were facing. But with help of the Caiman team we got through these problems. 

For example:

  • How to easy jumpstart Solaris and OpenSolaris
  • Just one DHCP server in our subnet
  • Run our post install automated tests without manual reboot (AI didn't reboot automatically after installation)
  • What if the boot from net option is set as a permanent in GRUB  
  • Possibility to install both language supports (slim and global)
  • Test our G11n IPS packages (actually, we are still waiting when AI can be able to install from two IPS repositories like the Distribution Constructor can)

Note: This is not documentation for the Automated Installer! The documentation can be found here.

 Example I - subnet


We created the interactive script called jump, which creates and assigns macros to the machines. Now we can jumpstart OpenSolaris, Solaris and also Linux very easy. We didn't create a new DHCP server but used existed DHCP server for our subnet.

System requires:

OpenSolaris 2008.11 or latter (AI server runs only on OpenSolaris)

The latest OBP (Open Boot PROM) for SPARC - see bug 6172

More information about upgrading the OBP can be found here. For SunBlade1500 and UltraSparc45 machines you can boot directly from: /net/lepra.czech/repo/export/pub/obp/blade1500 and /net/lepra.czech/repo/export/pub/obp/ultra45

SUNWinstalladm-tolls with reboot option - see bug 6556

If you don't want to edit microroot or build AI image with reboot option , you will nee the latest version of the SUNWinstalladm-tools package which allows to enable reboot option in the manifest.

How to build the Caiman gate and get packages the latest versions can be found here.

AI images - can be downloaded from /net/lepra.czech/repo/export/images/ai/ or OpenSolaris.com page or built by the Distribution Constructor

Start AI server

Note: we start service without DHCP server, because don't need another DHCP server created by AI

For SPARC

$ pfexec installadm create-service -n sparc_slim_108 -s /net/lepra.czech/repo/export/images/ai/automated_installer_image_sparc.iso /export/ai_boot_images/sparc_slim_108
$ pfexec installadm create-service -n sparc_global_108 -s /net/lepra.czech/repo/export/images/ai/automated_installer_image_sparc.iso /export/ai_boot_images/sparc_global_108 

Note: Information which macro should contain are displayed

For x86

$ pfexec installadm create-service -n x86_slim_108 -s /net/lepra.czech/repo/export/images/ai/automated_installer_image_x86.iso /export/ai_boot_images/x86_slim_108
 $ pfexec installadm create-service -n x86_global_108 -s /net/lepra.czech/repo/export/images/ai/automated_installer_image_x86.iso /export/ai_boot_images/x86_global_108

Note: Information which macro should contain are displayed

The macros are stored in /net/lepra.czech/repo/export/tftp/

E.g.:

$ cat /repo/export/tftp/x86/osol_x86_global_108 
x86
:Subnet=255.255.255.0:Router=10.16.22.1:Broadcst=10.16.22.255:BootSrvA=10.16.22.13:BootFile=x86_global_108:GrubMenu=menu.lst.x86_global_108:Timeserv=10.16.22.13:LeaseTim=86400:LeaseNeg:DNSdmain=czech.sun.com:DNSserv=10.16.22.11:UTCoffst=3600:

$ cat /repo/export/tftp/sparc/osol_sparc_slim_108 
sparc
:Subnet=255.255.255.0:Router=10.16.22.1:Broadcst=10.16.22.255:BootSrvA=10.16.22.13:BootFile="http://10.16.22.13:5555/cgi-bin/wanboot-cgi":Rootpath="http://10.16.22.13:5555/export/ai_boot_images/sparc_slim_108":Timeserv=10.16.22.13:LeaseTim=86400:LeaseNeg:DNSdmain=czech.sun.com:DNSserv=10.16.22.11:UTCoffst=3600:

Note: Exactly 2 lines are required

The manifests

For slim installation (core languages)

Just change ai_auto_reboot to true.

Click here to see the manifest.

For global installation (all languages)

Click here to see the manifest.

Jump script

Can be downloaded here.

#!/bin/sh 

# QA Network OS Installation Configuration Script
# @(#)jump      7/march/09      
# 01/03/09

FIND="/usr/local/bin/find"
FIND_MAXDEPTH="5"
IMAGE_DIR="/export/fast/images"
NETWORK="10.16.22.0"
OLDDIR=`pwd`

# JUMPSTART OPTIONS
PROFILESERVER="10.16.22.10"
PROFILEDIR="/export/mirror/jumpstart"
KICKDIR="/export/mirror/jes/kickstart"
SINSTNM="tgm"
SINSTIP4="10.16.22.10"
SROOTNM="tgm"
SROOTIP4="10.16.22.10"
SJUMPSCF="$PROFILESERVER:$PROFILEDIR"

SIGHUP=1
SIGINT=2
SIGQUIT=3
SIGTERM=15

welcome()
{
   SCRIPTNAME=$0
   ID=`id`
   USER=`expr "${ID}" : 'uid=\\([\^(]\*\\).\*'`

   trap abort $SIGHUP $SIGINT $SIGQUIT $SIGTERM

   # Verify user ID before proceeding - must be root
   if [ "${USER}" != "0" ]; then
      echo "You must be root to run $0"
      cleanup
      exit 1
   else
      echo "============================================================="
      echo "                      Welcome to Jump                        "
      echo "            OS Installation Configuration Utility            "
      echo "                    G11n Team in Prague                      "
      echo "============================================================="
   fi
}

abort()
{
   echo "${SCRIPTNAME}: Aborted"
   cleanup
   exit 1
}

check_find()
{
   if [ -f $FIND ];
   then
      $FIND /tmp -maxdepth 1 >/dev/null 2>&1
      RET=$?
      if [ $RET -ne 0 ];
      then
         echo "Don't have GNU find, using default. Performance will be lower."
         GNUFIND=0
      else
#         echo "Using GNU find."
         GNUFIND=1
      fi
   else
      echo "The file '$FIND' does not exist. Using /usr/bin/find instead."
      echo "Performance will be lower."
      FIND="/usr/bin/find"
      GNUFIND=0
   fi
}

get_os()
{
   echo; echo "Select OS:"
   echo "1. Solaris"
   echo "2. OpenSolaris"
   echo "3. RedHat Linux"
   echo
   printf "Choose OS [1]: "
   read OS
   case $OS in
      1)        LOGOS="Solaris"; solaris;;
      2)        LOGOS="OpenSolaris"; opensolaris;;
      3)        LOGOS="RedHat"; LOGPLATFORM="x86"; redhat;;
      \*)        LOGOS="Solaris"; solaris;;
   esac
}

get_platform()
{
   echo; echo "Select platform:"
   echo "1. X86"
   echo "2. SPARC"
   printf "Choose platform [1]: "
   read PLATFORM
   case $PLATFORM in
      1)        LOGPLATFORM="x86"; sol_x86;;
      2)        LOGPLATFORM="sparc"; sol_sparc;;
      \*)        LOGPLATFORM="x86"; PLATFORM=1; sol_x86;;
   esac
}

get_hosts()
{
   cat /etc/ethers | grep "\^[0-9]\*:" | awk '{ print $2 }' | sed "/lepra/d" >> /tmp/hosts.$$
}

show_hosts()
{
   HOSTS=`cat /tmp/hosts.$$`
   N=1
   for i in $HOSTS
   do
      echo "$N. $i" >> /tmp/hosts_menu.$$
      N=`expr $N + 1`
   done
   cat /tmp/hosts_menu.$$
}

get_host_mac()
{
# get the MAC, IP and MAC in DHCP format for the target host

   HOSTMAC=`cat /etc/ethers | egrep "\^[0-9].\*" | egrep ":[0-9a-f][0-9a-f][      ]\*${USEHOST}[   ]\*(#.\*)\*$" | awk '{ print $1 }'`

   if [ "$HOSTMAC" = "" ]; then
          printf "\\nError: MAC adress for host '$USEHOST' not found in /etc/ethers!\\n\\n"
          exit 3
       else
          echo "MAC: $HOSTMAC"
       fi
}

get_host_ip()
{
        HOSTIP=`cat /etc/hosts | grep "${USEHOST}[ ]\*$" | awk '{ print $1 }'` 

        if [ "$HOSTIP" = "" ]; then
                printf "Error: IP adress for host '$USEHOST' not found in /etc/hosts!\\n\\n"
                exit 4
        else
                echo "IP: $HOSTIP"
        fi
}

# delete DHCP network table for specific machine
delete_dhcp_entry()
{
        echo "Deleting DHCP network table for" $USEHOST 
        /usr/sbin/pntadm -D $USEHOST $NETWORK 2>/dev/null
}

# create DHCP network table for specific machine
create_dhcp_entry()
{
        echo "Creating DHCP network table for" $USEHOST
        /usr/sbin/pntadm -A $USEHOST -f PERMANENT -c $USEHOST -i $CLIENTID -m $CLIENTID $NETWORK
}

get_client_id()
{
        CLIENTID=01`echo $HOSTMAC |perl -pe 's/:/\\n/g' | sed 's/\^\\([0-9]\\)$/0\\1/' | sed 's/\^\\([A-Fa-f]\\)$/0\\1/' | perl -pe 's/\\n//' | tr [:lower:] [:upper:]`
        delete_dhcp_entry
        create_dhcp_entry
}

select_host()
{
   echo; echo "Select host for JumpStart setup:"
   get_hosts
   show_hosts
        USEHOST=""

        while [ "$USEHOST" = "" ]; do
        echo; printf "Choose host: "
        read SELECTION

                if [ "x`echo ${SELECTION}|egrep '\^[a-zA-Z][-a-zA-Z0-9]\*$'`" != "x" ]; then
                        USEHOST=`cat /tmp/hosts_menu.$$|egrep "\^[0-9]+[.] ${SELECTION}$"| awk '{ print $2 }'`
                elif [ "x`echo ${SELECTION}|egrep '\^[0-9]+$'`" != "x"  ]; then
                USEHOST=`cat /tmp/hosts_menu.$$ | egrep "\^${SELECTION}[.] [-0-9a-zA-Z]+$" | awk '{ print $2 }' `
                else
                        USEHOST=""
                fi
                if [ "$USEHOST" = "" ]; then
                        echo "Invalid selection."
                fi
        done
   echo; echo "Host $USEHOST selected."
}

get_sol_images()
{
   if [ $GNUFIND -eq 1 ];
   then
      $FIND $IMAGE_DIR -maxdepth $FIND_MAXDEPTH -name .cdtoc > /tmp/search.$$ 2>/dev/null
   else
      $FIND $IMAGE_DIR -name .cdtoc > /tmp/search.$$ 2>/dev/null
   fi

   sed "s:.cdtoc::g" /tmp/search.$$ > /tmp/images.$$
}

get_osol_images()
{
 echo "$PLATFORM"
 find /net/lepra.czech.sun.com/repo/export/tftp/$PLATFORM -type f > /tmp/images.$$
}

filter_img_platf_osol()
{
   cat /tmp/images.$$ | while read LINE
   do
        IMGPLATFORM=`head -1 $LINE`
        if [ "$IMGPLATFORM" = "sparc" ]; then
                echo $LINE >> /tmp/images_sparc.$$
        else
                echo $LINE >> /tmp/images_x86.$$
        fi
   done
}

filter_img_platf()
{
   cat /tmp/images.$$ | while read LINE
   do
      VOLINF=`cat $LINE/.volume.inf | grep -i sparc`
      if [ "$VOLINF" = "" ]; then
         echo $LINE >> /tmp/images_x86.$$
      else
         echo $LINE >> /tmp/images_sparc.$$
      fi
   done
}

show_images()
{
   case $PLATFORM in
      1)        IMAGES=`cat /tmp/images_x86.$$`;;
      2)        IMAGES=`cat /tmp/images_sparc.$$`;;
   esac

   N=1
   for i in $IMAGES
   do
      echo "$N. $i" >> /tmp/images_menu.$$
      N=`expr $N + 1`
   done
   cat /tmp/images_menu.$$
}

cleanup()
{
   rm /tmp/\*.$$ 2>/dev/null
   cd $OLDDIR
}

get_sol_toolsdir()
{
   DIR1=`ls $USEIMAGE | grep -i "solaris_[0-9]\*"`
   TOOLSDIR="$USEIMAGE/$DIR1/Tools"
   if [ ! -d $TOOLSDIR ]; then
      echo "No directory $TOOLSDIR found."
      exit 2
   fi
}

select_sol_image()
{
   echo; echo "Select image for JumpStart setup:"
   show_images
   echo; printf "Choose image: "
   read SELECTION

   if [ "$SELECTION" = "" ]; then
   echo "Invalid selection."
   exit 1
   fi

   USEIMAGE=`cat /tmp/images_menu.$$ | grep "\^${SELECTION}[.] .\*" | awk '{ print $2 }' ` 
   echo; echo "Image $USEIMAGE selected."
   
   if [ "$LOGOS" != "OpenSolaris" ]; then
     get_sol_toolsdir
   else
     OSOLMACRO=`tail -1 $USEIMAGE`
   fi
}

select_sol_boot_loader()
{
   echo; echo "Select network boot loader:"
   echo "1. PXE Grub (S10U1 and above)"
   echo "2. Solaris Network Boot (S10 and below)"
   printf "Choose network boot loader [1]: "
   read BLOADER
   case $BLOADER in
      1)        LOGBLOADER="grub"; sol_x86_grub;;
      2)        LOGBLOADER="nbp"; sol_x86_nbp;;
      \*)   BLOADER=1; LOGBLOADER="grub"; sol_x86_grub;;
   esac
}

netboot_sol_x86()
{
   echo; echo "Do you want to configure network boot?"
   echo "1. Yes"
   echo "2. No"
   echo "if you're installing OpenSolaris, you must choose 1"
   printf "Choose option [1]: "
   read WANTNETBOOT
   case $WANTNETBOOT in
      1)        LOGNETBOOT="Yes"; select_sol_boot_loader;;
      2)        LOGNETBOOT="No"; sol_x86_nonet;;
      \*)        LOGNETBOOT="Yes"; select_sol_boot_loader;;
   esac
}

# parameter $1 ... macro name to delete
delete_dhcp_macro()
{
   /usr/sbin/dhtadm -P | awk '{ print $1 }' | grep $1 >/dev/null
   RET=$?
   case $RET in
      0)        /usr/sbin/dhtadm -D -m $1;;
      \*)        echo;echo "Macro $1 not yet defined.";;
   esac
}

# parameter $1 ... macro name to add
add_dhcp_macro_sol_grub()
{
   echo "Creating DHCP macro: $1"
   /usr/sbin/dhtadm -A -m $1 -d \\
   ":BootFile=\\"$1\\":SjumpsCF=\\"$SJUMPSCF\\":SsysidCF=\\"$SJUMPSCF/$USEHOST\\":" >/dev/null 2>&1

   RET=$?
   case $RET in
      0)        /usr/bin/pkill -1 in.dhcpd;;
      \*)        echo "Error modifying DHCP table."; exit $RET;;
   esac
}

# parameter $1 ... macro name to add. $2 is macro to add
add_dhcp_macro_osol_grub()
{
   echo "Creating DHCP macro: $1"
   /usr/sbin/dhtadm -A -m $1 -d \\
   "$2" >/dev/null 2>&1
   RET=$?
   case $RET in
      0)        /usr/bin/pkill -1 in.dhcpd;;
      \*)        echo "Error modifying DHCP table."; exit $RET;;
   esac
}

# parameter $1 ... macro name to add
add_dhcp_macro_sol_nbp()
{
   echo "Creating DHCP macro: $1"
        echo "..avoiding dhcp option overflow"
        # hack specific for S9x86 nbp - DHCP is limited for dhcp-request 43 (vendor-options packed) upto 255bytes
        # for now, we can try to remove symlinks as it might not break anything
        NBP_SJUMPSCF=`echo $SJUMPSCF|sed -e's/\\/mirror//'`
        NBP_USEIMAGE=`echo $USEIMAGE|sed -e's/\\/fast//'`
        NBP_TOOLSDIR=`echo $TOOLSDIR|sed -e's/\\/fast//'`
   /usr/sbin/dhtadm -A -m $1 -d ":SinstNM=\\"$SINSTNM\\":SinstIP4=$SINSTIP4:SinstPTH=\\"$NBP_USEIMAGE\\":SrootNM=\\"$SROOTNM\\":SrootIP4=$SROOTIP4:SrootPTH=\\"$NBP_TOOLSDIR/Boot\\":BootFile=\\"nbp.$1\\":SbootURI=\\"tftp://$SINSTIP4/$1\\":SjumpsCF=\\"$NBP_SJUMPSCF\\":SsysidCF=\\"$NBP_SJUMPSCF/$USEHOST\\":" 
#>/dev/null 2>&1
   /usr/bin/pkill -1 in.dhcpd

   RET=$?
   case $RET in
      0)        ;;
      \*)        echo "Error modifying DHCP table."; exit $RET;;
   esac

}

get_jump_options()
{
        AWKTMP=/tmp/jump_awkmenu.$$
        AWKTAR=$MENU_TMPFILE
        # init options to differ x86/sparc Solaris
        if [ $PLATFORM -eq 1 ]; then    # Solaris x86
                AWKPAT='kernel\\/unix install'
                AWKDEL=','
        else                                                                            # Solaris sparc 
                AWKPAT="\^$USEHOST "
                AWKDEL=' '
        fi

        # read options from file
   grep -v '\^#' $PROFILEDIR/$USEHOST/bootenv.rc | grep -v '\^[    ]\*$' | while read LINE
   do
                printf "%s%s" "$AWKDEL" "$LINE" >> $AWKTMP
   done
        AWKOPT=`cat $AWKTMP`
        if [ "X$AWKOPT" = "X" ]; then
                echo "No JumpStart options found or accessible.";
                exit 7
        fi

        # run awk to update files
        AWKCMD="/$AWKPAT/ {print \\$0\\"$AWKOPT\\"; next}; {print}"
        cp $AWKTAR $AWKTAR.orig.$$
        awk "$AWKCMD" $AWKTAR.orig.$$ > $AWKTAR
   case $RET in
      0) ;;
      \*) echo "Error!"; exit $RET;;
        esac
}

solaris()
{
   echo; echo "========== S O L A R I S =========="
   echo; echo "Searching for available images ..."
   get_sol_images
   filter_img_platf
   get_platform
}

opensolaris()
{
   echo; echo "========== O P E N S O L A R I S =========="
   echo; echo "Searching for available images ..."
   get_osol_images
   filter_img_platf_osol 
   get_platform
}

sol_x86()
{
   echo; echo "========== S O L A R I S  x 8 6 =========="
   select_sol_image
   select_host
   netboot_sol_x86
}

sol_x86_grub()
{
  get_host_mac
  get_host_ip
  get_client_id
  if [ "$LOGOS" != "OpenSolaris" ]; then
   cd $TOOLSDIR

   # run add_install_client. It will modify /etc/bootparams, create boot files under /tftpboot
   # and create a menu file for grub in /tftpboot/menu.lst.<HOSTMAC> 

   ./add_install_client -d -e $HOSTMAC -c ${SJUMPSCF} \\
    -p ${SJUMPSCF}/$USEHOST i86pc 
#>/dev/null 2>&1

   if [ $? -ne 0 ]; then
      printf "\\nError encoutered! The host '$USEHOST' has not been set up for JumpStart.\\n\\n"
      exit 6
   fi

   # modify DHCP table
   delete_dhcp_macro $CLIENTID
   add_dhcp_macro_sol_grub $CLIENTID

   # 1. modify the menu file to automatically perform the JumpStart
   #    by including "install" as a kernel parameter
   # 2. create second menu entry for manual install

   MENUFILE="/tftpboot/menu.lst.$CLIENTID"
   HUMANMENUFILE="/tftpboot/menu.lst.$USEHOST"
   MENU_TMPFILE="/tmp/menu.lst.$$"
   if [ -f $MENU_TMPFILE ]; then
         /bin/rm $MENU_TMPFILE
   fi
   TITLE=`cat $MENUFILE | grep "[ \\t]\*title "`
#   KERNEL=`cat $MENUFILE | grep "[ \\t]\*kernel "`
#   MODULE=`cat $MENUFILE | grep "[ \\t]\*module "`
KERNEL=`cat $MENUFILE | grep "[ \\t]\*kernel[ $]"`
MODULE=`cat $MENUFILE | grep "[ \\t]\*module[ $]"`
   TITLE_NEW=`echo $TITLE | sed -e 's/\\(.\*\\)Jumpstart/\\1Manual Install/'`

   sed -e 's/kernel\\/unix/kernel\\/unix install/' -e 's/default=0/default=2/' $MENUFILE > $MENU_TMPFILE
   printf "\\n$TITLE_NEW\\n$KERNEL\\n$MODULE\\n" >> $MENU_TMPFILE

        # add jumpstart options via PXE bootpath
        if [ -f $PROFILEDIR/$USEHOST/bootenv.rc ]; then
                get_jump_options
                case $RET in
        0) echo "Done!";;
        \*) echo "Error in jump_opt_x86!"; exit $RET;;
                esac
        fi

   # add SunGhost entry:
   USEETH=`cat $KICKDIR/ks_ethlist | grep -i $USEHOST | awk '{ print $2; }'`
   if [ "x$USEETH" = "x" ]; then
        USEETH="eth0"
   fi

cat <<EOF >> $MENU_TMPFILE

title HDD First partition
   rootnoverify (hd0)
   chainloader +1

title SunGhost (DHCP)
   root (nd)
   kernel (nd)/sg.img ramdisk_size=80000 sg_net=eth0:dhcp sg_net=eth1:dhcp sg_net=eth2:dhcp sg_net=eth3:dhcp quiet
   initrd (nd)/sg.gz

EOF

   # ------------------

   mv $MENU_TMPFILE $MENUFILE
   if [ ! -L $HUMANMENUFILE ]; then 
        /bin/rm -f $HUMANMENUFILE
        ln -s $MENUFILE $HUMANMENUFILE > /dev/null 2>&1
   fi
   chmod 666 $MENUFILE


  else
   # modify DHCP table
   delete_dhcp_macro $CLIENTID
   add_dhcp_macro_osol_grub $CLIENTID $OSOLMACRO
  fi
   printf "\\nDone! Please, reboot the machine $USEHOST and boot it using PXE.\\n"
   printf "(Press F8 or F12 after reboot and select MBA UNDI as the boot device.)\\n\\n"
}

sol_x86_nbp()
{
   get_host_mac
   get_host_ip
   get_client_id
   cd $TOOLSDIR
   ./add_install_client -d -e $HOSTMAC -c ${SJUMPSCF} \\
    -p ${SJUMPSCF}/$USEHOST i86pc > /tmp/add_install_client_out.$$
# -b "input-device=keyboard" \\
# -b "output-device=screen" i86pc 
#>/dev/null 

   # parse BootFile & BootURI from the output of add_install_client script

   BOOTID=`cat /tmp/add_install_client_out.$$ | grep "\\(BootFile\\)" | awk -F: '{ print $2 }' | head -1 | sed 's/nbp[.]//'`

   # modify DHCP table
   delete_dhcp_macro $CLIENTID
   delete_dhcp_macro $BOOTID
   #add_dhcp_macro_sol_nbp $CLIENTID
   add_dhcp_macro_sol_nbp $BOOTID

   printf "\\nDone! Please, reboot the machine $USEHOST and boot it using PXE.\\n"
   printf "(Press F8 or F12 after reboot and select MBA UNDI as the boot device.)\\n\\n"
}

sol_x86_nonet()
{
   get_host_mac
   get_host_ip
   cd $TOOLSDIR
   ./add_install_client -c ${SJUMPSCF} -p ${SJUMPSCF}/$USEHOST $USEHOST i86pc >/dev/null

   printf "\\nDone! Please, reboot the machine $USEHOST and boot it using CD/DVD media.\\n"
   printf "Choose Network Install - Jumpstart as the installation method.\\n\\n"
}

sol_sparc()
{
   echo; echo "========== S O L A R I S  S P A R C =========="
   select_sol_image
   select_host
  if [ "$LOGOS" != "OpenSolaris" ]; then
   cd $TOOLSDIR
   ./add_install_client -c ${SJUMPSCF} -p ${SJUMPSCF}/$USEHOST $USEHOST sun4u 
   RET=$?
   case $RET in
      0)        echo "Done!";;
      \*)        echo "Error!"; exit $RET;;
   esac
        # add jumpstart options via bootparams
        if [ -f $PROFILEDIR/$USEHOST/bootenv.rc ]; then
                MENU_TMPFILE=/tmp/jump_bootparams.$$
                cp /etc/bootparams $MENU_TMPFILE
                get_jump_options
                case $RET in
        0) ;;
        \*) echo "Error in jump_opt_sparc!"; exit $RET;;
        esac
                mv /etc/bootparams /etc/bootparams.orig
                mv $MENU_TMPFILE /etc/bootparams
        fi
  else
   get_host_mac
   get_host_ip
   get_client_id
   # modify DHCP table
   delete_dhcp_macro $CLIENTID
   add_dhcp_macro_osol_grub $CLIENTID $OSOLMACRO
        printf "\\nDone! Please, reboot the machine $USEHOST with command \\"reboot net:dhcp\\"\\n"
        printf "(or press \\"Stop + a\\" on the machine $USEHOST and enter \\"boot net:dhcp\\")\\n\\n"
  fi
}

show_kickstart()
{
        KSFILES=`ls -1A $KICKDIR/\*ks_${USEHOST}\* 2>/dev/null`
        RET=$?
        case $RET in
                0)      ;;
                \*)      echo "No config found."; exit $RET;;
        esac

        N=1
        for i in $KSFILES
        do
                echo "$N. $i" >> /tmp/kickstart_menu.$$
                N=`expr $N + 1`
        done
        cat /tmp/kickstart_menu.$$
}

select_kickstart()
{
        echo; echo "Select kickstart configuration:"
        show_kickstart
        echo; printf "Choose config: "
        read SELECTION

        if [ "$SELECTION" = "" ]; then
                echo "Invalid selection."
                exit 1
        fi

        USECFG=`cat /tmp/kickstart_menu.$$ | grep "\^${SELECTION}[.] .\*" | awk '{ print $2 }' `
        echo; echo "Config $USECFG selected."

        case $USECFG in
                \*rh30_x86\*)     USEIMG=rh3x86;USETITLE='Redhat 3.0 x86';;
                \*rh30u6_x86\*)   USEIMG=rh3u6x86;USETITLE='Redhat 3.0 ur6 x86';;
                \*rh40_x86\*)     USEIMG=rh4x86;USETITLE='Redhat 4.0 x86';;
                \*rh40_amd64\*)   USEIMG=rh4amd64;USETITLE='Redhat 4.0 amd64';;
                \*rh4u6_x64\*)   USEIMG=rh4u6_x64;USETITLE='Redhat 4.0u6 amd64';;
                \*rh40u3_x86\*)   USEIMG=rh4u3x86;USETITLE='Redhat 4.0 ur3 x86';;
                \*rh40u4_x86\*)   USEIMG=rh4u4x86;USETITLE='Redhat 4.0 ur4 x86';;
                \*rh50_x86\*)     USEIMG=rh5x86;USETITLE='Redhat 5.0 x86';;
                \*rh52_x86\*)     USEIMG=rh52x86;USETITLE='Redhat 5.2 x86';;
                \*rh52_x64\*)     USEIMG=rh52x64;USETITLE='Redhat 5.2 x64';;
        esac
}

redhat()
{
   echo;echo "========== R E D H A T  L I N U X =========="
        select_host
        select_kickstart

        get_host_mac
        get_host_ip
        get_client_id

        #modify DHCP table
        delete_dhcp_macro $CLIENTID
        add_dhcp_macro_sol_grub $CLIENTID

        MENUFILE="/tftpboot/menu.lst.$CLIENTID"
        HUMANMENUFILE="/tftpboot/menu.lst.$USEHOST"
        MENU_TMPFILE="/tmp/menu.lst.$$"
        if [ -f $MENU_TMPFILE ]; then
                /bin/rm $MENU_TMPFILE
        fi
        USEETH=`cat $KICKDIR/ks_ethlist | grep -i $USEHOST | awk '{ print $2; }'`
        if [ "x$USEETH" = "x" ]; then
                USEETH="eth0"
        fi
cat << RHEOF > $MENU_TMPFILE
default=2
timeout=30

title HDD First partition
   rootnoverify (hd0)
   chainloader +1

title SunGhost (DHCP)
   root (nd)
   kernel (nd)/sg.img ramdisk_size=80000 sg_net=eth0:dhcp sg_net=eth1:dhcp sg_net=eth2:dhcp sg_net=eth3:dhcp quiet
   initrd (nd)/sg.gz

title $USETITLE
        root (nd)
        kernel (nd)/ks_vmlinuz_$USEIMG ks=nfs:10.16.22.10:$USECFG ksdevice=${USEETH}
        initrd (nd)/ks_initrd_$USEIMG

RHEOF

        #---------------------------------------
        
        mv $MENU_TMPFILE $MENUFILE
        if [ ! -L $HUMANMENUFILE ]; then
                /bin/rm -f $HUMANMENUFILE
                ln -s $MENUFILE $HUMANMENUFILE > /dev/null 2>&1
        fi
        chmod 666 $MENUFILE

        printf "\\nDone! Please, reboot the machine $USEHOST and boot it using PXE.\\n"
        printf "(Press F8 or F12 after reboot and select MBA UNDI as the boot device.)\\n\\n"
}

# Delete exiting macro in 10 minutes
delete_macro_after_timeout()
{
        if [ $PLATFORM = 1 ]; then              #platform is x86
                echo "Do you wish to delete created macro in 5 minutes? [yes]"
                echo "   Yes - You have only 5 minutes to jumpstart selected PC"
                echo "   No - You can jumpstart the PC without any time restriction"
                read ANSWER
                ANSWER=`echo $ANSWER | tr [:upper:] [:lower:]`
                case $ANSWER in
                        no)     exit 10 ;;
                        \*)      echo "Created macro will be deleted in 5 minutes"
                                echo "/usr/sbin/dhtadm -D -m $CLIENTID && /usr/bin/pkill -1 in.dhcpd" >/tmp/tmpfile.$$
                                echo "rm /tmp/tmpfile.$$" >>/tmp/tmpfile.$$
                                at -f /tmp/tmpfile.$$ now + 5 minutes 2>/dev/null
                                ;;
                esac
        fi
}

# ==================== MAIN ====================

welcome
check_find
get_os
cleanup
who am i | sed 's/\^\\([\^ ]\*\\ \\).\*/\\1/' > /export/jes/scripts/machines/$USEHOST
date +%b\\%e\\ %T >> /export/jes/scripts/machines/$USEHOST
echo "$USEIMAGE$USECFG" >> /export/jes/scripts/machines/$USEHOST
echo "$LOGPLATFORM" >> /export/jes/scripts/machines/$USEHOST
echo "$LOGOS" >> /export/jes/scripts/machines/$USEHOST
echo "$HOSTIP" >> /export/jes/scripts/machines/$USEHOST
echo "$LOGNETBOOT" >> /export/jes/scripts/machines/$USEHOST
echo "$LOGBLOADER" >> /export/jes/scripts/machines/$USEHOST
chmod 0666 /export/jes/scripts/machines/$USEHOST
delete_macro_after_timeout

Note: Our DHCP server runs on tgm (10.16.22.10), network is 10.16.22.0. The script was written for Solaris 9, for Solaris 10 or OpenSolaris use:

svcadm refresh dhcp-server && svcadm restart dhcp-server insted of /usr/bin/pkill -1 in.dhcpd

Note: We are using local IPS repositories (on lepra.czech) which are cloned from pkg team.

How it looks

1) Jumpstart SPARC machine

  • choose OpenSolaris
  • choose SPARC and image which you want install
  • choose machine (hostname or number, e.g. otava)

Information is displayed:

Choose host: otava

Host otava selected.
MAC: 00:03:ba:86:28:70
IP: 10.16.22.106
Deleting DHCP network table for otava
Creating DHCP network table for otava
Creating DHCP macro: 010003BA862870

Done! Please, reboot the machine otava with command "reboot net:dhcp"
(or press "Stop + a" on the machine otava and enter "boot net:dhcp")


2) Jumpstart x86 machine

  • choose OpenSolaris
  • choose x86 and image which you want install
  • choose machine (hostname or number, e.g. chomutov)
  • configure network boot
  • choose network boot loader
  • delete created macro in 5 minutes (avoid auto reinstall after reboot - when permanent boot form net is set in BIOS)

Information is displayed:

 Choose host: chomutov

Host chomutov selected.

Do you want to configure network boot?
1. Yes
2. No
if you're installing OpenSolaris, you must choose 1
Choose option [1]:

Select network boot loader:
1. PXE Grub (S10U1 and above)
2. Solaris Network Boot (S10 and below)
Choose network boot loader [1]:
MAC: 00:0a:5e:4c:f1:f9
IP: 10.16.22.208
Deleting DHCP network table for chomutov
Creating DHCP network table for chomutov

Macro 01000A5E4CF1F9 not yet defined.
Creating DHCP macro: 01000A5E4CF1F9

Done! Please, reboot the machine chomutov and boot it using PXE.
(Press F8 or F12 after reboot and select MBA UNDI as the boot device.)

Do you wish to delete created macro in 5 minutes? [yes]
   Yes - You have only 5 minutes to jumpstart selected PC
   No - You can jumpstart the PC without any time restriction
yes
Created macro will be deleted in 5 minutes

Watch jump in action


Changing default user

Sometimes we need to change the default user (jack) and root pasword (opensolaris).

It can be done by this script:

#include <stdio.h>
#include <stdlib.h>
#include <crypt.h>
#include <pwd.h>

int main( int argc, char\*\* argv ) {
	const char\* user = "jack";
	const char\* password = "mynewpassword";

	struct passwd\* user_passwd = getpwnam( user );
	if ( NULL == user_passwd ) {
		return EXIT_FAILURE;
	}

	char\* salt = crypt_gensalt( (const char\* ) "", user_passwd);

	if ( NULL == salt ) {
		return EXIT_FAILURE;
	}
	printf( "Salt is : %s\\n", salt);

	char\* shadow = crypt( password, salt );

	if ( NULL == shadow ) {
		return EXIT_FAILURE;
	}

	printf( "Shadow is : %s\\n", shadow);

	return EXIT_SUCCESS;
}

Note: You will need to have an entry in /etc/passwd for each user or role you want to create a password for (root should be there, but jack might not be)

How we are using AI directly in SWAN is coming in next blog.

Comments:

Generating an encrypted passwd for the manifest can be easier, with perl:

shadow=`perl -e 'print crypt("", "mynewpassword");'`
echo $shadow

Posted by Sean McGrath on March 09, 2009 at 09:38 AM CET #

Thank you for the comment. I'll try it.

Posted by Jan Hlodan on March 09, 2009 at 11:01 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Solaris l10n & i18n, locales, keyboards, fonts and related topics.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today