1*7c478bd9Sstevel@tonic-gate#!/sbin/sh 2*7c478bd9Sstevel@tonic-gate# 3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START 4*7c478bd9Sstevel@tonic-gate# 5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only 7*7c478bd9Sstevel@tonic-gate# (the "License"). You may not use this file except in compliance 8*7c478bd9Sstevel@tonic-gate# with the License. 9*7c478bd9Sstevel@tonic-gate# 10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 13*7c478bd9Sstevel@tonic-gate# and limitations under the License. 14*7c478bd9Sstevel@tonic-gate# 15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 20*7c478bd9Sstevel@tonic-gate# 21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END 22*7c478bd9Sstevel@tonic-gate# 23*7c478bd9Sstevel@tonic-gate# 24*7c478bd9Sstevel@tonic-gate# Copyright 2004 Sun Microsystems, Inc. All rights reserved. 25*7c478bd9Sstevel@tonic-gate# Use is subject to license terms. 26*7c478bd9Sstevel@tonic-gate# 27*7c478bd9Sstevel@tonic-gate#ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate. /lib/svc/share/fs_include.sh 30*7c478bd9Sstevel@tonic-gate. /lib/svc/share/net_include.sh 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate# Make sure that the essential libraries can be found. 33*7c478bd9Sstevel@tonic-gateLD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH 34*7c478bd9Sstevel@tonic-gateSTMSBOOTUTIL=/lib/mpxio/stmsboot_util 35*7c478bd9Sstevel@tonic-gateFPCONF=/kernel/drv/fp.conf 36*7c478bd9Sstevel@tonic-gateSAVEDIR=/etc/mpxio 37*7c478bd9Sstevel@tonic-gateRECOVERFILE=$SAVEDIR/recover_instructions 38*7c478bd9Sstevel@tonic-gateDEVFSADM=/usr/sbin/devfsadm 39*7c478bd9Sstevel@tonic-gateMETADEVADM=/usr/sbin/metadevadm 40*7c478bd9Sstevel@tonic-gateusrmounted=0 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate# map $special and $fsckdev 43*7c478bd9Sstevel@tonic-gatempxio_mapdev() 44*7c478bd9Sstevel@tonic-gate{ 45*7c478bd9Sstevel@tonic-gate new_special=`$STMSBOOTUTIL -m $special` 46*7c478bd9Sstevel@tonic-gate if [ $? -eq 0 ]; then 47*7c478bd9Sstevel@tonic-gate special=$new_special 48*7c478bd9Sstevel@tonic-gate fi 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate new_fsckdev=`$STMSBOOTUTIL -m $fsckdev` 51*7c478bd9Sstevel@tonic-gate if [ $? -eq 0 ]; then 52*7c478bd9Sstevel@tonic-gate fsckdev=$new_fsckdev 53*7c478bd9Sstevel@tonic-gate fi 54*7c478bd9Sstevel@tonic-gate} 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gatempxio_error() 57*7c478bd9Sstevel@tonic-gate{ 58*7c478bd9Sstevel@tonic-gate cecho "\nERROR: stmsboot: $1" 59*7c478bd9Sstevel@tonic-gate # 60*7c478bd9Sstevel@tonic-gate # display recovery instructions - the first call logs to the service 61*7c478bd9Sstevel@tonic-gate # log and the second call displays on the console. 62*7c478bd9Sstevel@tonic-gate # 63*7c478bd9Sstevel@tonic-gate shcat $RECOVERFILE 64*7c478bd9Sstevel@tonic-gate shcat $RECOVERFILE >/dev/msglog 2>&1 65*7c478bd9Sstevel@tonic-gate cecho "These instructions were also logged to the file $RECOVERFILE\n" 66*7c478bd9Sstevel@tonic-gate} 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate# 69*7c478bd9Sstevel@tonic-gate# root ("/") is already mounted read only by the kernel. 70*7c478bd9Sstevel@tonic-gate# Remount the root read-write. 71*7c478bd9Sstevel@tonic-gate# 72*7c478bd9Sstevel@tonic-gatempxio_mount_root() 73*7c478bd9Sstevel@tonic-gate{ 74*7c478bd9Sstevel@tonic-gate exec < $vfstab; readvfstab / 75*7c478bd9Sstevel@tonic-gate mpxio_mapdev 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate checkopt "llock" $mntopts 78*7c478bd9Sstevel@tonic-gate mntopts='remount' 79*7c478bd9Sstevel@tonic-gate [ -n "$otherops" ] && mntopts="${mntopts},${otherops}" 80*7c478bd9Sstevel@tonic-gate /sbin/mount -m -F $fstype -o $mntopts $special $mountp \ 81*7c478bd9Sstevel@tonic-gate>/dev/msglog 2>&1 82*7c478bd9Sstevel@tonic-gate} 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate# 85*7c478bd9Sstevel@tonic-gate# mount /usr read only 86*7c478bd9Sstevel@tonic-gate# 87*7c478bd9Sstevel@tonic-gatempxio_mount_usr() 88*7c478bd9Sstevel@tonic-gate{ 89*7c478bd9Sstevel@tonic-gate exec < $vfstab; readvfstab "/usr" 90*7c478bd9Sstevel@tonic-gate ret_val=0 91*7c478bd9Sstevel@tonic-gate if [ -n "$mountp" ]; then 92*7c478bd9Sstevel@tonic-gate mpxio_mapdev 93*7c478bd9Sstevel@tonic-gate if [ "$fstype" = cachefs ]; then 94*7c478bd9Sstevel@tonic-gate # Mount read-only without the cache. 95*7c478bd9Sstevel@tonic-gate case "$mntopts" in 96*7c478bd9Sstevel@tonic-gate *backfstype=nfs*) 97*7c478bd9Sstevel@tonic-gate cfsbacktype=nfs 98*7c478bd9Sstevel@tonic-gate ;; 99*7c478bd9Sstevel@tonic-gate *backfstype=hsfs*) 100*7c478bd9Sstevel@tonic-gate cfsbacktype=hsfs 101*7c478bd9Sstevel@tonic-gate ;; 102*7c478bd9Sstevel@tonic-gate *) 103*7c478bd9Sstevel@tonic-gate cecho 'stmsboot: invalid vfstab entry for /usr' 104*7c478bd9Sstevel@tonic-gate cfsbacktype=nfs 105*7c478bd9Sstevel@tonic-gate ;; 106*7c478bd9Sstevel@tonic-gate esac 107*7c478bd9Sstevel@tonic-gate # see the comment below for /dev/null 108*7c478bd9Sstevel@tonic-gate /sbin/mount -m -F $cfsbacktype -o ro $special $mountp \ 109*7c478bd9Sstevel@tonic-gate>/dev/null 2>&1 110*7c478bd9Sstevel@tonic-gate ret_val=$? 111*7c478bd9Sstevel@tonic-gate else 112*7c478bd9Sstevel@tonic-gate # 113*7c478bd9Sstevel@tonic-gate # Must use -o largefiles here to ensure the read-only 114*7c478bd9Sstevel@tonic-gate # mount does not fail as a result of having a large 115*7c478bd9Sstevel@tonic-gate # file present on /usr. 116*7c478bd9Sstevel@tonic-gate # 117*7c478bd9Sstevel@tonic-gate if [ "x$mntopts" = x- ]; then 118*7c478bd9Sstevel@tonic-gate mntopts='ro,largefiles' 119*7c478bd9Sstevel@tonic-gate else 120*7c478bd9Sstevel@tonic-gate checkopt largefiles $mntopts 121*7c478bd9Sstevel@tonic-gate if [ "x$option" != xlargefiles ]; then 122*7c478bd9Sstevel@tonic-gate mntopts="largefiles,$mntopts" 123*7c478bd9Sstevel@tonic-gate fi 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate checkopt ro $mntopts 126*7c478bd9Sstevel@tonic-gate if [ "x$option" != xro ]; then 127*7c478bd9Sstevel@tonic-gate mntopts="ro,$mntopts" 128*7c478bd9Sstevel@tonic-gate fi 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate # 131*7c478bd9Sstevel@tonic-gate # Requesting logging on a read-only mount 132*7c478bd9Sstevel@tonic-gate # causes errors to be displayed, so remove 133*7c478bd9Sstevel@tonic-gate # "logging" from the list of options. 134*7c478bd9Sstevel@tonic-gate # 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate checkopt logging $mntopts 137*7c478bd9Sstevel@tonic-gate if [ "x$option" = xlogging ]; then 138*7c478bd9Sstevel@tonic-gate mntopts="$otherops" 139*7c478bd9Sstevel@tonic-gate fi 140*7c478bd9Sstevel@tonic-gate fi 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate # 143*7c478bd9Sstevel@tonic-gate # In case of a manual restart of the service, mount 144*7c478bd9Sstevel@tonic-gate # will emit messages if /usr is already mounted. 145*7c478bd9Sstevel@tonic-gate # So redirect the output to /dev/null. 146*7c478bd9Sstevel@tonic-gate # 147*7c478bd9Sstevel@tonic-gate /sbin/mount -m -F $fstype -o $mntopts $special /usr \ 148*7c478bd9Sstevel@tonic-gate>/dev/null 2>&1 149*7c478bd9Sstevel@tonic-gate ret_val=$? 150*7c478bd9Sstevel@tonic-gate fi 151*7c478bd9Sstevel@tonic-gate if [ $ret_val -eq 0 ]; then 152*7c478bd9Sstevel@tonic-gate usrmounted=1 153*7c478bd9Sstevel@tonic-gate fi 154*7c478bd9Sstevel@tonic-gate fi 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate return $ret_val 157*7c478bd9Sstevel@tonic-gate} 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate# update system dump configuration 160*7c478bd9Sstevel@tonic-gateupdate_dumpconf() 161*7c478bd9Sstevel@tonic-gate{ 162*7c478bd9Sstevel@tonic-gate set -- `dumpadm -u 2>&1 | egrep 'cannot use /dev.* as dump device'` 163*7c478bd9Sstevel@tonic-gate if [ "x$4" != x ]; then 164*7c478bd9Sstevel@tonic-gate newname=`$STMSBOOTUTIL -M $4` 165*7c478bd9Sstevel@tonic-gate if [ $? -eq 0 ]; then 166*7c478bd9Sstevel@tonic-gate if dumpadm -d $newname > /dev/null; then 167*7c478bd9Sstevel@tonic-gate cecho "stmsboot: dump configuration has been \ 168*7c478bd9Sstevel@tonic-gateupdated." 169*7c478bd9Sstevel@tonic-gate else 170*7c478bd9Sstevel@tonic-gate mpxio_error "failed to configure $newname as \ 171*7c478bd9Sstevel@tonic-gatethe dump device.\nold dump device name: $4" 172*7c478bd9Sstevel@tonic-gate return 1 173*7c478bd9Sstevel@tonic-gate fi 174*7c478bd9Sstevel@tonic-gate fi 175*7c478bd9Sstevel@tonic-gate fi 176*7c478bd9Sstevel@tonic-gate return 0 177*7c478bd9Sstevel@tonic-gate} 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate# 180*7c478bd9Sstevel@tonic-gate# do the actual work 181*7c478bd9Sstevel@tonic-gate# 182*7c478bd9Sstevel@tonic-gatempxio_main() 183*7c478bd9Sstevel@tonic-gate{ 184*7c478bd9Sstevel@tonic-gate # 185*7c478bd9Sstevel@tonic-gate # NOTE: If the first attempt to run the service has failed due to an 186*7c478bd9Sstevel@tonic-gate # expected error, users should be able to manually rerun the service. 187*7c478bd9Sstevel@tonic-gate # 188*7c478bd9Sstevel@tonic-gate # First mount /usr read only. This must be done to run 189*7c478bd9Sstevel@tonic-gate # utilities such as fsck and devfsadm. 190*7c478bd9Sstevel@tonic-gate # In the case of a manual rerun of the service, mounting of /usr here 191*7c478bd9Sstevel@tonic-gate # fails if /usr already happens to be mounted. It is better that we 192*7c478bd9Sstevel@tonic-gate # do not mount /usr if already mounted, but there seems to be no 193*7c478bd9Sstevel@tonic-gate # apparent way to check whether /usr is mounted or not as we mount 194*7c478bd9Sstevel@tonic-gate # /usr without making an entry into /etc/mnttab. So instead of 195*7c478bd9Sstevel@tonic-gate # explicitly checking for mount failures, we just do a sanity check 196*7c478bd9Sstevel@tonic-gate # by looking for some file (in this case devfsadm) in /usr. 197*7c478bd9Sstevel@tonic-gate # 198*7c478bd9Sstevel@tonic-gate mpxio_mount_usr 199*7c478bd9Sstevel@tonic-gate if [ ! -s $DEVFSADM ]; then 200*7c478bd9Sstevel@tonic-gate mpxio_error "failed to mount the /usr filesystem." 201*7c478bd9Sstevel@tonic-gate return 202*7c478bd9Sstevel@tonic-gate fi 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate if mpxio_mount_root; then 205*7c478bd9Sstevel@tonic-gate # create /dev links 206*7c478bd9Sstevel@tonic-gate cecho "stmsboot: configuring devices" 207*7c478bd9Sstevel@tonic-gate $DEVFSADM 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate # update /etc/vfstab to reflect device name changes 210*7c478bd9Sstevel@tonic-gate if $STMSBOOTUTIL -u >/dev/msglog 2>&1; then 211*7c478bd9Sstevel@tonic-gate if update_dumpconf; then 212*7c478bd9Sstevel@tonic-gate # update svm configuration to reflect new names 213*7c478bd9Sstevel@tonic-gate if [ -s /kernel/drv/md.conf ] && \ 214*7c478bd9Sstevel@tonic-gate [ -x $METADEVADM ]; then 215*7c478bd9Sstevel@tonic-gate $METADEVADM -r >/dev/msglog 2>&1 216*7c478bd9Sstevel@tonic-gate fi 217*7c478bd9Sstevel@tonic-gate fi 218*7c478bd9Sstevel@tonic-gate else 219*7c478bd9Sstevel@tonic-gate mpxio_error "failed to update /etc/vfstab." 220*7c478bd9Sstevel@tonic-gate fi 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate /usr/sbin/svcadm disable platform/sun4u/mpxio-upgrade 223*7c478bd9Sstevel@tonic-gate 224*7c478bd9Sstevel@tonic-gate /usr/sbin/reboot 225*7c478bd9Sstevel@tonic-gate else 226*7c478bd9Sstevel@tonic-gate mpxio_error "failed to mount the root filesystem." 227*7c478bd9Sstevel@tonic-gate if [ $usrmounted -eq 1 ]; then 228*7c478bd9Sstevel@tonic-gate /sbin/umount /usr 229*7c478bd9Sstevel@tonic-gate fi 230*7c478bd9Sstevel@tonic-gate fi 231*7c478bd9Sstevel@tonic-gate} 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gatempxio_main 234