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