17c478bd9Sstevel@tonic-gate#!/sbin/sh 27c478bd9Sstevel@tonic-gate# 37c478bd9Sstevel@tonic-gate# CDDL HEADER START 47c478bd9Sstevel@tonic-gate# 57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 604cbdd1eSramat# Common Development and Distribution License (the "License"). 704cbdd1eSramat# You may not use this file except in compliance with the License. 87c478bd9Sstevel@tonic-gate# 97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate# and limitations under the License. 137c478bd9Sstevel@tonic-gate# 147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate# 207c478bd9Sstevel@tonic-gate# CDDL HEADER END 217c478bd9Sstevel@tonic-gate# 227c478bd9Sstevel@tonic-gate# 23*a0261a43SJames C. McPherson# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate# Use is subject to license terms. 257c478bd9Sstevel@tonic-gate# 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate. /lib/svc/share/fs_include.sh 287c478bd9Sstevel@tonic-gate. /lib/svc/share/net_include.sh 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate# Make sure that the essential libraries can be found. 317c478bd9Sstevel@tonic-gateLD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH 327c478bd9Sstevel@tonic-gateSTMSBOOTUTIL=/lib/mpxio/stmsboot_util 337c478bd9Sstevel@tonic-gateSAVEDIR=/etc/mpxio 347c478bd9Sstevel@tonic-gateRECOVERFILE=$SAVEDIR/recover_instructions 357c478bd9Sstevel@tonic-gateDEVFSADM=/usr/sbin/devfsadm 36*a0261a43SJames C. McPhersonDUMPADM=/usr/sbin/dumpadm 377c478bd9Sstevel@tonic-gateMETADEVADM=/usr/sbin/metadevadm 387c478bd9Sstevel@tonic-gateusrmounted=0 395a4c37c9Sqh201292MACH=`/usr/bin/uname -p` 40*a0261a43SJames C. McPhersonCP=/usr/bin/cp 41*a0261a43SJames C. McPhersonDF=/usr/bin/df 42*a0261a43SJames C. McPhersonLS=/usr/bin/ls 43*a0261a43SJames C. McPhersonRM=/usr/bin/rm 4460fffc19Sjw149990EGREP=/usr/bin/egrep 45c17d6d03SjmcpSED=/usr/bin/sed 46*a0261a43SJames C. McPhersonZPOOL=/usr/sbin/zpool 47*a0261a43SJames C. McPhersonAWK=/usr/bin/awk 48*a0261a43SJames C. McPhersonMOUNT=/sbin/mount 49*a0261a43SJames C. McPhersonUMOUNT=/sbin/mount 50*a0261a43SJames C. McPhersonEEPROM=/usr/sbin/eeprom 51*a0261a43SJames C. McPhersonBOOTADM=/usr/sbin/bootadm 52*a0261a43SJames C. McPhersonSVCADM=/usr/sbin/svcadm 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gatempxio_error() 557c478bd9Sstevel@tonic-gate{ 567c478bd9Sstevel@tonic-gate cecho "\nERROR: stmsboot: $1" 577c478bd9Sstevel@tonic-gate # 587c478bd9Sstevel@tonic-gate # display recovery instructions - the first call logs to the service 597c478bd9Sstevel@tonic-gate # log and the second call displays on the console. 607c478bd9Sstevel@tonic-gate # 617c478bd9Sstevel@tonic-gate shcat $RECOVERFILE 627c478bd9Sstevel@tonic-gate shcat $RECOVERFILE >/dev/msglog 2>&1 637c478bd9Sstevel@tonic-gate cecho "These instructions were also logged to the file $RECOVERFILE\n" 647c478bd9Sstevel@tonic-gate} 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate# 677c478bd9Sstevel@tonic-gate# root ("/") is already mounted read only by the kernel. 687c478bd9Sstevel@tonic-gate# Remount the root read-write. 697c478bd9Sstevel@tonic-gate# 707c478bd9Sstevel@tonic-gatempxio_mount_root() 717c478bd9Sstevel@tonic-gate{ 72*a0261a43SJames C. McPherson HASZFSROOT=`$DF -g / |grep zfs` 737c478bd9Sstevel@tonic-gate 74*a0261a43SJames C. McPherson # In single-user maintenance mode, we don't have a writable 75*a0261a43SJames C. McPherson # root partition, so we _cannot_ use devlinks. Therefore we 76*a0261a43SJames C. McPherson # have to do some dancing - first mount the physical path 77*a0261a43SJames C. McPherson # read-write, then re-run $STMSBOOTUTIL to get the real 78*a0261a43SJames C. McPherson # devlink mapping, and then re-mount the root slice. Of course, 79*a0261a43SJames C. McPherson # if we all used ZFS this wouldn't be such a pain! 80*a0261a43SJames C. McPherson exec < $vfstab; readvfstab / 81*a0261a43SJames C. McPherson # ZFS root environments should _not_ have an entry for / 82*a0261a43SJames C. McPherson # in their /etc/vfstab. 83*a0261a43SJames C. McPherson if [ "x$special" != "x" ]; then 84*a0261a43SJames C. McPherson # sanity check for ZFSRoot _and_ / in /etc/vfstab 85*a0261a43SJames C. McPherson if [ "x$HASZFSROOT" != "x" ]; then 86*a0261a43SJames C. McPherson # ERROR - this would cause a failure later 87*a0261a43SJames C. McPherson # so let root know about it now and provide 88*a0261a43SJames C. McPherson # a chance to handle it before filesystem/usr 89*a0261a43SJames C. McPherson cecho "stmsboot: System has ZFS Root *and* an entry for / in /etc/vfstab\nstmsboot: Please remove the / entry from /etc/vfstab and then run\n# svcadm clear mpxio-upgrade" 90*a0261a43SJames C. McPherson exit 1 91*a0261a43SJames C. McPherson fi 92*a0261a43SJames C. McPherson ISPHYS=`echo $special |$AWK '/^\/dev\/dsk/ {print}'`; 93*a0261a43SJames C. McPherson if [ "x$ISPHYS" != "x" ]; then 94*a0261a43SJames C. McPherson new_special=`$STMSBOOTUTIL -m $special` 95*a0261a43SJames C. McPherson if [ "x$new_special" = "xNOT_MAPPED" ]; then 96*a0261a43SJames C. McPherson # this is a bad state to be in, exit 97*a0261a43SJames C. McPherson cecho "Error: Your root device is not mapped." 98*a0261a43SJames C. McPherson exit 1 99*a0261a43SJames C. McPherson fi 1007c478bd9Sstevel@tonic-gate checkopt "llock" $mntopts 1017c478bd9Sstevel@tonic-gate mntopts='remount' 1027c478bd9Sstevel@tonic-gate [ -n "$otherops" ] && mntopts="${mntopts},${otherops}" 103*a0261a43SJames C. McPherson $MOUNT -m -F $fstype -o $mntopts $new_special \ 104*a0261a43SJames C. McPherson $mountp >/dev/msglog 2>&1 105*a0261a43SJames C. McPherson 106*a0261a43SJames C. McPherson # now re-run $STMSBOOTUTIL to get the real mapping 107*a0261a43SJames C. McPherson new_special=`$STMSBOOTUTIL -m $special` 108*a0261a43SJames C. McPherson else 109*a0261a43SJames C. McPherson # a metadevice, either /dev/md or /dev/vx 110*a0261a43SJames C. McPherson new_special=$special 111*a0261a43SJames C. McPherson fi 112*a0261a43SJames C. McPherson # mount root for real 113*a0261a43SJames C. McPherson $MOUNT -o remount,rw $new_special / >/dev/msglog 2>&1 114*a0261a43SJames C. McPherson else 115*a0261a43SJames C. McPherson if [ "x$HASZFSROOT" = "x" ]; then 116*a0261a43SJames C. McPherson cecho "stmsboot: Error: your root slice is invalid" 117*a0261a43SJames C. McPherson exit 1 118*a0261a43SJames C. McPherson else 119*a0261a43SJames C. McPherson cecho "stmsboot: Root is on ZFS" 120*a0261a43SJames C. McPherson fi 121*a0261a43SJames C. McPherson fi 1227c478bd9Sstevel@tonic-gate} 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate# 1257c478bd9Sstevel@tonic-gate# mount /usr read only 1267c478bd9Sstevel@tonic-gate# 1277c478bd9Sstevel@tonic-gatempxio_mount_usr() 1287c478bd9Sstevel@tonic-gate{ 1297c478bd9Sstevel@tonic-gate exec < $vfstab; readvfstab "/usr" 1307c478bd9Sstevel@tonic-gate ret_val=0 1317c478bd9Sstevel@tonic-gate if [ -n "$mountp" ]; then 132*a0261a43SJames C. McPherson new_special=`$STMSBOOTUTIL -m $special` 133*a0261a43SJames C. McPherson 1347c478bd9Sstevel@tonic-gate if [ "$fstype" = cachefs ]; then 1357c478bd9Sstevel@tonic-gate # Mount read-only without the cache. 1367c478bd9Sstevel@tonic-gate case "$mntopts" in 1377c478bd9Sstevel@tonic-gate *backfstype=nfs*) 1387c478bd9Sstevel@tonic-gate cfsbacktype=nfs 1397c478bd9Sstevel@tonic-gate ;; 1407c478bd9Sstevel@tonic-gate *backfstype=hsfs*) 1417c478bd9Sstevel@tonic-gate cfsbacktype=hsfs 1427c478bd9Sstevel@tonic-gate ;; 1437c478bd9Sstevel@tonic-gate *) 1447c478bd9Sstevel@tonic-gate cecho 'stmsboot: invalid vfstab entry for /usr' 1457c478bd9Sstevel@tonic-gate cfsbacktype=nfs 1467c478bd9Sstevel@tonic-gate ;; 1477c478bd9Sstevel@tonic-gate esac 1487c478bd9Sstevel@tonic-gate # see the comment below for /dev/null 149*a0261a43SJames C. McPherson $MOUNT -m -F $cfsbacktype -o ro $new_special $mountp \ 1507c478bd9Sstevel@tonic-gate>/dev/null 2>&1 1517c478bd9Sstevel@tonic-gate ret_val=$? 1527c478bd9Sstevel@tonic-gate else 1537c478bd9Sstevel@tonic-gate # 1547c478bd9Sstevel@tonic-gate # Must use -o largefiles here to ensure the read-only 1557c478bd9Sstevel@tonic-gate # mount does not fail as a result of having a large 1567c478bd9Sstevel@tonic-gate # file present on /usr. 1577c478bd9Sstevel@tonic-gate # 1587c478bd9Sstevel@tonic-gate if [ "x$mntopts" = x- ]; then 1597c478bd9Sstevel@tonic-gate mntopts='ro,largefiles' 1607c478bd9Sstevel@tonic-gate else 1617c478bd9Sstevel@tonic-gate checkopt largefiles $mntopts 1627c478bd9Sstevel@tonic-gate if [ "x$option" != xlargefiles ]; then 1637c478bd9Sstevel@tonic-gate mntopts="largefiles,$mntopts" 1647c478bd9Sstevel@tonic-gate fi 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate checkopt ro $mntopts 1677c478bd9Sstevel@tonic-gate if [ "x$option" != xro ]; then 1687c478bd9Sstevel@tonic-gate mntopts="ro,$mntopts" 1697c478bd9Sstevel@tonic-gate fi 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate # Requesting logging on a read-only mount 1727c478bd9Sstevel@tonic-gate # causes errors to be displayed, so remove 1737c478bd9Sstevel@tonic-gate # "logging" from the list of options. 1747c478bd9Sstevel@tonic-gate checkopt logging $mntopts 1757c478bd9Sstevel@tonic-gate if [ "x$option" = xlogging ]; then 1767c478bd9Sstevel@tonic-gate mntopts="$otherops" 1777c478bd9Sstevel@tonic-gate fi 1787c478bd9Sstevel@tonic-gate fi 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate # In case of a manual restart of the service, mount 1817c478bd9Sstevel@tonic-gate # will emit messages if /usr is already mounted. 1827c478bd9Sstevel@tonic-gate # So redirect the output to /dev/null. 183*a0261a43SJames C. McPherson $MOUNT -m -F $fstype -o $mntopts $new_special /usr \ 1847c478bd9Sstevel@tonic-gate>/dev/null 2>&1 1857c478bd9Sstevel@tonic-gate ret_val=$? 1867c478bd9Sstevel@tonic-gate fi 1877c478bd9Sstevel@tonic-gate if [ $ret_val -eq 0 ]; then 1887c478bd9Sstevel@tonic-gate usrmounted=1 1897c478bd9Sstevel@tonic-gate fi 1907c478bd9Sstevel@tonic-gate fi 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate return $ret_val 1937c478bd9Sstevel@tonic-gate} 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate# update system dump configuration 1967c478bd9Sstevel@tonic-gateupdate_dumpconf() 1977c478bd9Sstevel@tonic-gate{ 19804cbdd1eSramat # Disable device-in-use checking (done in libdiskmgt). 19904cbdd1eSramat # Without disabling this check, the configuration of dump device 20004cbdd1eSramat # would fail as the device-in-use code incorrectly concludes that 20104cbdd1eSramat # the device is in use and hence prevents configuration of the dump 20204cbdd1eSramat # device. 20304cbdd1eSramat NOINUSE_CHECK=1 20404cbdd1eSramat export NOINUSE_CHECK 20504cbdd1eSramat 206*a0261a43SJames C. McPherson DUMPISZFS=`$AWK -F"=" '/DUMPADM_DEVICE/ {print $2}' /etc/dumpadm.conf|$EGREP zvol` 207*a0261a43SJames C. McPherson if [ "x$DUMPISZFS" = "x" ]; then 208*a0261a43SJames C. McPherson set -- `$DUMPADM -u 2>&1 | $EGREP 'cannot use /dev.* as dump device'` 2097c478bd9Sstevel@tonic-gate if [ "x$4" != x ]; then 210*a0261a43SJames C. McPherson newname=`$STMSBOOTUTIL -m $4` 2117c478bd9Sstevel@tonic-gate if [ $? -eq 0 ]; then 212*a0261a43SJames C. McPherson if $DUMPADM -d $newname > /dev/msglog 2> /dev/console; then 213*a0261a43SJames C. McPherson cecho "stmsboot: dump configuration \ 214*a0261a43SJames C. McPherson has been updated." 2157c478bd9Sstevel@tonic-gate else 216*a0261a43SJames C. McPherson mpxio_error "failed to configure \ 217*a0261a43SJames C. McPherson the dump device.\nold \ 218*a0261a43SJames C. McPherson dump device name: $4" 2197c478bd9Sstevel@tonic-gate return 1 2207c478bd9Sstevel@tonic-gate fi 2217c478bd9Sstevel@tonic-gate fi 2227c478bd9Sstevel@tonic-gate fi 223*a0261a43SJames C. McPherson else 224*a0261a43SJames C. McPherson # make sure we can get to it, force zfs to load fully 225*a0261a43SJames C. McPherson $LS $DUMPISZFS >>/dev/null 2>&1 226*a0261a43SJames C. McPherson cecho "stmsboot: dump on ZFS, no dumpadm update required" 227*a0261a43SJames C. McPherson fi 2287c478bd9Sstevel@tonic-gate return 0 2297c478bd9Sstevel@tonic-gate} 2307c478bd9Sstevel@tonic-gate 2315a4c37c9Sqh201292# Update bootpath for x86 here when we are enabling mpxio on root 2325a4c37c9Sqh201292update_bootpath() 2335a4c37c9Sqh201292{ 234*a0261a43SJames C. McPherson cur_bootpath=`$STMSBOOTUTIL -b` 235*a0261a43SJames C. McPherson if [ $? != 0 ]; then 236*a0261a43SJames C. McPherson cecho "stmsboot: ERROR! Unable to retrieve bootpath property\n" 237*a0261a43SJames C. McPherson exit 1 238*a0261a43SJames C. McPherson fi 2395a4c37c9Sqh201292 240*a0261a43SJames C. McPherson NEWBOOTPATH="" 241*a0261a43SJames C. McPherson for path in $cur_bootpath; do 242*a0261a43SJames C. McPherson mapped=`$STMSBOOTUTIL -p $path` 243*a0261a43SJames C. McPherson if [ "$mapped" != "NOT_MAPPED" ]; then 244*a0261a43SJames C. McPherson if [ "x$mapped" != "x$path" ]; then 245*a0261a43SJames C. McPherson NEWBOOTPATH=`echo "$path " | \ 246*a0261a43SJames C. McPherson $SED -e"s|$path|$mapped|"`" $NEWBOOTPATH" 247*a0261a43SJames C. McPherson else 248*a0261a43SJames C. McPherson NEWBOOTPATH="$NEWBOOTPATH $path" 2495a4c37c9Sqh201292 fi 2505a4c37c9Sqh201292 fi 251*a0261a43SJames C. McPherson done 252*a0261a43SJames C. McPherson # now strip off leading and trailing space chars 253*a0261a43SJames C. McPherson new_bootpath=`echo $NEWBOOTPATH` 254*a0261a43SJames C. McPherson $EEPROM bootpath="$new_bootpath" 255*a0261a43SJames C. McPherson cecho "stmsboot: bootpath has been updated, now regenerating boot archive" 256*a0261a43SJames C. McPherson $BOOTADM update-archive 257*a0261a43SJames C. McPherson cecho "" 2585a4c37c9Sqh201292} 2595a4c37c9Sqh201292 260*a0261a43SJames C. McPherson# Now do the actual work 2617c478bd9Sstevel@tonic-gatempxio_main() 2627c478bd9Sstevel@tonic-gate{ 2637c478bd9Sstevel@tonic-gate # NOTE: If the first attempt to run the service has failed due to an 2647c478bd9Sstevel@tonic-gate # expected error, users should be able to manually rerun the service. 2657c478bd9Sstevel@tonic-gate # 2667c478bd9Sstevel@tonic-gate # First mount /usr read only. This must be done to run 2677c478bd9Sstevel@tonic-gate # utilities such as fsck and devfsadm. 2687c478bd9Sstevel@tonic-gate # In the case of a manual rerun of the service, mounting of /usr here 2697c478bd9Sstevel@tonic-gate # fails if /usr already happens to be mounted. It is better that we 2707c478bd9Sstevel@tonic-gate # do not mount /usr if already mounted, but there seems to be no 2717c478bd9Sstevel@tonic-gate # apparent way to check whether /usr is mounted or not as we mount 2727c478bd9Sstevel@tonic-gate # /usr without making an entry into /etc/mnttab. So instead of 2737c478bd9Sstevel@tonic-gate # explicitly checking for mount failures, we just do a sanity check 2747c478bd9Sstevel@tonic-gate # by looking for some file (in this case devfsadm) in /usr. 2757c478bd9Sstevel@tonic-gate # 2767c478bd9Sstevel@tonic-gate mpxio_mount_usr 2777c478bd9Sstevel@tonic-gate if [ ! -s $DEVFSADM ]; then 2787c478bd9Sstevel@tonic-gate mpxio_error "failed to mount the /usr filesystem." 2797c478bd9Sstevel@tonic-gate return 2807c478bd9Sstevel@tonic-gate fi 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate if mpxio_mount_root; then 2837c478bd9Sstevel@tonic-gate # create /dev links 2847c478bd9Sstevel@tonic-gate cecho "stmsboot: configuring devices" 2857c478bd9Sstevel@tonic-gate $DEVFSADM 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate # update /etc/vfstab to reflect device name changes 288*a0261a43SJames C. McPherson $STMSBOOTUTIL -u >/dev/msglog 2>&1 289*a0261a43SJames C. McPherson if [ $? -eq 0 ]; then 290*a0261a43SJames C. McPherson $CP /etc/vfstab /etc/vfstab.old 291*a0261a43SJames C. McPherson $CP $SAVEDIR/vfstab.new /etc/vfstab 292*a0261a43SJames C. McPherson $RM $SAVEDIR/vfstab.new 293*a0261a43SJames C. McPherson cecho "" 294*a0261a43SJames C. McPherson cecho "stmsboot: vfstab has been updated" 2957c478bd9Sstevel@tonic-gate if update_dumpconf; then 2967c478bd9Sstevel@tonic-gate # update svm configuration to reflect new names 2977c478bd9Sstevel@tonic-gate if [ -s /kernel/drv/md.conf ] && \ 2987c478bd9Sstevel@tonic-gate [ -x $METADEVADM ]; then 2997c478bd9Sstevel@tonic-gate $METADEVADM -r >/dev/msglog 2>&1 3007c478bd9Sstevel@tonic-gate fi 3017c478bd9Sstevel@tonic-gate fi 3025a4c37c9Sqh201292 if [ "x$MACH" = "xi386" ]; then 3035a4c37c9Sqh201292 # only update bootpath here for x86 3045a4c37c9Sqh201292 update_bootpath 3055a4c37c9Sqh201292 fi 3067c478bd9Sstevel@tonic-gate else 3077c478bd9Sstevel@tonic-gate mpxio_error "failed to update /etc/vfstab." 3087c478bd9Sstevel@tonic-gate fi 3097c478bd9Sstevel@tonic-gate 310*a0261a43SJames C. McPherson $SVCADM disable system/device/mpxio-upgrade 3117c478bd9Sstevel@tonic-gate else 3127c478bd9Sstevel@tonic-gate mpxio_error "failed to mount the root filesystem." 3137c478bd9Sstevel@tonic-gate if [ $usrmounted -eq 1 ]; then 314*a0261a43SJames C. McPherson $UMOUNT /usr 3157c478bd9Sstevel@tonic-gate fi 3167c478bd9Sstevel@tonic-gate fi 3177c478bd9Sstevel@tonic-gate} 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gatempxio_main 320