10Sstevel@tonic-gate#! /usr/bin/sh 20Sstevel@tonic-gate# 30Sstevel@tonic-gate# CDDL HEADER START 40Sstevel@tonic-gate# 50Sstevel@tonic-gate# The contents of this file are subject to the terms of the 60Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only 70Sstevel@tonic-gate# (the "License"). You may not use this file except in compliance 80Sstevel@tonic-gate# with the License. 90Sstevel@tonic-gate# 100Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 110Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 120Sstevel@tonic-gate# See the License for the specific language governing permissions 130Sstevel@tonic-gate# and limitations under the License. 140Sstevel@tonic-gate# 150Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 160Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 170Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 180Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 190Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 200Sstevel@tonic-gate# 210Sstevel@tonic-gate# CDDL HEADER END 220Sstevel@tonic-gate# 230Sstevel@tonic-gate# 240Sstevel@tonic-gate# ident "%Z%%M% %I% %E% SMI" 250Sstevel@tonic-gate# 26*113Sgjelinek# Copyright 2005 Sun Microsystems, Inc. All rights reserved. 270Sstevel@tonic-gate# Use is subject to license terms. 280Sstevel@tonic-gate# 290Sstevel@tonic-gate# SVM Flash cleanup 300Sstevel@tonic-gate# Remove existing master SVM configuration on clone after full flash install. 310Sstevel@tonic-gate# Restore existing clone SVM configuation after differential flash install. 320Sstevel@tonic-gate# 330Sstevel@tonic-gate 340Sstevel@tonic-gateIN_SYS=${FLASH_ROOT}/etc/system 350Sstevel@tonic-gateIN_CONF=${FLASH_ROOT}/kernel/drv/md.conf 360Sstevel@tonic-gateIN_CF=${FLASH_ROOT}/etc/lvm/mddb.cf 370Sstevel@tonic-gate 380Sstevel@tonic-gateTMP_SYS=/var/tmp/system.1 390Sstevel@tonic-gateTMP_CONF=/var/tmp/md.conf.1 400Sstevel@tonic-gateTMP_CF=/var/tmp/mddb.cf.1 410Sstevel@tonic-gate 420Sstevel@tonic-gate# Directory where original clone config is saved. 430Sstevel@tonic-gateSAVE_DIR=${FLASH_DIR}/flash/svm 440Sstevel@tonic-gate 450Sstevel@tonic-gateif [ "${FLASH_TYPE}" = "FULL" ]; then 460Sstevel@tonic-gate # Full flash install, remove master's SVM configuration from clone. 470Sstevel@tonic-gate 480Sstevel@tonic-gate # Remove any SVM root entry from /etc/system file. 490Sstevel@tonic-gate nawk ' 500Sstevel@tonic-gate BEGIN {delroot=0} 510Sstevel@tonic-gate /^\* Begin MDD root info \(do not edit\)$/ {delroot=1} 520Sstevel@tonic-gate /^\* End MDD root info \(do not edit\)$/ {delroot=0; next} 530Sstevel@tonic-gate {if (delroot == 0) print $0} 540Sstevel@tonic-gate ' ${IN_SYS} > ${TMP_SYS} 550Sstevel@tonic-gate cp ${TMP_SYS} ${IN_SYS} 560Sstevel@tonic-gate 57*113Sgjelinek # Check if we are on the mini-root. If we are, we need to clean up the 58*113Sgjelinek # mddb configuration since this implies we are doing a full flash onto 59*113Sgjelinek # a fresh system. 60*113Sgjelinek # 61*113Sgjelinek # If we are not on the mini-root that must mean we are installing 62*113Sgjelinek # the full flash via live-upgrade. In that case we share the 63*113Sgjelinek # SVM configuration with the currently running system so we 64*113Sgjelinek # need to copy the md.conf file from the current root onto the 65*113Sgjelinek # newly installed root. Note that the flash archive might not have 66*113Sgjelinek # been created from the currently running system. 67*113Sgjelinek if [ -h /kernel/drv/md.conf ]; then 68*113Sgjelinek # Remove SVM mddb entries from /kernel/drv/md.conf. 69*113Sgjelinek nawk ' 70*113Sgjelinek BEGIN {delmddb=0} 71*113Sgjelinek /^# Begin MDD database info \(do not edit\)$/ {delmddb=1} 72*113Sgjelinek /^# End MDD database info \(do not edit\)$/ {delmddb=0; next} 73*113Sgjelinek {if (delmddb == 0) print $0} 74*113Sgjelinek ' ${IN_CONF} > ${TMP_CONF} 75*113Sgjelinek cp ${TMP_CONF} ${IN_CONF} 76*113Sgjelinek 77*113Sgjelinek # Remove SVM mddb entries from /etc/lvm/mddb.cf. 78*113Sgjelinek nawk ' 79*113Sgjelinek /^#/ {print $0} 80*113Sgjelinek ' ${IN_CF} > ${TMP_CF} 81*113Sgjelinek cp ${TMP_CF} ${IN_CF} 820Sstevel@tonic-gate 83*113Sgjelinek else 84*113Sgjelinek # copy SVM config from current root to new root 85*113Sgjelinek cp /kernel/drv/md.conf ${IN_CONF} 86*113Sgjelinek cp /etc/lvm/mddb.cf ${IN_CF} 87*113Sgjelinek fi 88*113Sgjelinek 89*113Sgjelinek # We may need to enable the SVM services in SMF. This could happen 90*113Sgjelinek # if we used jumpstart or live-upgrade to create SVM volumes as 91*113Sgjelinek # part of the flash install. 92*113Sgjelinek # 93*113Sgjelinek # It doesn't matter if we are doing a flash install via a jumpstart 94*113Sgjelinek # on the mini-root or via a live-upgrade. In both cases we check 95*113Sgjelinek # the md.conf on the currently running root to see if SVM is 96*113Sgjelinek # configured. For the jumpstart case it will have setup the 97*113Sgjelinek # volumes already so the mini-root md.conf has the mddb info. For 98*113Sgjelinek # the live-upgade case both roots will be sharing the same md.conf 99*113Sgjelinek # and have the same view of the SVM configuration. 100*113Sgjelinek # 101*113Sgjelinek # Check if there are mddb entries in md.conf to determine if SVM is 102*113Sgjelinek # configured. 103*113Sgjelinek sed -e 's/#.*$//' /kernel/drv/md.conf | \ 104*113Sgjelinek egrep '^[ ]*mddb_bootlist' >/dev/null 2>&1 105*113Sgjelinek MDDB_STATUS=$? 106*113Sgjelinek 107*113Sgjelinek if [ $MDDB_STATUS -eq 0 ]; then 108*113Sgjelinek echo "/usr/sbin/svcadm enable system/metainit:default" >> \ 109*113Sgjelinek ${FLASH_ROOT}/var/svc/profile/upgrade 110*113Sgjelinek 111*113Sgjelinek echo "/usr/sbin/svcadm enable system/mdmonitor:default" >> \ 112*113Sgjelinek ${FLASH_ROOT}/var/svc/profile/upgrade 113*113Sgjelinek 114*113Sgjelinek echo "/usr/sbin/svcadm enable network/rpc/meta:default" >> \ 115*113Sgjelinek ${FLASH_ROOT}/var/svc/profile/upgrade 116*113Sgjelinek fi 1170Sstevel@tonic-gate 1180Sstevel@tonic-gateelse 1190Sstevel@tonic-gate # Differential flash install, restore clone SVM configuration. 1200Sstevel@tonic-gate # The matrix of master/clone SVM config w/ diff. flash looks like: 1210Sstevel@tonic-gate # 1220Sstevel@tonic-gate # master clone clone after differential flash 1230Sstevel@tonic-gate # 1240Sstevel@tonic-gate # yes yes same as clone prior to diff. flash 1250Sstevel@tonic-gate # yes no no 1260Sstevel@tonic-gate # no yes same as clone prior to diff. flash 1270Sstevel@tonic-gate # no no no 1280Sstevel@tonic-gate # 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate # restore saved config files 1310Sstevel@tonic-gate cp ${SAVE_DIR}/md.conf ${FLASH_ROOT}/kernel/drv/md.conf 1320Sstevel@tonic-gate cp ${SAVE_DIR}/devpath ${FLASH_ROOT}/etc/lvm/devpath 1330Sstevel@tonic-gate cp ${SAVE_DIR}/md.cf ${FLASH_ROOT}/etc/lvm/md.cf 1340Sstevel@tonic-gate cp ${SAVE_DIR}/md.ctlrmap ${FLASH_ROOT}/etc/lvm/md.ctlrmap 1350Sstevel@tonic-gate cp ${SAVE_DIR}/md.tab ${FLASH_ROOT}/etc/lvm/md.tab 1360Sstevel@tonic-gate cp ${SAVE_DIR}/mddb.cf ${FLASH_ROOT}/etc/lvm/mddb.cf 1370Sstevel@tonic-gate cp ${SAVE_DIR}/runtime.cf ${FLASH_ROOT}/etc/lvm/runtime.cf 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate # Now process the various permutations for the master and clone 1400Sstevel@tonic-gate # /etc/system file SVM root entries. 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate # First check if we need to do anything with /etc/system. 1430Sstevel@tonic-gate if `cmp -s ${SAVE_DIR}/system ${IN_SYS} >/dev/null 2>&1`; then 1440Sstevel@tonic-gate # There is no difference so leave it alone. 1450Sstevel@tonic-gate exit 0; 1460Sstevel@tonic-gate fi 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate # Get any SVM root entry from master /etc/system file. 1490Sstevel@tonic-gate MASTER_ROOT=`nawk ' 1500Sstevel@tonic-gate BEGIN {inroot=0} 1510Sstevel@tonic-gate /^\* Begin MDD root info \(do not edit\)$/ {inroot=1; next} 1520Sstevel@tonic-gate /^\* End MDD root info \(do not edit\)$/ {inroot=0} 1530Sstevel@tonic-gate {if (inroot == 1) print $0} 1540Sstevel@tonic-gate ' ${IN_SYS}` 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate # Get any SVM root entry from clone /etc/system file. 1570Sstevel@tonic-gate CLONE_ROOT=`nawk ' 1580Sstevel@tonic-gate BEGIN {inroot=0} 1590Sstevel@tonic-gate /^\* Begin MDD root info \(do not edit\)$/ {inroot=1; next} 1600Sstevel@tonic-gate /^\* End MDD root info \(do not edit\)$/ {inroot=0} 1610Sstevel@tonic-gate {if (inroot == 1) print $0} 1620Sstevel@tonic-gate ' ${SAVE_DIR}/system` 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate # If there is an SVM root entry in the master /etc/system file. 1650Sstevel@tonic-gate if [ "${MASTER_ROOT}" ]; then 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate # If there is an SVM root entry in the clone /etc/system file. 1680Sstevel@tonic-gate if [ "${CLONE_ROOT}" ]; then 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate # Restore clone SVM root entry in /etc/system file. 1710Sstevel@tonic-gate nawk -v clone_root="${CLONE_ROOT}" ' 1720Sstevel@tonic-gate BEGIN {newroot=0} 1730Sstevel@tonic-gate /^\* Begin MDD root info \(do not edit\)$/ { 1740Sstevel@tonic-gate newroot=1 1750Sstevel@tonic-gate print $0 1760Sstevel@tonic-gate print clone_root 1770Sstevel@tonic-gate } 1780Sstevel@tonic-gate /^\* End MDD root info \(do not edit\)$/ {newroot=0} 1790Sstevel@tonic-gate {if (newroot == 0) print $0} 1800Sstevel@tonic-gate ' ${IN_SYS} >${TMP_SYS} 1810Sstevel@tonic-gate cp ${TMP_SYS} ${IN_SYS} 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate else 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate # There is no SVM root entry in the clone so remove the entry 1860Sstevel@tonic-gate # from the /etc/system file. 1870Sstevel@tonic-gate nawk ' 1880Sstevel@tonic-gate BEGIN {delroot=0} 1890Sstevel@tonic-gate /^\* Begin MDD root info \(do not edit\)$/ {delroot=1} 1900Sstevel@tonic-gate /^\* End MDD root info \(do not edit\)$/ {delroot=0; next } 1910Sstevel@tonic-gate {if (delroot == 0) print $0} 1920Sstevel@tonic-gate ' ${IN_SYS} >${TMP_SYS} 1930Sstevel@tonic-gate cp ${TMP_SYS} ${IN_SYS} 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate fi 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate else 1980Sstevel@tonic-gate # Master has no SVM root entry in the /etc/system file. 1990Sstevel@tonic-gate if [ "${CLONE_ROOT}" ]; then 2000Sstevel@tonic-gate # But clone does have one so we need to add it back in. 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate echo "* Begin MDD root info (do not edit)" >> ${IN_SYS} 2030Sstevel@tonic-gate echo "${CLONE_ROOT}" >> ${IN_SYS} 2040Sstevel@tonic-gate echo "* End MDD root info (do not edit)" >> ${IN_SYS} 2050Sstevel@tonic-gate fi 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate # If neither master nor clone has SVM root entry then 2080Sstevel@tonic-gate # we just leave the system file alone. 2090Sstevel@tonic-gate fi 2100Sstevel@tonic-gatefi 2110Sstevel@tonic-gate 2120Sstevel@tonic-gateexit 0 213