1 #! /usr/bin/sh
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License, Version 1.0 only
   7 # (the "License").  You may not use this file except in compliance
   8 # with the License.
   9 #
  10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  11 # or http://www.opensolaris.org/os/licensing.
  12 # See the License for the specific language governing permissions
  13 # and limitations under the License.
  14 #
  15 # When distributing Covered Code, include this CDDL HEADER in each
  16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  17 # If applicable, add the following below this CDDL HEADER, with the
  18 # fields enclosed by brackets "[]" replaced with your own identifying
  19 # information: Portions Copyright [yyyy] [name of copyright owner]
  20 #
  21 # CDDL HEADER END
  22 #
  23 #
  24 # ident "%Z%%M% %I%     %E% SMI"
  25 #
  26 # Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  27 # Use is subject to license terms.
  28 #
  29 # SVM Flash cleanup
  30 # Remove existing master SVM configuration on clone after full flash install.
  31 # Restore existing clone SVM configuation after differential flash install.
  32 #
  33 
  34 IN_SYS=${FLASH_ROOT}/etc/system
  35 IN_CONF=${FLASH_ROOT}/kernel/drv/md.conf
  36 IN_CF=${FLASH_ROOT}/etc/lvm/mddb.cf
  37 
  38 TMP_SYS=/var/tmp/system.1
  39 TMP_CONF=/var/tmp/md.conf.1
  40 TMP_CF=/var/tmp/mddb.cf.1
  41 
  42 # Directory where original clone config is saved.
  43 SAVE_DIR=${FLASH_DIR}/flash/svm
  44 
  45 if [ "${FLASH_TYPE}" = "FULL" ]; then
  46         # Full flash install, remove master's SVM configuration from clone.
  47 
  48         # Remove any SVM root entry from /etc/system file.
  49         nawk '
  50         BEGIN {delroot=0}
  51         /^\* Begin MDD root info \(do not edit\)$/ {delroot=1}
  52         /^\* End MDD root info \(do not edit\)$/ {delroot=0; next}
  53         {if (delroot == 0) print $0}
  54         ' ${IN_SYS} > ${TMP_SYS}
  55         cp ${TMP_SYS} ${IN_SYS}
  56 
  57         # Check if we are on the mini-root.  If we are, we need to clean up the
  58         # mddb configuration since this implies we are doing a full flash onto
  59         # a fresh system.
  60         #
  61         # If we are not on the mini-root that must mean we are installing
  62         # the full flash via live-upgrade.  In that case we share the
  63         # SVM configuration with the currently running system so we
  64         # need to copy the md.conf file from the current root onto the
  65         # newly installed root.  Note that the flash archive might not have
  66         # been created from the currently running system.
  67         if [ -h /kernel/drv/md.conf ]; then
  68                 # Remove SVM mddb entries from /kernel/drv/md.conf.
  69                 nawk '
  70                 BEGIN {delmddb=0}
  71                 /^# Begin MDD database info \(do not edit\)$/ {delmddb=1}
  72                 /^# End MDD database info \(do not edit\)$/ {delmddb=0; next}
  73                 {if (delmddb == 0) print $0}
  74                 ' ${IN_CONF} > ${TMP_CONF}
  75                 cp ${TMP_CONF} ${IN_CONF}
  76 
  77                 # Remove SVM mddb entries from /etc/lvm/mddb.cf.
  78                 nawk '
  79                 /^#/ {print $0}
  80                 ' ${IN_CF} > ${TMP_CF}
  81                 cp ${TMP_CF} ${IN_CF}
  82 
  83         else
  84                 # copy SVM config from current root to new root
  85                 cp /kernel/drv/md.conf ${IN_CONF}
  86                 cp /etc/lvm/mddb.cf ${IN_CF}
  87         fi
  88 
  89         # We may need to enable the SVM services in SMF.  This could happen
  90         # if we used jumpstart or live-upgrade to create SVM volumes as
  91         # part of the flash install.
  92         #
  93         # It doesn't matter if we are doing a flash install via a jumpstart
  94         # on the mini-root or via a live-upgrade.  In both cases we check
  95         # the md.conf on the currently running root to see if SVM is
  96         # configured.  For the jumpstart case it will have setup the
  97         # volumes already so the mini-root md.conf has the mddb info.  For
  98         # the live-upgade case both roots will be sharing the same md.conf
  99         # and have the same view of the SVM configuration.
 100         #
 101         # Check if there are mddb entries in md.conf to determine if SVM is
 102         # configured.
 103         sed -e 's/#.*$//' /kernel/drv/md.conf | \
 104             egrep '^[    ]*mddb_bootlist' >/dev/null 2>&1
 105         MDDB_STATUS=$?
 106 
 107         if [ $MDDB_STATUS -eq 0 ]; then
 108                 echo "/usr/sbin/svcadm enable system/metainit:default" >> \
 109                     ${FLASH_ROOT}/var/svc/profile/upgrade
 110 
 111                 echo "/usr/sbin/svcadm enable system/mdmonitor:default" >> \
 112                     ${FLASH_ROOT}/var/svc/profile/upgrade
 113 
 114                 echo "/usr/sbin/svcadm enable network/rpc/meta:default" >> \
 115                     ${FLASH_ROOT}/var/svc/profile/upgrade
 116         fi
 117 
 118 else
 119         # Differential flash install, restore clone SVM configuration.
 120         # The matrix of master/clone SVM config w/ diff. flash looks like:
 121         #
 122         # master    clone    clone after differential flash
 123         # 
 124         # yes        yes     same as clone prior to diff. flash
 125         # yes        no      no
 126         # no         yes     same as clone prior to diff. flash
 127         # no         no      no
 128         #
 129 
 130         # restore saved config files
 131         cp ${SAVE_DIR}/md.conf ${FLASH_ROOT}/kernel/drv/md.conf
 132         cp ${SAVE_DIR}/devpath ${FLASH_ROOT}/etc/lvm/devpath
 133         cp ${SAVE_DIR}/md.cf ${FLASH_ROOT}/etc/lvm/md.cf
 134         cp ${SAVE_DIR}/md.ctlrmap ${FLASH_ROOT}/etc/lvm/md.ctlrmap
 135         cp ${SAVE_DIR}/md.tab ${FLASH_ROOT}/etc/lvm/md.tab
 136         cp ${SAVE_DIR}/mddb.cf ${FLASH_ROOT}/etc/lvm/mddb.cf
 137         cp ${SAVE_DIR}/runtime.cf ${FLASH_ROOT}/etc/lvm/runtime.cf
 138 
 139         # Now process the various permutations for the master and clone
 140         # /etc/system file SVM root entries.
 141 
 142         # First check if we need to do anything with /etc/system.
 143         if `cmp -s ${SAVE_DIR}/system ${IN_SYS} >/dev/null 2>&1`; then
 144             # There is no difference so leave it alone.
 145             exit 0;
 146         fi
 147 
 148         # Get any SVM root entry from master /etc/system file.
 149         MASTER_ROOT=`nawk '
 150         BEGIN {inroot=0}
 151         /^\* Begin MDD root info \(do not edit\)$/ {inroot=1; next}
 152         /^\* End MDD root info \(do not edit\)$/ {inroot=0}
 153         {if (inroot == 1) print $0}
 154         ' ${IN_SYS}`
 155 
 156         # Get any SVM root entry from clone /etc/system file.
 157         CLONE_ROOT=`nawk '
 158         BEGIN {inroot=0}
 159         /^\* Begin MDD root info \(do not edit\)$/ {inroot=1; next}
 160         /^\* End MDD root info \(do not edit\)$/ {inroot=0}
 161         {if (inroot == 1) print $0}
 162         ' ${SAVE_DIR}/system`
 163 
 164         # If there is an SVM root entry in the master /etc/system file.
 165         if [ "${MASTER_ROOT}" ]; then
 166 
 167             # If there is an SVM root entry in the clone /etc/system file.
 168             if [ "${CLONE_ROOT}" ]; then
 169 
 170                 # Restore clone SVM root entry in /etc/system file.
 171                 nawk -v clone_root="${CLONE_ROOT}" '
 172                 BEGIN {newroot=0}
 173                 /^\* Begin MDD root info \(do not edit\)$/ {
 174                     newroot=1
 175                     print $0
 176                     print clone_root
 177                 }
 178                 /^\* End MDD root info \(do not edit\)$/ {newroot=0}
 179                 {if (newroot == 0) print $0}
 180                 ' ${IN_SYS} >${TMP_SYS}
 181                 cp ${TMP_SYS} ${IN_SYS}
 182 
 183             else
 184 
 185                 # There is no SVM root entry in the clone so remove the entry
 186                 # from the /etc/system file.
 187                 nawk '
 188                 BEGIN {delroot=0}
 189                 /^\* Begin MDD root info \(do not edit\)$/ {delroot=1}
 190                 /^\* End MDD root info \(do not edit\)$/ {delroot=0; next }
 191                 {if (delroot == 0) print $0}
 192                 ' ${IN_SYS} >${TMP_SYS}
 193                 cp ${TMP_SYS} ${IN_SYS}
 194 
 195             fi
 196 
 197         else
 198             # Master has no SVM root entry in the /etc/system file.
 199             if [ "${CLONE_ROOT}" ]; then
 200                 # But clone does have one so we need to add it back in.
 201 
 202                 echo "* Begin MDD root info (do not edit)" >> ${IN_SYS}
 203                 echo "${CLONE_ROOT}" >> ${IN_SYS}
 204                 echo "* End MDD root info (do not edit)" >> ${IN_SYS}
 205             fi
 206 
 207             # If neither master nor clone has SVM root entry then
 208             # we just leave the system file alone.
 209         fi
 210 fi
 211 
 212 exit 0